您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 其它文档 > 计算机图形学(OpenGL技术)太阳系动画
#includegl/glut.h#includestdlib.hfloatfEarth=2.0f;floatfMood=24.0f;voidInit(){glEnable(GL_DEPTH_TEST);glClearColor(0.0f,0.0f,0.0f,0.8f);}voidDisplay(){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();//»Ì«ÑôglTranslated(0.0f,0.0f,-500.0f);glColor3f(1.0f,0.0f,0.0f);glutSolidSphere(50,20,20);//»µØÇòglColor3f(0.0f,0.0f,1.0f);glRotatef(23.27,0.0f,0.0f,1.0f);glRotatef(fEarth,0.0f,1.0f,0.0f);glTranslated(200.0f,0.0f,0.0f);glutSolidSphere(20.0,10,16);//»ÔÂÇòglPopMatrix();glPopMatrix();glRotatef(6.0,1.0f,1.0f,1.0f);glRotatef(fMood,0.0f,1.0f,0.0f);glTranslated(30.0f,0.0f,0.0f);glColor3f(1.0f,1.0f,0.0f);glutSolidSphere(5,20,20);glLoadIdentity();glFlush();glutSwapBuffers();}voidmyIdle(){fEarth+=0.03;if(fEarth360.0f)fEarth=0.2f;fMood+=0.24f;if(fMood360.0f)fMood=24.0f;Display();}voidreshape(intw,inth){if(h==0)h=0;glViewport(0,0,w,h);//ÉèÖÃÊÓÇø´óСglMatrixMode(GL_PROJECTION);//glLoadIdentity();gluPerspective(45.0f,w/h,1.0f,1000.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(500,500);glutCreateWindow(Ì«Ñôϵ¶¯»);glutDisplayFunc(Display);glutReshapeFunc(reshape);glutIdleFunc(&myIdle);Init();glutMainLoop();return0;}
本文标题:计算机图形学(OpenGL技术)太阳系动画
链接地址:https://www.777doc.com/doc-5147886 .html