Sign in to follow this  

Rotation in space

Recommended Posts

Hi... I have a problem, of course... I'm working on a space game where you have absolute freedom of movement... But, as I've progressed with it, I had couple of problems... First of them I'll ask you if you could help me. I had a problem how to menage control of the movement in space, but after a while I've came up with an idea to have 3 orthonormal vectors, first pointing in the direction of movement, second is actually "up", and the third is to the right of the current position... Now it works great when I want to move... But, there apeeread a new problem that I haven't solved yet... I want to load a model of spacecraft into current position witch should be at the center of the screen. But I can't get it to work because the model is spinning strangely. I've tried it for hours, and I couldnt find a solution how to rotate it correctly. I know that I should use that 3 vectors, I've tried to calculate angles, but nothing worked. I know how to use a trick, but that's not what I want. Btw. I control camera with gluLookAt(). Whanks in advance...

Share this post

Link to post
Share on other sites
If you have the right, up and forward vector you can indeed create a rotation matrix.

Opengl's matrix looks like this:

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

cells 0, 4, 8 contain the right vector.
cells 1, 5, 9 contain the up vector.
cells 2, 6, 10 contain the forward vector.
cells 12, 13, 14 contain the translation vector.

to get it to work:

float m[16];
// put your vectors in the array here.
// ...
m[3] = m[7] = m[11] = 0;
m[15] = 1;

glMultMatrixf( m );

[Edited by - Centauri on August 18, 2008 12:57:13 PM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this