PDA

View Full Version : Getting positions and rotations for a limb?

Flotonic
02-16-2013, 10:39 AM
Pseudo code below:
glPushMatrix();
glRotatef(100,1,0,0);;
glRotatef(50,0,1,0);
glRotatef(100,1,0,0);
glTranslatef(x0,y0,z0);
glCallList(dl0);

glPushMatrix();
glRotatef(50,1,0,0);;
glRotatef(50,0,1,0);
glRotatef(50,1,0,0);
glTranslatef(x1,y1,z1);
glCallList(dl1);

glPushMatrix();
glRotatef(50,1,0,0);;
glRotatef(100,0,1,0);
glRotatef(50,1,0,0);
glTranslatef(x2,y2,z2);
glCallList(dl2);Relative to 0, how would I determine the translation and rotation value for the last Display List in this series, if I were exporting it like a scene? If there were no rotations, I would just add all of the translations up, but when a rotation is performed, it is a different story. Is there a quick and simple way to get that translation value relative to the origin and the rotation value that I need to use so it is also rotated the same way as when called this way? Like if I were editing the vertex data of something to be rotated and placed just like in the OpenGL window after the pushes, rotations, and translations? Thank you!

Dark Photon
02-17-2013, 06:56 PM
Pseudo code below:[CODE]...how would I determine the translation and rotation value for the last Display List in this series, if I were exporting it like a scene?

Do the transforms with the matrix stack, then query back the matrix. The translation is in the last column. The upper-left 3x3 are the rotation matrix (orthonormal basis vectors). Decompose into whatever form you want to represent the rotation transform in.

Flotonic
02-18-2013, 11:07 AM
Thank you so much for your response, Dark Photon! It is now getting the correct translations, but rotations are another thing. I am getting the matrix with the following code:
GLint matrix[16]; glGetIntegerv(GL_MODELVIEW_MATRIX,matrix);I have been searching for hours but have still yet to find a function that decomposes the matrix to X, Y, Z Euler angles. Do you happen to have any code from a project of yours that happens to do this that you can share, or is there a way to get the final rotation by doing some sort of calculations with the previous rotations? Thanks again!

Dark Photon
02-19-2013, 05:59 AM
GLint matrix[16]???

Think you mean GLfloat matrix[16] and glGetFloatv().

Flotonic
02-19-2013, 07:46 AM
Thanks! It is now a little closer! Some of the rotations are correct while others are wrong. Do you think it may have something to do with axis ordering?
GLfloat matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);
float xR, yR, zR;
EulerAnglesFromMatrix(&xR,&yR,&zR,matrix);