Sign in to follow this  
No_Germs

Using glMultMatrix*

Recommended Posts

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)?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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... :/

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Assuming you interpret the matrix this way (if not just do the transpose of it)


0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

then this is how your matrix SHOULD be set up
Individual components decend from x
x y z w | x
x y z w | y
x 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

Share this post


Link to post
Share on other sites
Ok, so you did this:

//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]);

it should be:
glVertex3f(0,0,0);
glVertex3f(theMatrix[0],theMatrix[1],theMatrix[2]);
//Y Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[4],theMatrix[5],theMatrix[6]);
//Z Axis
glVertex3f(0,0,0);
glVertex3f(theMatrix[8],theMatrix[9],theMatrix[10]);

what you were doing would work on the transpose of an openGL matrix

hope that helps
-Dan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this