View Full Version : rotations are messed up

12-01-2000, 05:48 PM
hi -

I am just starting opengl and I wanted to create a simple program to rotate objects, so I planned to write a solar system where planets can rotate about its own axis as well as rotate around the sun.

So I created a matrix to store the planets axis, and I can get that to rotate fine my called glLoadMatrix. However I can't get the planets to rotate around the sun. The planet just stays in the middle of the screen and doesn't move.

Can anyone help me out please.
If you need more detail on my code, let me know.


12-01-2000, 06:59 PM
I actually did a project a lot like this for a graphics class I'm taking. Unfortunately, for this class we are using something called the VTK rather than OpenGL. Anyway... I'll describe how I setup my code.

I had a C++ class for each body in the scene. In this class I stored a number of matrices. These matrices were basically these:

CurAxisRot - a matrix for the current axis rotation
AxisRotInc - the incremental axis rotation
CurOrbitRot - matrix for the current orbit rotation
OrbitRotInc - the incremental orbit rotation
OrbitRadiusMatrix - a translation matrix for the orbit radius from the parent body.
Final - a final matrix
FinalPos - final positional matrix that does not include the planet's axis rotation.

The class also had a pointer to the parent object, and a list of children objects. There was a function that got the parents FinalPos matrix.

Each frame the axis and orbit rotational matrices were incremented by the incremental matrices.

When rendering, I started with the root parent object (the sun) and went through all the children, and all the children's children.

To calculate the final matrices, I basically did something like so...

FinalPos = GetParentPos() * CurOrbitRot * OrbitRadiusMatrix;
Final = FinalPos * CurAxisRot;

Since the matrices are actually affected in the reverse order that they are specified, you can see that in effect the order of transformations would be something like so...

1. Rotate the body around it's axis
2. Translate the body the length of it's radius from the parent body.
3. Rotate the body to it's correct location around it's parent
4. Do whatever translations are necessary from the parent body. (Essentially none if the parent is the sun)

I could probably send you my code if that would make things more clear. I should almost translate the whole program to OpenGL just for the fun of it, but I haven't really had the time. http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Deiussum (edited 12-01-2000).]