Archived

This topic is now archived and is closed to further replies.

martinjy

Confused and lost in space

Recommended Posts

Yes, and lost in the corridors of internet. I''m coding this 3D space-shooter where I''m using quaternions to avoid gimble-lock. I''ve heard and read a lot about matrices and quaternions, camera and object-space, local and global coordinates, etc.. I''m pretty confused. This is what I''m trying to get an understanding of: My spaceship is right in front of the camera, and I can rotate it on all axes, accelerate it forwards and backwards and my camera tries to hang on to it. Is there anyone that can explain the whole process of setup and in-which-order-to-execute-transforms to me? Do I have to apply forward transformations to my ship, and inverse transformations to the camera? Is there some way I can only use one set of transformations to complete both?

Share this post


Link to post
Share on other sites
well thats a whole bunch of questions there and not much info to go on. Are you using OpenGL? If you are then the solution is fairly easy (and why are you using quats when you could just use GL''s matrix routines?). GLs transform routines are always done from a "local" perspective i.e. a command to rotate an object will rotate it about itself and not the origin. Thus an acceptable sequence of steps for drawing a particular object as seen by a particular camera might be:

glLoadIdentity();
glMultMatrix(inverseCamRotation.m);
glTranslate(inverseCamTranslation.x, inverseCamTranslation.y, inverseCamTranslation.z);

glPushMatrix();
glMultMatrix(object1Matrix.m);
DrawObject1();
glPopMatrix();

glPushMatrix();
glMultMatrix(object2Matrix.m);
DrawObject2();
glPopMatrix();

if you aren''t using gl but can implement local transformations the order of operations should be the same but you might not have the handy stack feature. Hope that helped. Try and include more info next time and try to condense your query into one clever question instead of three vague ones

-




Geocyte Has Committed Suicide.

Share this post


Link to post
Share on other sites