模拟太阳、地球和月亮
2015-01-02 10:06
399 查看
代码如下:
#include <windows.h> //#include <GLUT/glut.h> #include <GL/glut.h> #include <math.h> #include <iostream> using namespace std; #define GL_PI 3.1415f void RenderScene() { static float fMoonRot = 0.0f; static float fEarthRot = 0.0f; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(0.0f,0.0f,-300.0f); glColor3ub(255,255,0); glutSolidSphere(25.0f,25,25); glRotatef(fEarthRot,0.0f,1.0f,0.0f); glColor3ub(0,0,255); glTranslatef(0.0f,0.0f,-105.0f); glutSolidSphere(15.0f,15,15); glColor3ub(200,200,200); glRotatef(fMoonRot,0.0f,1.0f,0.0f); glTranslatef(0.0f,0.0f,-30.0f); fMoonRot += 15.0f; if(fMoonRot > 360.0f) fMoonRot = 0.0f; glutSolidSphere(6.0f,15,15); glPopMatrix(); fEarthRot += 5.0f; if(fEarthRot > 360.0f) fEarthRot = 0.0f; glutSwapBuffers(); } void ChangeSize(GLsizei w,GLsizei h) { if(h==0) h = 1; GLfloat aspectRatio = (GLfloat)w/(GLfloat)h; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,aspectRatio,1.0,425.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void SetupRC() { glClearColor(0.0f,0.0f,0.0f,1.0f); glColor3f(0.0f,1.0f,0.0f); glEnable(GL_DEPTH_TEST); } void TimerFunction(int value) { glutPostRedisplay(); glutTimerFunc(33,TimerFunction,1); } int main(int argc, char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(800,600); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); glutTimerFunc(33,TimerFunction,1); SetupRC(); glutMainLoop(); return 0; }
相关文章推荐
- 关于OpenGL入门中地球,月亮,太阳运动模拟无法显示的问题(只显示黑框)
- 基于C#的2D太阳、地球、月亮运动轨迹模拟实现
- SVG 模拟太阳 地球 月亮旋转
- 运用Python 模拟太阳-地球-月亮运动模型
- OpenGL模拟太阳、地球、月球公转自转
- OpenGL “太阳、地球和月亮”天体运动动画 例子
- WPF太阳、地球、月球运动轨迹模拟
- Canvas模拟太阳地球月球的运动过程
- OpenGL:太阳、地球、月球模型模拟动画
- OpenGL 地球,月亮,太阳 相对运动
- [HTML5-SVG]使用svg、CSS3、raphaeljs:模拟月球绕地球,地球绕太阳旋转
- 太阳、地球、月亮
- opengl: 太阳地球和月亮
- OpenGL入门记录--“太阳,地球和月亮”系统代码
- Transform类 RotateAround() 太阳、地球、月亮围绕旋转
- 太阳、地球、月亮
- 太阳和地球间有神秘磁性通道 8分钟开启一次
- 地球太阳间发现磁性隧道 每8分钟接通一次
- 《佛密诸事》第二十二章:太阳与地球智慧生命
- 一张纸折51次,有多高?一个冰箱?一层楼?或者一栋摩天大厦?NO,你错了.这个厚度超过了地球和太阳之间的距离。