Results 1 to 3 of 3

Thread: Rotation Problem

  1. #1
    Senior Member Regular Contributor
    Join Date
    Sep 2005
    Location
    Dayton
    Posts
    148

    Rotation Problem

    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
    Code :
     glOrtho( 0, x, 0, y, 0, z ).
    If I want to rotate 5 degrees in the x-axis I do this:

    Code :
     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!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: Rotation Problem

    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

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2005
    Location
    Dayton
    Posts
    148

    Re: Rotation Problem

    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!

Similar Threads

  1. Rotation problem.
    By Joshhua5 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-18-2011, 05:31 AM
  2. problem with rotation
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-08-2005, 07:25 PM
  3. need help with this rotation problem
    By imported_spooky in forum OpenGL: General
    Replies: 1
    Last Post: 04-15-2004, 11:08 PM
  4. rotation problem
    By hoganh in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-28-2003, 08:02 AM
  5. Rotation problem, i even do a WEB page to let you see my problem
    By sicklab in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-19-2000, 12:47 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