1. Use the glTranslate(-x, -y, -z) function to move the object relative to (0,0,0)
2. Call glRotate() to rotate the objects, relative to (0,0,0)
3. Call glTranslate(x, y, z) to move the objects back to a position relative to (x,y,z).
Be sure that you draw your model relative to (0,0,0), and let OpenGL do the work of moving it around.
void PartCubes::drawCube(float x, float y, float z, float xrot)
{
glPushMatrix();
static float xoff = 1.0f;
static float yoff = 0.5f;
static float zoff = 0.0f;
glTranslatef(x,y,z);
glRotatef(xrot, 0, 1, 0);
glTranslatef(xoff,yoff,zoff);
drawCube();
glTranslatef(x,y,z);
glPopMatrix();
}
void PartCubes::drawCube(void)
{
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -0.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -0.0f);
glVertex3f(0.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
}