I have worked with OpenGL for a while but am having some problems with a basic rotation. I think it is because my origin is not at the middle of the screen but rather at the lower-left corner of the screen as I set up my
glOrtho( 0, x, 0, y, 0, z ).
If I want to rotate 5 degrees in the x-axis I do this:
glPushMatrix( );
glTranslatef( halfWidth, halfHeight, 127.0 );
glRotatef( rotX, 1.0, 0.0, 0.0 );
glRotatef( rotY, 0.0, 1.0, 0.0 );
glTranslatef( -halfWidth, -halfHeight, -127.0 );
glBegin( GL_TRIANGLES );
glColor3f( 0.5, 0.5, 0.5 );
for( y = 0 ; y < ( height2 - 1 ) ; y++ )
{
for( x = 0 ; x < ( width2 - 1 ) ; x++ )
{
v[0][0] = x;
v[0][1] = y;
v[0][2] = image[y * nc + x];
v[1][0] = x;
v[1][1] = y + 1;
v[1][2] = image[( y + 1 ) * nc + x];
v[2][0] = x + 1;
v[2][1] = y;
v[2][2] = image[y * nc + ( x + 1 )];
calcNormal( v, normal );
glNormal3fv( normal );
glVertex3fv( v[0] );
glVertex3fv( v[1] );
glVertex3fv( v[2] );
v[0][0] = x;
v[0][1] = y + 1;
v[0][2] = image[( y + 1 ) * nc + x];
v[1][0] = x + 1;
v[1][1] = y;
v[1][2] = image[y * nc + ( x + 1 )];
v[2][0] = x + 1;
v[2][1] = y + 1;
v[2][2] = image[( y + 1 ) * nc + ( x + 1 )];
calcNormal( v, normal );
glNormal3fv( normal );
glVertex3fv( v[0] );
glVertex3fv( v[1] );
glVertex3fv( v[2] );
} // End for( x = 0 ; x < width2 ; x++ )
} // End for( y = 0 ; y < ( height2 - 1 ) ; y++ )
glEnd( );
glPopMatrix( );
I am drawing traingles that have an area of 1/2 square pixel. I modify rotX and rotY when the keyboard is pressed. The object is rotating, but my image is not drawing correctly upon rotation. Do I appear to be doing my rotating incorrectly? Thanks for your help!