Spaceship rotations
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++.
Quote:Original post by n99bThis problem comes up quite often on these forums. Fortunately, it's easily solved (and yes, you can do it without using quaternions :).
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++.
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement