PDA

View Full Version : local and global space camera angles rotatef function



oscar_benjamin
02-23-2002, 10:35 AM
If you want an object to rotate properly about its own axis transformations must be carried out in it's own axis. My method is to store the position vector and global axis vectors in local space for each object and rotate translate them in the opposite direction every time the objects stats are changed. Then using the dot-product with the position vector and each of the global axis vectors the position of the object can be found. How do I find the angles of the spaceship for the glrotatef function and/or the vectors to rotate around. Or, is there another, better way of using local space that still allows proper rotation.

Jambolo
02-27-2002, 10:33 PM
You have built a mountain out of a flattened molehill.

OpenGL transformations are done in the "local" coordinate system. If you want to display two spaceships and light them, you do it like this:






glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt();

glPushMatrix(); // Save world space
glTranslate(); // Move to the light's location
glRotate(); // Rotate around the translated origin
SetLight(); // Make a light
glPopMatrix(); // Restore world space

glPushMatrix(); // Save world space
glTranslate(); // Move to the ship's location
glRotate(); // Rotate around the translated origin
DrawShip1(); // Draw ship 1
glPopMatrix(); // Restore world space

glPushMatrix(); // Save world space
glTranslate(); // Move to the ship's location
glRotate(); // Rotate around the translated origin
DrawShip2(); // Draw ship 2
glPopMatrix(); // Restore world space

....

glFlush();



Note that the translation call is before the rotation. If the translation is after the rotation, it occurs in the rotated coordinate system.

Now, figuring out what the glRotate() parameters are is going to take some research.

oscar_benjamin
03-03-2002, 09:27 AM
Thank you for replying to my topic. Not without some considerable degree of effort Ihave now finally solved the problem using quaternions. Thank you for your help