我試圖在GLUT中製作Solarsystem的動畫,但不知何故,所有行星都以相同的速度在太陽周圍飛行,而它們都有不同值。OpenGL:動畫時,所有行星在太陽周圍都有相同的速度
我是新的OpenGL處/ GLUT所以,如果你能解釋一下你的答案我們將不勝感激:)
這是我的動畫製作方法:
void renderScene(void)
{
glClearDepth(1);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (spinMode) {
// Update the animation state
HourOfDay += AnimateIncrement;
DayOfYear += AnimateIncrement/24.0;
HourOfDay = HourOfDay - ((int)(HourOfDay/24))*24;
DayOfYear = DayOfYear - ((int)(DayOfYear/365))*365;
}
glLoadIdentity();
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glRotatef(15.0, 1.0, 0.0, 0.0);
//Drawing the sun
glTranslatef(0.0f, 0.0f, f);
glColor3f(1.0, 1.0, 0.0);
//glPushMatrix();
gluSphere(quad[0], 1.0f, 64, 64);
glRotatef(360.0*DayOfYear/365.0, 0.0, 1.0, 0.0);
glPopMatrix();
//Drawing mercurius
glColor3f(0.5, 0.5, 0.5);
glPushMatrix();
glTranslatef(2.0, 0.0, 0.0); //eerste parameter afstand tot zon
gluSphere(quad[1], 0.2f, 64, 64);
glRotatef(360.0*DayOfYear/365.0, 0.0, 1.0, 0.0);
glPopMatrix();
//Drawing the earth
glColor3f(0.2, 0.2, 1.0);
glPushMatrix();
glTranslatef(3.0, 0.0, 0.0); //eerste paramater afstand tot zon
gluSphere(quad[2], 0.4f, 64, 64);
glRotatef(360.0*DayOfYear/365.0, 0.0, 1.0, 0.0);
glPopMatrix();
//Drawing the earth1
glColor3f(0.2, 0.2, 1.0);
glPushMatrix();
glTranslatef(3.0, 0.0, 0.0); //eerste paramater afstand tot zon
gluSphere(quad[2], 0.6f, 64, 64);
glRotatef(360.0*3*DayOfYear/365.0, 0.0, 1.0, 0.0);
glPopMatrix();
//Drawing the earth2
glColor3f(0.2, 0.2, 1.0);
glPushMatrix();
glTranslatef(4.0, 0.0, 0.0); //eerste paramater afstand tot zon
gluSphere(quad[2], 0.3f, 64, 64);
glRotatef(360.0*4*DayOfYear/365.0, 0.0, 1.0, 0.0);
glPopMatrix();
//Drawing the earth3
glColor3f(0.2, 0.2, 1.0);
glPushMatrix();
glTranslatef(4.3, 0.0, 0.0); //eerste paramater afstand tot zon
gluSphere(quad[2], 0.75f, 64, 64);
glRotatef(360.0*2*DayOfYear/365.00, 0.0, 1.0, 0.0);
glPopMatrix();
// Flush the pipeline, and swap the buffers
glFlush();
glutSwapBuffers();
if (singleStep) {
spinMode = GL_FALSE;
}
glutPostRedisplay(); // Request a re-draw for animation purposes
}
或許有太陽系暗物質? – 2011-04-21 13:59:55
我可能用「使用GLUT」代替「GLUT」中的「GLUT」,僅供將來參考:) – 2011-04-21 21:14:48