Blain

05-18-2009, 10:46 PM

Ok. Say I have two angles. A roll angle (around z-axis) and a pitch angle (around x-axis) for the orientation of a spaceship. This is all I need it seems to point the spaceship and draw it. Problem is I want to move it forward. How do I calculate a direction vector?

Thanks

Blain - the phrase "I want it to move forward" is pretty vague, particularly considering you are working with a spaceship. I'm going to assume that you want your ship to fly like a plane, i.e. you want it to fly along the reoriented Z axis (roll axis). If this is true, try the following:

glPushMatrix ();

glRotatef (pitch_angle, 1,0,0);

glRotatef ( roll_angle, 0,0,1);

glTranslatef (0, 0, distance);

Draw_Spaceship ();

glPopMatrix ();

If this doesn't work, try switching the order of the rotations. Using this approach you don't have to explicitly compute the direction vector. The translation and spaceship will be reoriented by the rotations. This only works if you want the ship to move in a straight line along the spaceship's Z axis. Good luck.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.