7创建一个空白Win32控制台应用程序将以下代码复制到刚刚配置好的vs中#include #include #include #include 'gl/glut.h'//行星//与地球公转相关参数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(){//清除颜色缓冲区的值 glClearColor(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);//表示将当前图形向Z轴负方向平移20 glTranslatef(0.0, 0.0, -20.0);//绕X轴旋转90度 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);//绕X轴旋转-90度 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(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); // 设置海王星公转速度 glRotatef(rot7, 0.0, 0.4, 0.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(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(){ rot0 += 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.00069; 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; rot11 += 0.01; if (rot11 >= 360.0) rot11 -= 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(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);//设置初始窗口大小 glutInitWindowSize(600, 400);//设置初始窗口位置 glutInitWindowPosition(500, 500);//创建窗口 glutCreateWindow('planet sim'); init();//显示 glutDisplayFunc(display);//重构 glutReshapeFunc(reshape);//设置全局的回调函数 glutIdleFunc(idle); glutMainLoop(); return;}编译运行后出现下图环境配置成功,若不成功检查以上步骤重新完成以上操作。