PDA

View Full Version : Rotation Problem

ToddAtWSU
04-30-2006, 06:45 PM
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!

mikael_aronsson
05-01-2006, 10:45 AM
If you do not have the mesh at the origin and want it to rotate around the origin or whatever you can always translate to the "origin" and then translate it back after the rotation.

Mikael

ToddAtWSU
05-01-2006, 12:13 PM
Are the translations I use correct? I am trying to move the middle of the image to the origin and then rotate it and then move it back to its original position. From what I understand OpenGL does the translates and rotation in a backwards order which is why I seem to move the object away from the origin first then rotate and then translate again back to its original position. Do these seem correct or are they wrong? Thanks!