Login  Register

Viewing transformations cleared after glLoadMatrix

Posted by andys on Dec 09, 2010; 10:34am
URL: https://forum.jogamp.org/Viewing-transformations-cleared-after-glLoadMatrix-tp2056651.html

Hi,

 this is a questions about fundamental understanding of the matrix. And i am honestly thinking over this a couple of days now. In the JBullet Demos the objects (RigidBodies) are transformed in their proper location by loading the ModelView Matrix with new matrix values :

float[] glMat = new float[16];
// trans is the com.bulletphysics.linearmath.Transform  object representing the Bodys translation & rotation.
trans.getOpenGLMatrix(glMat);
gl.glLoadMatrixf(glMat, 0);
gl.glBegin(GL2.GL_QUADS);
.... draw body .....
gl.glEnd();


So far so good - all bodys are drawn perfectly correct. But my View transformation which i setup at the very beginning of the display() method is wipped out. Regardless what transformation/rotation i do before/after this glLoadMatrix() command - it is ignored.  PushMatrix/PopMatrix (as i normally do it for all my JOGL testcode) doesn't help in any way. And also keeping a Backup of the original ModelView Matrix which i reloaded after gl.glEnd doesn't help.  I honestly do not understand this at all. I always thought it is "standard" and bulletprove operation to Push the Matrix, transform object to its location i 3d world, draw it  and then Restore the Matrix via Pop.  But in this case this glLoadMatrix seems to make an unrecoverable change of my Modelview matrix?

As far i could dig out of the JBullet demo code to me it looks like the projection matrix is changed all the time - which probably sets the proper view for the user. But no idea if this indeed is the reason why the view is correct in the original JBullet Demos. In my stripped down version of the "BasicDemo" i only get my proper view if i extract Translation & Rotation parameters from the Transfrom object:

gl.glPushMatrix();
gl.glTranslatef(trans.origin.x, trans.origin.y, trans.origin.z);
Quat4f glRot = new Quat4f();
trans.getRotation(glRot);
gl.glRotatef(glRot.w * 360, glRot.x, glRot.y, glRot.z);
... draw object ....
gl.glPopMatrix();


But there seems to be a lot of math  involved in order to get the rotation out of a rotation matrix (at least the Bullet source for Matrix3x3.getRoatation() shows that:  getRotation Bullet src ) so i thought it might be better to stay with the glLoadMatrix version.  But for this i would need a way to keep my view transformation.

Also for my fundamental understanding it would be very beneficial if somebody please could explain to me why this glLoadMatrix overrides all my other transformations (even if a backup matrix via push/pop).

Cheers
    Andy