Hi! I’m working on a Solar System model. I have done an asteroid consisting of several random spheres. I can get the spheres to rotate one and one but I want to make them rotate as if they were one object. Here’s my code as it is right now.
glPushMatrix();
glRotatef(orbitalAngle, 0.0, 1.0, 0.0);
for (int i = 0; i < numOfSpheres; i++)
{
glPushMatrix();
GLdouble enlargedRadiusZ = (orbitalRadius + spheresPosition[i].z) * ENLARGED_RADIUS;
GLdouble enlargedRadiusX = spheresPosition[i].x * ENLARGED_RADIUS;
GLdouble enlargedRadiusY = spheresPosition[i].y * ENLARGED_RADIUS;
colorMixer->set_color(WHITE);
glTranslatef(enlargedRadiusX, enlargedRadiusY, enlargedRadiusZ);
glRotatef(90.0, 1.0, 0.0, 0.0);
gluSphere(sphere, 1, 5, 5);
glPopMatrix();
}
glRotatef(rotationAngleX, 1.0, 0.0, 0.0);
glRotatef(rotationAngleY, 0.0, 1.0, 0.0);
glRotatef(rotationAngleZ, 0.0, 0.0, 1.0);
glPopMatrix();
I iterate through all the spheres and draw them and after that I want to rotate it as one object but it doesn’t work. If I put the rotations just before I draw the sphere they rotate, but just one and one.
Thanx!