projection transformation

I’m defining my projection matrix like this:

/// move the world centre to origin:
glTranslatef(-1.0f * centroid);
/// move everything beneath the origin
glTranslatef(0,0,-1.0f * camera_distance);
/// rotate the world about the z axis

The translations work fine, but the rotation does not; I expected it to rotate the world beneath the camera along an axis through the camera.

A theta angle of just 1 degree will make the whole world disappear, and a theta angle of 0.001 degrees will move it a bit, but it doesn’t look like a rotation to me.

What have I done wrong here?

try putting the rotate statement first. Or you can do this:


Thanks, that’s good. Why should it go first? My interpretation of the OpenGL bible is that it must go last.

[This message has been edited by mr_coolio (edited 01-28-2003).]

It’s generally not a good idea to use glTranslate, glRotate, & glScale on the projection matrix. The projection matrix defines the shape of your viewing volume and shouldn’t be used to position/orient a “camera.” Camera-like positioning/orientation should be done as the first step of setting up the modelview matrix.

By trying to do these things in the projection matrix, you are likely to get undesired results when it comes to adding things like fog and lighting.

Take a look at some of the tutors on this site:

He has tutors on 3D world building and moving in a 3D world.