Jump to content
• Advertisement

# OpenGL About modelview matrix

This topic is 4097 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

##### 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

##### 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5
• Advertisement

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013541
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!