Sign in to follow this  

Spaceship rotations

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm working on a game where you will get to fly freely with a spaceship in space. I can't seem to get the rotations to work as I want them to, though. I've tried Euler angles, applying rotation about one axis at a time, and I hope and think this can be done without using quaternions. I need help, though, because I can't seem to make the spaceship behave the way I want it to. The spaceship should be able to pitch, yaw and roll, and it shouldn't matter which way it's facing (because it's in space, eh). If it's of any significance, I'm coding OpenGL/C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by n99b
Hello.

I'm working on a game where you will get to fly freely with a spaceship in space. I can't seem to get the rotations to work as I want them to, though. I've tried Euler angles, applying rotation about one axis at a time, and I hope and think this can be done without using quaternions. I need help, though, because I can't seem to make the spaceship behave the way I want it to. The spaceship should be able to pitch, yaw and roll, and it shouldn't matter which way it's facing (because it's in space, eh).

If it's of any significance, I'm coding OpenGL/C++.
This problem comes up quite often on these forums. Fortunately, it's easily solved (and yes, you can do it without using quaternions :).

To implement free, 6DOF motion, you'll need to store the orientation of the object somewhere, and then update it incrementally using local-axis rotations. You'll also need to normalize the orientation occasionally to prevent numerical drift.

This can be done using OpenGL exclusively (how to do so is touched on briefly in this recent thread). However, it's usually best to do this sort of thing using a third-party math library.

The details depend somewhat on what notational convention you're using, but since you're using OpenGL I'll assume column-vector notation. In pseudocode, it might look something like this:
matrix33 orientation; // This is stored somewhere, e.g. at class or global scope

...

// Then, in the update function...

matrix33 rotation_delta = matrix_yaw_pitch_roll(
relative_yaw,
relative_pitch,
relative_roll
);

orientation *= rotation_delta;
orientation.orthogonalize();
And that's pretty much it. (For linear motion, you simply translate along the appropriate local axis of the object.)

Here is a link to some code that implements 6DOF motion using OpenGL conventions (the code uses vector math rather than the above matrix computations, but the idea is the same).

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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