Using glMultMatrix*

Started by
11 comments, last by No_Germs 19 years, 1 month ago
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)?
Advertisement
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...
Fill in 0s for the rest, (well, 1 for element 15)

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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... :/
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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 :)
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)

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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."

This topic is closed to new replies.

Advertisement