|
|
就是这个程序。它演示了太阳系中地月系与太阳之间的运动关系:月球饶地球转,整个地月系饶太阳转,所有的星球都自转。
以下是控制运动的主要代码
procedure TfrmMain.RenderScene;
begin
glEnable(GL_CULL_FACE);
glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glTranslatef(0,0,-110);
glRotatef(yDeg,0,1,0);
glRotatef(xDeg,1,0,1);
RenderLights;//光照处理
//绘制太阳
glColor3ub(255,100,64);
glPushMatrix;
glRotate(SunSelfAng,0,1,0);
DrawSphere(10);
glPopMatrix;
glPushMatrix;//推入当前矩阵
//绘制地月系
glRotatef(EarthCommonAng,0,1,0);
glTranslatef(50,0,0);
glPushMatrix;//绘制地球
glRotatef(EarthSelfAng,0,1,0);
glColor3ub(20,50,255);
DrawSphere(5);
glPopMatrix;
glPushMatrix;//绘制月球
glColor3ub(200,200,200);
glRotatef(MoonAng,0,1,0);
glTranslatef(10,0,0);
glRotatef(MoonSelfAng,0,1,0);
DrawSphere(2);
glPopMatrix;
glPopMatrix;//弹出矩阵
SwapBuffers(wglGetCurrentDC);
end;
拿地球来说吧:渲染的顺序应该是先自转,再平移,再公转的啊。 可程序中的顺序恰好相反
这是怎么回事呢? 望各位大侠不吝赐教啊
程序效果图:
 |
|