《2022年2022年计算机图形学模拟太阳系源代码 .pdf》由会员分享,可在线阅读,更多相关《2022年2022年计算机图形学模拟太阳系源代码 .pdf(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include #include #include #include / 行星GLfloat rot0 = 30.0; GLfloat rot1 = 0.0; GLfloat rot2 = 0.0; GLfloat rot3 = 0.0; GLfloat rot4 = 0.0; GLfloat rot5 = 0.0; GLfloat rot6 = 0.0; GLfloat rot7 = 0.0; GLfloat rot8 = 0.0; / 卫星GLfloat rot9 = 0.0; GLfloat rot10 = 0.0; GLfloat rot11 = 0.0; void init() g
2、lClearColor(0.0,0.0,0.0,0.0); glClearDepth(1.0); glShadeModel(GL_FLAT); void display() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glLoadIdentity(); /gluLookAt(0, 10, 10, 0,0,0,0, 1,0); /glRotatef(45.0,0.0,0.0,1.0); glTranslatef(0.0,0.0,-20.0); glRotatef(90.0,1.0,0.0,
3、0); glPushMatrix(); / 绘制太阳glColor3f(1.0,0.0,0.0); glutSolidSphere(2.0,32,32); / 绘制地球glPushMatrix(); glColor3f(0.0,0.0,1.0); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 8 页 - - - - - - - - - glutSolidTorus(0.02, 5.0, 10, 64);
4、glRotatef(-90,1.0,0,0.0); / 设置地球公转速度glRotatef(rot0,0.0,1.0,0.0); / 设置地球半径glTranslatef(5.0,0.0,0.0); / 设置地球自转速度/glRotatef(rot1,0.0,1.0,0.0); / 绘制地球glutSolidSphere(0.4,32,32); / 绘制地球的卫星 -月亮glColor3f(0.5,0.6,0.5); / 抵消地球自转影响/glRotatef(-rot1,0.0,1.0,0.0); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glRotatef(-90,1
5、.0,0,0.0); / 设置月亮公转速度glRotatef(rot9,0.0,1.0,0.0); / 设置月亮公转半径glTranslatef(0.6,0.0,0.0); / 绘制月亮glutSolidSphere(0.1,10,8); glPopMatrix(); / 绘制水星glPushMatrix(); glColor3f(0.0,1.0,1.0); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 2.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置水星公转速度glRotatef(rot1,
6、0.0,1.0,0.0); / 设置水星公转半径glTranslatef(2.5,0.0,0.0); / 设置水星自传glRotatef(rot3,0.0,1.0,0.0); / 绘制水星glutSolidSphere(0.2,32,32); glPopMatrix(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 8 页 - - - - - - - - - / 绘制金星glPushMatrix(); glColor3f(0.0,1.0,0.0); / 绘制辅助轨道g
7、lRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 3.4, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置金星公转速度glRotatef(rot2,0.0,3.0,0.0); / 设置金星公转半径glTranslatef(3.4,0.0,0.0); / 设置金星自传glRotatef(rot0,0.0,1.0,0.0); / 绘制金星glutSolidSphere(0.3,32,32); glPopMatrix(); / 绘制火星glPushMatrix(); glColor3f(1.0,0.0,0.0); / 绘制辅助轨
8、道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 6.6, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置火星公转速度glRotatef(rot3,0.0,4.0,0.0); / 设置火星公转半径glTranslatef(6.6,0.0,0.0); / 设置火星自传glRotatef(rot7,0.0,2.0,0.0); / 绘制火星glutSolidSphere(0.5,32,32); glPopMatrix(); / 绘制木星glPushMatrix(); glColor3f(2.0,0.1,1.0); / 绘制辅
9、助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 8.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置木星公转速度名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 8 页 - - - - - - - - - glRotatef(rot4,0.0,0.4,0.0); / 设置木星公转半径glTranslatef(8.5,0.0,0.0); / 设置木星自传glRotatef(rot3,0.0,
10、0.3,0.0); / 绘制木星glutSolidSphere(1.0,32,32); / 绘制木星卫星 - 木卫 1 glColor3f(0.4,0.3,0.5); / 抵消地球自转影响/glRotatef(-rot1,0.0,1.0,0.0); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glRotatef(-90,1.0,0,0.0); / 设置木卫 1 公转速度glRotatef(rot10,0.0,1.0,0.0); / 设置木卫 1 公转半径glTranslatef(1.3,0.0,0.0); / 绘制木卫 1 glutSolidSphere(0.1,10,8
11、); / 绘制木星卫星 - 木卫 2 glColor3f(0.5f,0.5f,0.5f); / 抵消地球自转影响/glRotatef(-rot1,0.0,1.0,0.0); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glRotatef(-90,1.0,0,0.0); / 设置木卫 2 公转速度glRotatef(rot11,0.0,1.0,0.0); / 设置木卫 2 公转半径glTranslatef(1.2,0.0,0.0); / 绘制木卫 2 glutSolidSphere(0.08,10,8); glPopMatrix(); / 绘制土星名师资料总结 - - -精
12、品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 8 页 - - - - - - - - - glPushMatrix(); glColor3f(1.0f, 1.0f, 0.0f); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 12.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置土星公转速度glRotatef(rot5,0.0,0.4,0.0); / 设置土星公转半径glTranslatef(12.
13、5,0.0,0.0); / 设置土星自传glRotatef(rot3,0.0,0.3,0.0); / 绘制土星glutSolidSphere(0.85,32,32); / 绘制土星光环glRotatef(90,1.0,0,0.0); glutSolidTorus(0.1, 1.25, 10, 64); glRotatef(-90,1.0,0,0.0); glRotatef(90,1.0,0,0.0); glutSolidTorus(0.07, 1.65, 10, 64); glRotatef(-90,1.0,0,0.0); glPopMatrix(); glPopMatrix(); / 绘制天
14、王星glPushMatrix(); glColor3f(0.0f, 1.0f, 1.0f); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 15.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置天王星公转速度glRotatef(rot6,0.0,0.4,0.0); / 设置天王星公转半径glTranslatef(15.5,0.0,0.0); / 设置天王星自传glRotatef(rot1,0.0,0.3,0.0); / 绘制天王星glutSolidSphere(0.15,32,32); glPop
15、Matrix(); / 绘制海王星名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 8 页 - - - - - - - - - glPushMatrix(); glColor3f(0.0f, 0.0, 8.0f); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 17.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置海王星公转速度glRotatef(rot7,0.0,0.4,0.
16、0); / 设置海王星公转半径glTranslatef(17.5,0.0,0.0); / 设置海王星自传glRotatef(rot3,0.0,0.3,0.0); / 绘制海王星glutSolidSphere(0.145,32,32); glPopMatrix(); / 绘制冥王星glPushMatrix(); glColor3f(0.5f, 0.5f, 0.5f); / 绘制辅助轨道glRotatef(90,1.0,0,0.0); glutSolidTorus(0.02, 19.5, 10, 64); glRotatef(-90,1.0,0,0.0); / 设置冥王星公转速度glRotatef
17、(rot8,0.0,0.4,0.0); / 设置冥王星公转半径glTranslatef(19.5,0.0,0.0); / 设置冥王星自传glRotatef(rot2,0.0,0.3,0.0); / 绘制冥王星glutSolidSphere(0.145,32,32); glPopMatrix(); glutSwapBuffers(); glFlush(); void idle() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 8 页 - - - - - - - - - r
18、ot0+=0.1; if(rot0=360.0) rot0-=360.0; rot1+=0.416; if(rot1=360.0) rot1-=360.0; rot2+=0.1631; if(rot2=360.0) rot2-=360.0; rot3+=0.053; if(rot3=360.0) rot3-=360.0; rot4+=0.0083; if(rot4=360.0) rot4-=360.0; rot5+=0.0034; if(rot5=360.0) rot5-=360.0; rot6+=0.00119; if(rot6=360.0) rot6-=360.0; rot7+=0.000
19、69; if(rot7=360.0) rot7-=360.0; rot8+=0.0008; if(rot8=360.0) rot8-=360.0; rot9+=1.0; if(rot9=360.0) rot9-=360.0; rot10+=0.005; if(rot10=360.0) rot10-=360.0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 8 页 - - - - - - - - - rot11+=0.01; if(rot11=360.0) rot11-
20、=360.0; glutPostRedisplay(); void reshape(int w,int h) glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0,(GLdouble)w/(GLdouble)h,1.0,100.0); glMatrixMode(GL_MODELVIEW); void main(int argc,char *argv) glutInit(&argc,argv); glutInitDisplayMode(GL
21、UT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(600,400); glutInitWindowPosition(500,500); glutCreateWindow(planet sim); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(idle); glutMainLoop(); return; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 8 页 - - - - - - - - -