Results 1 to 7 of 7

Thread: glRotatef in ortho perspective

  1. #1
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20

    glRotatef in ortho perspective

    Hi all,
    I had aspired to use ortho perspective but I've discovered that rotation about the x axis doesn't work properly on my system. Is this to be expected?
    Sample code:

    Code :
          theta += 2;
            glPushMatrix ();
            glTranslatef (50,50,0);
            glRotatef (theta,1,0,0);
            glBegin (GL_TRIANGLES);
            glColor3f(1.0, 0.0, 0.0);
            glVertex2d(0.0,0.0);
            glVertex2d(100,0.0);
            glVertex2d(100,100);
            glColor3f(0.0, 100, 0.0);
            glVertex2d(0.0,0.0);
            glVertex2d(0.0,100);
            glVertex2d(100,100);
            glEnd();
            glPopMatrix ();

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671
    Quote Originally Posted by question2 View Post
    Hi all,
    I had aspired to use ortho perspective but I've discovered that rotation about the x axis doesn't work properly on my system.
    In what way does it not "work properly"?

  3. #3
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by Alfonse Reinheart View Post
    In what way does it not "work properly"?
    The rectangle (two triangles) appears only at certain angles, e.g. -15 to 15 degrees. Otherwise it completely disappears. If you wanted I could make a video and upload that somewhere.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,100
    It would probably simpler to just post the rest of your code, i.e. the part where the bug is (there's nothing wrong with the fragment you posted).

  5. #5
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by GClements View Post
    It would probably simpler to just post the rest of your code, i.e. the part where the bug is (there's nothing wrong with the fragment you posted).
    Other than that there is only initialization code. But I think I see what the problem is. Consider the code below. I change the vertex coordinates to be on both sides of the X and Y axes.
    However when I rotate about the x-axis, it actually seems to be rotating about a line that is 50 points below the X axis i.e. y=-50. You can try for yourself.

    When I change the axis of rotation to Y, a similar thing occurs: glRotatef rotates about a line that is not the Y axis but is maybe x=50.
    Code :
    void draw_scene ()
    {
       glMatrixMode (GL_PROJECTION);
            glLoadIdentity ();
            glOrtho(0.0f, width, height, 0.0f, 0.0f, 1.0f);
            glMatrixMode (GL_MODELVIEW);
            glLoadIdentity ();
     
     
            glDisable(GL_CULL_FACE);
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
            glDisable(GL_BLEND);
            glDisable(GL_LIGHTING);
            glDisable(GL_DEPTH_TEST);
            glColor3f (1.0, 1.0, 1.0);
            glClear (GL_COLOR_BUFFER_BIT);
     
    //  draw the rectangle
            glPushMatrix ();
            glTranslatef (100,100,0);
            glRotatef (theta,1,0,0);
            glScalef (2,2,1);
            glBegin (GL_TRIANGLES);
            glColor3f(1.0, 0.0, 0.0);
            glVertex2d(-50.0,-50.0);
            glVertex2d(50,-50.0);
            glVertex2d(50,50);
            glColor3f(1, 1, 0.0);
            glVertex2d(-50.0,-50.0);
            glVertex2d(-50.0,50);
            glVertex2d(50,50);
            glEnd();
            glPopMatrix ();
     
            glutSwapBuffers ();
    }

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,100
    Quote Originally Posted by question2 View Post
    Other than that there is only initialization code.
    Code :
            glOrtho(0.0f, width, height, 0.0f, 0.0f, 1.0f);
    The rectangle is 100 units across, but the near and far planes are only one unit apart, and the rotation axis is coincident with the near plane. Except when the rectangle is almost exactly vertical, most of it is being clipped away by the near and far planes. Try:
    Code :
            glOrtho(0.0f, width, height, 0.0f, -100.0f, 100.0f);

  7. #7
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by GClements View Post
    The rectangle is 100 units across, but the near and far planes are only one unit apart, and the rotation axis is coincident with the near plane. Except when the rectangle is almost exactly vertical, most of it is being clipped away by the near and far planes. Try:
    Code :
            glOrtho(0.0f, width, height, 0.0f, -100.0f, 100.0f);
    That fixed it! Thanks.

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2015, 07:35 AM
  2. Migrating from GLOrtho to GLU to give glRotatef perspective
    By FrankMonza in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-08-2014, 06:29 AM
  3. glRotatef scaling up and down on ortho projection?
    By doodlemunch in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-24-2007, 03:07 AM
  4. ortho + perspective + ortho
    By mithun_daa in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-09-2004, 07:54 AM
  5. changing from perspective to ortho back to perspective
    By crappy04 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-19-2001, 09:03 AM

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