Results 1 to 3 of 3

Thread: opengl rotate-translate-rotate problem

  1. #1
    Join Date
    Sep 2007
    Location
    Finland
    Beans
    27
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Question opengl rotate-translate-rotate problem

    Im drawing a box and i would like to do the following:

    1. rotate the box around its own axis (the angle of the object)
    2. move it to position according to the position values and camera position
    3. rotate again for the camera angle

    I have managed to make following piece of code, but when the model angle changes it rotates around the viewer, not its own axis.

    Code:
    glPushMatrix();
    glLoadIdentity();
    
    glRotatef(model.Angle.X,1.0f,0.0f,0.0f); 
    glRotatef(model.Angle.Y,0.0f,1.0f,0.0f); 
    glRotatef(model.Angle.Z,0.0f,0.0f,1.0f);
    glTranslatef(-Position.X+model.Position.X,-Position.Y+model.Position.Y,-Position.Z+model.Position.Z);
    glRotatef(Angle.X,1.0f,0.0f,0.0f); 
    glRotatef(Angle.Y,0.0f,1.0f,0.0f); 
    glRotatef(Angle.Z,0.0f,0.0f,1.0f); 
    
    glBegin(GL_QUADS);
    glVertex3f(i->Vertexes[0].X,i->Vertexes[0].Y,i->Vertexes[0].Z);
    glVertex3f(i->Vertexes[1].X,i->Vertexes[1].Y,i->Vertexes[1].Z);
    glVertex3f(i->Vertexes[2].X,i->Vertexes[2].Y,i->Vertexes[2].Z);
    glVertex3f(i->Vertexes[3].X,i->Vertexes[3].Y,i->Vertexes[3].Z);
    glEnd();
    			
    glPopMatrix();

  2. #2
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: opengl rotate-translate-rotate problem

    Do the "camera" first, then the object.

  3. #3
    Join Date
    Sep 2007
    Location
    Finland
    Beans
    27
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: opengl rotate-translate-rotate problem

    Thank you for the tip. It seems to work now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •