这是一个提示.. 在您的显示回调函数中执行此操作:
void display()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(10,10,10, 0,0,0, 0,1,0);
/* current position is by default the origin */
//draw sun
glutSolidSphere(1,100,100);
//draw planet
glRotated(angle1,0,1,0); //rotates position by angle1
glTranslated(0,0,5); //translates position by sun-planet distance
glutSolidSphere(0.7,100,100); //draw planet at this new position
//draw moon
glRotated(angle2,0,1,0); //rotates position by angle1+angle2
glTranslated(0,0,2); //translates position by planet-moon distance
glutSolidSphere(0.3,100,100); //draw moon at this new position
glutSwapBuffers();
angle1 += 0.2;
angle2 += 0.2;
if(angle1 > 360) angle1 = 0;
if(angle2 > 360) angle2 = 0;
}
尝试评论绘制行星和月球部分的一些线条并查看差异,这将有助于您理解它。
希望这可以帮助!