#### Archived

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

This topic is 6041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, this is my first post here I just started to develop my first game in 3D. The game is supposed to be a very basic Elite-Clone using OpenGL and I got stuck at this problem: I can''t figure out how to make the space ships head in the right direction. Right direction is the LookAt vector of the ship but i got no idea how to make OpenGL rotate my ships exactly in that direction. Can anyone give me a basic algorithm or some keywords to look for? Links to tutorials/articles would be cool too I already tried to google for information but I don''t know what to look for. regards, Havok

##### Share on other sites
I am currently working on the same kind of game....
Since you want to have all degrees of freedom you can''t use the Euler rotations any more ... So you shouldn''t use glRoatate...

You could look at my code ... just head over to
http://sourceforge.net/projects/spaceshooter/
There you can browse through the CVS Tree ... in the subfolder util you will find the modules camera and object ... The object holds 3 direction vectors and a position vector and a speed vector.. These vectors were updated every frame ... The camera class has a pointer to an object object . Everytime the matrix ist needed the camera class gets the direction vectors and the position of the object and creates a Modelview matrix...

By the way, we could need some further team members

##### Share on other sites
try this url - it may help ...

http://www.gamedev.net/community/forums/topic.asp?whichpage=1&pagesize=20&topic_id=54563

##### Share on other sites
Thanks to both of you. You helped me a lot. I got an idea how to solve the heading problem now

Later, Havok

##### Share on other sites
Actually you can use glRotate. What''s important is the order in which you rotate and translate. Your spaceship should have a vector variable/structure in it, and your camera should also have a similar structure or variables.
First you rotate based on the camera''s position:
glRotatef( -m_Camera.m_sDirection.x, 1.0f, 0.0f, 0.0f );
glRotatef( -m_Camera.m_sDirection.y, 0.0f, 1.0f, 0.0f );
glRotatef( -m_Camera.m_sDirection.z, 0.0f, 0.0f, 1.0f );
(the signs might differ depending on how you handle your coordinates).

Then, you translate to the origin of the object relative to the camera by calling
glTranslatef( object.x-camera.x, object.y-camera.y, object.z-camera.z);
or a similar translate function.

You then rotate about the rotation vector of the object, similar to how you rotated the camera, and then do any scaling/drawing.

Just before to use glLoadIdentity in between each object and each frame =P.

• 10
• 16
• 9
• 13
• 41
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!