Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rotate an object around a point

  1. #1
    Newbie Newbie
    Join Date
    Mar 2018
    Posts
    1

    Rotate an object around a point

    Hello,

    I am simply trying to rotate an object by 20 degrees around the point (-.5,3.0)

    Code cpp:
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
     
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     glColor3f(1,0,0);
     glPushMatrix();
     
     
    glColor3f(1,0,0);
    glTranslatef(.5 ,-3.0 ,0.0);
    glRotatef(-20.0f, 0.0, 0.0, 0.0);
    glTranslatef(-.5, 3.0, 0.0);    
    drawHead();
    glPopMatrix();

    here is my drawHead()

    Code cpp:
    void drawHead()
    {
        glBegin(GL_POLYGON); // Draw A Quad
        glVertex3f(-1.0f, 5.0f, 0.0f); 
        glVertex3f(0.0f, 5.0f, 0.0f); 
        glVertex3f(1.0f, 4.0f, 0.0f); 
        glVertex3f(0.0f, 3.0f, 0.0f); 
        glVertex3f(-1.0f, 3.0f, 0.0f); 
        glVertex3f(-2.0f, 4.0f, 0.0f); 
        glEnd();
    }

    I've looked on other posts and forums and this seems to be the way to do it. However, it is not coming out right when I run it. Sometimes the whole head will disappear. I've tried putting in different values in the glrotate to no avail. In theory this should move the whole object with the point i want to rotate about at origin. Rotate. And then go back to prior CS. Any help would be appreciated. Thanks!
    Last edited by Dark Photon; 03-01-2018 at 06:13 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by coolbiscuit View Post
    I am simply trying to rotate an object by 20 degrees around the point (-.5,3.0)
    Quote Originally Posted by coolbiscuit View Post
    Code cpp:
    glRotatef(-20.0f, 0.0, 0.0, 0.0);
    You have to specify the axis of rotation. An axis of [0 0 0] will result in undefined behaviour; normalisation will probably result in NaN values.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •