# Rotate an object around a point

• 03-01-2018, 05:03 PM
coolbiscuit
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();```

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!
• 03-02-2018, 05:23 AM
GClements
Quote:

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

Quote:

Originally Posted by coolbiscuit
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.