PDA

View Full Version : projection transformation



mr_coolio
01-28-2003, 02:01 AM
Hi!
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
glRotated(Theta,0.0,0.0,1.0);

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?

HalcyonBlaze
01-28-2003, 03:09 AM
try putting the rotate statement first. Or you can do this:



glTranslatef(...);
glTranslatef(...);
glPushMatrix();
glRotated(theta,0.0,0.0,1.0);
DrawWorld();
glPopMatrix();

mr_coolio
01-28-2003, 03:36 AM
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).]

Deiussum
01-28-2003, 05:31 AM
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.

nexusone
01-28-2003, 06:05 AM
Take a look at some of the tutors on this site: nehe.gamedev.net

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