Results 1 to 2 of 2

Thread: rotations are messed up

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2000
    Posts
    8

    rotations are messed up

    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.

    Thanks

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: rotations are messed up

    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.


    [This message has been edited by Deiussum (edited 12-01-2000).]
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Messed up Mipmaps
    By Dr. Coaster in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2004, 01:06 AM
  2. OpenGL maybe messed up...........
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 04-06-2003, 02:59 PM
  3. My game is messed
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 01-07-2003, 04:20 PM
  4. messed up opengl
    By DaBeast in forum OpenGL: User Software
    Replies: 7
    Last Post: 06-15-2002, 09:23 PM
  5. Image looks messed up
    By kabrit in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-01-2002, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean