Using glMultMatrix*
i'm trying to draw a plane. i have a matrix that stores the plane's orientation. how do i use glMultMatrix to to rotate the plane model before i draw it (the red book doesn't refer to glMultMatrix too much)?
Quote:Original post by No_Germs
i'm trying to draw a plane. i have a matrix that stores the plane's orientation. how do i use glMultMatrix to to rotate the plane model before i draw it (the red book doesn't refer to glMultMatrix too much)?
From the red book
Quote:void glMultMatrix{fd}(const TYPE *m);
Multiplies the matrix specified by the sixteen values pointed to by m by the current matrix and stores the result as the current matrix.
That's really all there is to it. If m is an array representing a rotation of 90 degrees around the z axis, then glMultMatrixf(m) is the same exact thing as calling glRotatef(90.0f, 0.0f, 0.0f, 1.0f).
Keep in mind, though, that OpenGL expects your matrix to be in column-major order. C/C++ encourage you to think in row-major order, so this is often a source of confusion.
Thanks, but what i really wanted to know is how do i translate the orientation matrix to the graphic matrix(for instance, i need to invert the Z direction).
another problem is that the orientation matrix is 3X3, it doesn't have the w value...
another problem is that the orientation matrix is 3X3, it doesn't have the w value...
Yeah, i tried that but i still get a perspective distortion.
when i draw the axes of the orientation matrix by their value using GL_LINES, everything look fine.
but when i try to translate -6 on the Z Axis, use glMultMatrix to apply the rotation and draw a glutWireCube, it doesn't corelate with the axes i've drawn before... :/
when i draw the axes of the orientation matrix by their value using GL_LINES, everything look fine.
but when i try to translate -6 on the Z Axis, use glMultMatrix to apply the rotation and draw a glutWireCube, it doesn't corelate with the axes i've drawn before... :/
do you have a screenshot of what it looks like? because if you draw the axis with the identity and then the cube with a different matrix, it will definitely be different
sorry if i misunderstood, hope that helps
-Dan
sorry if i misunderstood, hope that helps
-Dan
no, i think you've got it... but i don't :) if i draw the orientation matrix's axis with the identity matrix and then draw the cube with the orientation matrix functioning as the model view matrix, the cube and the lines should be in sync, no? i mean, drawing the plane's matrix's axis with the identity modelview matrix is exactly the same as Multiplying the identity modelview matrix with the plane's matrix and than drawing the global coordinate system axis:
glLoadIdentity();
glBegin(GL_LINES);
// X Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[0],theMatrix[4],theMatrix[8]);
//Y Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[1],theMatrix[5],theMatrix[9]);
//Z Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[2],theMatrix[6],theMatrix[10]);
glEnd();//So far all's well
glPushMatrix();
glTranslatef(0,0,-6);//Zoom Out A little bit
glMultMatrixf(theMatrix);//Rotate by the Plane's Orientation Matrix
glBegin(GL_LINES);
// X Axis
glVertex3f(0,0,0);
glVertex3f(1,0,0);
//Y Axis
glVertex3f(0,0,0);
glVertex3f(0,1,0);
//Z Axis
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glEnd();/*this should produce the same result?*/
glPopMatrix();
thanks :)
glLoadIdentity();
glBegin(GL_LINES);
// X Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[0],theMatrix[4],theMatrix[8]);
//Y Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[1],theMatrix[5],theMatrix[9]);
//Z Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[2],theMatrix[6],theMatrix[10]);
glEnd();//So far all's well
glPushMatrix();
glTranslatef(0,0,-6);//Zoom Out A little bit
glMultMatrixf(theMatrix);//Rotate by the Plane's Orientation Matrix
glBegin(GL_LINES);
// X Axis
glVertex3f(0,0,0);
glVertex3f(1,0,0);
//Y Axis
glVertex3f(0,0,0);
glVertex3f(0,1,0);
//Z Axis
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glEnd();/*this should produce the same result?*/
glPopMatrix();
thanks :)
one correction, the "glTranslaef(0,0,-6)" line's supposed to come after the "glLoadIdentity()"
Assuming you interpret the matrix this way (if not just do the transpose of it)
ugh im sorry im doing a terrible job of explaining this, anyways, 12, 13, 14 should be transformation no matter what, which makes 0 1 2 the x y z of the "x" basis vector
4 5 6 the x y z of the "y" basis vector and so on
hope that helps
-Dan
0 4 8 121 5 9 132 6 10 143 7 11 15then this is how your matrix SHOULD be set up Individual components decend from xx y z w | xx y z w | yx y z w | z x y z w | w
ugh im sorry im doing a terrible job of explaining this, anyways, 12, 13, 14 should be transformation no matter what, which makes 0 1 2 the x y z of the "x" basis vector
4 5 6 the x y z of the "y" basis vector and so on
hope that helps
-Dan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement