PDA

View Full Version : Need Help



Uncertainty
09-23-2005, 05:44 AM
Hi all

I want to make the moon rotate the earth but instead it rotates around some point between the sun and the earth..and i dont get it..can someone help me?

Here's my code:

void drawsphere(void)
{
GLUquadricObj *pObj;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pObj = gluNewQuadric();

glPushMatrix();
glTranslatef(0.0f, 0.0f, -2.0f);
glColor3f(1.0f, 1.0f, 0.0f);
gluSphere(pObj, .15f, 40, 20);



glRotatef(alpha, 0.0f, 0.0f, 1.0f); glTranslatef(1.0f,0.0f,-2.0f);
glColor3f(0.0f,0.0f,1.0f); // Terra
gluSphere(pObj, 0.1f, 40,20);


glRotatef(fMoonRot, 0.0f, 0.0f, 1.0f);
glTranslatef(.5f , 0.0f, -2.0f);
fMoonRot+= 2.0f;
if(fMoonRot > 360.0f)
fMoonRot = 0.0f; glColor3ub(105,105,105);
gluSphere(pObj, 0.02f, 40,20);
glPopMatrix();
glutSwapBuffers();
}

a_wolly
09-25-2005, 05:35 AM
hi,

I'm not too sure since I'm in a rush but from the top of my head I think you might have to pop the matrix after making your earth object and then make the moon object in a new push/pop, rotating and then translating it in relation to the earth's centre. Hope that does it...

Andy