Search code examples
c++openglglut

OpenGL Rotation


I'm trying to do a simple rotation in OpenGL but must be missing the point. I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally.

At the moment I have code like this:

glPushMatrix();
  glRotatef(90.0, 0.0, 1.0, 0.0);
  glBegin(GL_TRIANGLES);        
    glVertex3f( 1.0, 1.0, 0.0 );        
    glVertex3f( 3.0, 2.0, 0.0 );        
    glVertex3f( 3.0, 1.0, 0.0 );        
  glEnd();
glPopMatrix();

But the result is not a triangle rotated 90 degrees.

Edit Hmm thanks to Mike Haboustak - it appeared my code was calling a SetCamera function that use glOrtho. I'm too new to OpenGL to have any idea of what this meant but disabling this and rotating in the Z-axis produced the desired result.


Solution

  • Do you get a 1 unit straight line? It seems that 90deg rot. around Y is going to have you looking at the side of a triangle with no depth.

    You should try rotating around the Z axis instead and see if you get something that makes more sense.

    OpenGL has two matrices related to the display of geometry, the ModelView and the Projection. Both are applied to coordinates before the data becomes visible on the screen. First the ModelView matrix is applied, transforming the data from model space into view space. Then the Projection matrix is applied with transforms the data from view space for "projection" on your 2D monitor.

    ModelView is used to position multiple objects to their locations in the "world", Projection is used to position the objects onto the screen.

    Your code seems fine, so I assume from reading the documentation you know what the nature of functions like glPushMatrix() is. If rotating around Z still doesn't make sense, verify that you're editing the ModelView matrix by calling glMatrixMode.