# Thread: Rotate an object around a point

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);
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);
glPopMatrix();```

Code cpp:
```void drawHead()
{
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!

2. Originally Posted by coolbiscuit
I am simply trying to rotate an object by 20 degrees around the point (-.5,3.0)
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.

#### Posting Permissions

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