how to set my opengl es 3D projection to jpct-es

Started by Davi, October 29, 2011, 05:25:45 PM

Previous topic - Next topic

Davi

         I have opengl es code as blew:     
             
                gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadMatrixf(ProjectionBuff);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadMatrixf(Transform);
             

      I want to know how to set jpct-es like this?


EgonOlsen

#2
The projection matrix is implicitly created by the engine based on the current fov settings and the far and near clipping plane. There's no way to set it directly from the outside. The model view matrix in OpenGL is a combination of object space->world space and world space->camera space transformations. The matrix itself is set by the engine based on an object's transformation and the camera rotation and position. You can't take some random GL code and just extract the matrices to feed them into jPCT-AE. You have to understand what the code does and rebuild it's behaviour by using the means that the engine offers.


Davi



onDrawFrame(GL10 gl) {

matrixTrans=new Matrix();
matrixTrans.translate(a,b,c)
model.setTranslationMatrix(matrixTrans);

//doAnim(); 
world.renderScene(fb);
world.draw(fb);
fb.display();
}
   
a,b,c is my dynamic value,it can control my model moved by my marker correctly before using jpct-ae. But with jpct, it seems can't be transformed correctly,at least not entirely correct. eg.when my marker is away from my device camera,it can be scaled correctly.but when I move my marker from up to down or from left to right,it can not moved to right place,but the  orientation is right.I don't know it is effected by wold or camra of jpct-ae. please?

EgonOlsen

I'm not 100% sure, what you are trying to do here, but keep in mind that jPCT uses this coordinate system: http://www.jpct.net/wiki/index.php/Coordinate_system

Maybe you have adjust your a,b,c values to this.

Davi

Quote from: EgonOlsen on October 30, 2011, 07:51:47 PM
The projection matrix is implicitly created by the engine based on the current fov settings and the far and near clipping plane. There's no way to set it directly from the outside. The model view matrix in OpenGL is a combination of object space->world space and world space->camera space transformations. The matrix itself is set by the engine based on an object's transformation and the camera rotation and position. You can't take some random GL code and just extract the matrices to feed them into jPCT-AE. You have to understand what the code does and rebuild it's behaviour by using the means that the engine offers.
how can I understand what the code does,can you give me some open source code about that?

EgonOlsen

I wasn't taking about the jPCT code. You have to understand what the OpenGL code does that you are going to port. jPCT just does the usual transformation stuff. I can post this part (6 lines or so...), but i don't see how this would help in any way. All it does is to tranform the world space transformation matrix to OpenGL's coordinate system, multiply with the camera's matrix and apply the camera's translation. Nothing special at all.

Davi

please post me that part (6 lines or so...), may be that can help me ;D

EgonOlsen

I don't see how, but here you go:


mo.setTo(transBuffer);
mat.setTo(cam.getBack());
mat.transformToGL();
mo.translate(-cam.backBx, -cam.backBy, -cam.backBz);
mo.matMul(mat);


mo is a Matrix that contains the final result, mat is a temp matrix, transBuffer contains the world transformation of that object.

Davi

"-cam.backBx, -cam.backBy, -cam.backBz",how to get them? :-[

EgonOlsen