资源描述:
《计算机绘图雪人》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#includestaticGLfloatxRot=0.0f;staticGLfloatyRot=0.0f;voidReshape(intw,inth){glClear(GL_COLOR_BUFFER_BIT
2、GL_DEPTH_BUFFER_BIT);glClearColor(0.5f,0.5f,1.0f,0.5f);GLfloatScale;if(h==0)h=1;glViewport(0,0,w,h);Scale=(GLfloat)w/(GLfloat)h;glMatrixMode(GL_PROJECT
3、ION);glLoadIdentity()gluPerspective(40.0f,Scale,1.0,40.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}voidSpecialKeys(intkey,intx,inty){if(key==GLUT_KEY_UP)xRot-=1.0f;if(key==GLUT_KEY_DOWN)xRot+=1.0f;if(key==GLUT_KEY_LEFT)yRot-=1.0f;if(key==GLUT_KEY_RIGHT)yRot+=1.0f
4、;xRot=(GLfloat)((constint)xRot%360);yRot=(GLfloat)((constint)yRot%360);glutPostRedisplay();}voidDisplay(void){GLUquadricObj*pObj;glClear(GL_COLOR_BUFFER_BIT
5、GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslatef(0.0f,-1.0f,-5.0f);glRotatef(xRot,1.0f,0.0f,0.0f);glRotatef(yR
6、ot,0.0f,1.0f,0.0f);pObj=gluNewQuadric();gluQuadricNormals(pObj,GLU_SMOOTH);//MainBodyglPushMatrix();glColor3f(1.0f,1.0f,1.0f);gluSphere(pObj,.40f,26,13);//BottomglTranslatef(0.0f,.550f,0.0f);//MidsectiongluSphere(pObj,.3f,26,13);glTranslatef(0.0f,0.45f,0.0f);//Headgl
7、uSphere(pObj,0.24f,26,13);//EyesglColor3f(0.0f,0.0f,0.0f);glTranslatef(0.1f,0.1f,0.21f);gluSphere(pObj,0.02f,26,13);glTranslatef(-0.2f,0.0f,0.0f);gluSphere(pObj,0.02f,26,13);//NoseglColor3f(1.0f,0.3f,0.3f);glTranslatef(0.1f,-0.12f,0.0f);gluCylinder(pObj,0.04f,0.0f,0.
8、3f,26,13);glPopMatrix();//HatglPushMatrix();glColor3f(0.0f,0.0f,0.0f);glTranslatef(0.0f,1.17f,0.0f);glRotatef(-90.0f,1.0f,0.0f,0.0f);gluCylinder(pObj,0.17f,0.17f,0.4f,26,13);//HatbrimglDisable(GL_CULL_FACE);gluDisk(pObj,0.17f,0.28f,26,13);glEnable(GL_CULL_FACE);glTra
9、nslatef(0.0f,0.0f,0.40f);gluDisk(pObj,0.0f,0.17f,26,13);glPopMatrix();glPopMatrix();glutSwapBuffers();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE
10、GLUT_RGB
11、GLUT_DEPTH);glutInitWindowSize(800,600);glutCreateWindow("Snowman");glutR
12、eshapeFunc(Reshape);glutSpecialFunc(SpecialKeys);glutDisplayFunc(Display);glutMainLoop();return0;}