Basically:
If you want to rotate around P , translate to -P (so that P moves to the origin), then rotate it and then translate to P (so that the origin returns to P ).
glTranslatef(Px, Py, Pz); glRotatef(angle, Ax, Ay, Az); glTranslatef(-Px, -Py, -Pz);
(Note: it is in “reverse order” because the last transformation added is the first one applied according to OpenGL rules.)
So, in your installation code, you need these calls:
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 499, 0, 499); glMatrixMode(GL_MODELVIEW);
And then your display() method should look something like this:
void display() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.5f, 0.5f, 0.5f); glRotatef(45.f, 1.f, 1.f, 1.f); glTranslatef(-0.5f, -0.5f, -0.5f); glColor3f(0.f, 0.f, 1.f); drawhouse(); glFlush(); }
source share