Jump to content
  • Advertisement
Sign in to follow this  
Great_White

OpenGL About modelview matrix

This topic is 4010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm trying to learn transformations in OpenGL. I write my own math routines for transformations. But I dont understand world and local object coordinates well. In my program I'm trying to rotate my object around its own local axis. I know that every vertices in the GL pipeline multiplied by the V*M matrix. What should I choose for the M matrix for this ?

Share this post


Link to post
Share on other sites
Advertisement
To rotate an object around its own local axis, I would try something like this:

glPushMatrix();
// Rotate the matrix as necessary:
glRotatef(30,0,0,1);
// Translate the matrix as necessary:
glTranslatef(-5, -5, -5);
// Draw the object relative to it's own axis of rotation:
glBegin(GL_QUADS);
glVertex3f(-5, -5, 0.0);
glVertex3f(5, -5, 0.0);
glVertex3f(5, 5, 0.0);
glVertex3f(-5, 5, 0.0);
glEnd();
glPopMatrix();

By default everything rotates around the origin (0,0,0). So I would draw the object relative to the origin, then rotate it and move it relative to the origin. Or you could use math to calculate the actual 3D coordinates of each vertex after rotation, but why do that when OpenGL will do it for you?

Share this post


Link to post
Share on other sites
I know PushMatrix method but I dont want to use it. Like I said I'm trying to learn internal workings of the pipeline. So when I draw an object say cube, its rotates around the world axis. ( I'm doing this with ViewMatrix*ModelMatrix*object local coordites At first both ViewMatrix and Model matrix are identity matrix). How can I define local object transform matrix with respect to the world coordinates?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!