太阳系行星运行模拟C++程序语言

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

太阳系行星运行模拟组员:2011年9月2日概述太阳系(SolarSystem)就是我们现在所在的恒星系统。它是以太阳为中心,和所有受到太阳引力约束的天体的集合体:8颗行星冥王星已被开除、至少165颗已知的卫星,和数以亿计的太阳系小天体。这些小天体包括小行星、柯伊伯带的天体、彗星和星际尘埃。广义上,太阳系的领域包括太阳、4颗像地球的内行星、由许多小岩石组成的小行星带、4颗充满气体的巨大外行星、充满冰冻小岩石、被称为柯伊伯带的第二个小天体区。在柯伊伯带之外还有黄道离散盘面、太阳圈和依然属于假设的奥尔特云。模拟太阳系不仅仅是完成作业,也能让我们更近一步的了解太阳系,拓广知识面,对行星的运行有基本的感性和理性感知。增加我们对宇宙探索的渴望,可能培养出又一批天文学家。OpenGL(全写OpenGraphicsLibrary)是个定义了一个跨编程语言、跨平台的编程接口的规格,它用于三维图象(二维的亦可)。OpenGL是个专业的图形程序接口,是一个功能强大,调用方便的底层图形库。OpenGL是一个开放的三维图形软件包,它独立于窗口系统和操作系统,以它为基础开发的应用程序可以十分方便地在各种平台间移植;OpenGL可以与VisualC++紧密接口,便于实现机械手的有关计算和图形算法,可保证算法的正确性和可靠性;OpenGL使用简便,效率高。它具有七大功能:1.建模:OpenGL图形库除了提供基本的点、线、多边形的绘制函数外,还提供了复杂的三维物体(球、锥、多面体、茶壶等)以及复杂曲线和曲面绘制函数。2.变换:OpenGL图形库的变换包括基本变换和投影变换。基本变换有平移、旋转、变比镜像四种变换,投影变换有平行投影(又称正射投影)和透视投影两种变换。其变换方法有利于减少算法的运行时间,提高三维图形的显示速度。3.颜色模式设置:OpenGL颜色模式有两种,即RGBA模式和颜色索引(ColorIndex)。4.光照和材质和镜面光(SpecularLight)。材质是用光反射率来表示。场景(Scene)中物体最终反映到人眼的颜色是光的红绿蓝分量与材质红绿蓝分量的反射率相乘后形成的颜色。5:纹理映射(TextureMapping)。利用OpenGL纹理映射功能可以十分逼真地表达物体表面细节。6:位图显示和图象增强图象功能除了基本的拷贝和像素读写外,还提供融合(Blending)、反走样(Antialiasing)和雾(fog)的特殊图象效果处理。以上三条可使被仿真物更具真实感,增强图形显示的效果。7:双缓存动画(DoubleBuffering)双缓存即前台缓存和后台缓存,简言之,后台缓存计算场景、生成画面,前台缓存显示后台缓存已画好的画面。此外,利用OpenGL还能实现深度暗示(DepthCue)、运动模糊(MotionBlur)等特殊效果。从而实现了消隐算法。具体实现利用VC6.0和OpenGL绘制太阳系模拟,以最简单的方式,新建一个win32consoleapplication,加入以下代码:#includewindows.h#includestdio.h#includestdlib.h#includegl/glut.h//行星GLfloatrot0=30.0;GLfloatrot1=0.0;GLfloatrot2=0.0;GLfloatrot3=0.0;GLfloatrot4=0.0;GLfloatrot5=0.0;GLfloatrot6=0.0;GLfloatrot7=0.0;GLfloatrot8=0.0;//卫星GLfloatrot9=0.0;GLfloatrot10=0.0;GLfloatrot11=0.0;voidinit(){glClearColor(0.0,0.0,0.0,0.0);glClearDepth(1.0);glShadeModel(GL_FLAT);}voiddisplay(){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,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);glutSolidTorus(0.02,5.0,10,64);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.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,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();//绘制金星glPushMatrix();glColor3f(0.0,1.0,0.0);//绘制辅助轨道glRotatef(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);//绘制辅助轨道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);//绘制辅助轨道glRotatef(90,1.0,0,0.0);glutSolidTorus(0.02,8.5,10,64);glRotatef(-90,1.0,0,0.0);//设置木星公转速度glRotatef(rot4,0.0,0.4,0.0);//设置木星公转半径glTranslatef(8.5,0.0,0.0);//设置木星自传glRotatef(rot3,0.0,0.3,0.0);//绘制木星glutSolidSphere(1.0,32,32);//绘制木星卫星-木卫1glColor3f(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);//绘制木卫1glutSolidSphere(0.1,10,8);//绘制木星卫星-木卫2glColor3f(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);//绘制木卫2glutSolidSphere(0.08,10,8);glPopMatrix();//绘制土星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.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();//绘制天王星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);glPopMatrix();//绘制海王星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);//设置海

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功