- 2022-08-30 发布 |
- 37.5 KB |
- 3页
申明敬告: 本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
文档介绍
计算机绘图雪人
#include
staticGLfloatxRot=0.0f;staticGLfloatyRot=0.0f;voidReshape(intw,inth){glClear(GL_COLOR_BUFFER_BIT|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_PROJECTION);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)\nyRot+=1.0f;xRot=(GLfloat)((constint)xRot%360);yRot=(GLfloat)((constint)yRot%360);glutPostRedisplay();}voidDisplay(void){GLUquadricObj*pObj;glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslatef(0.0f,-1.0f,-5.0f);glRotatef(xRot,1.0f,0.0f,0.0f);glRotatef(yRot,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);//HeadgluSphere(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.3f,26,13);glPopMatrix();\n//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);glTranslatef(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|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(800,600);glutCreateWindow("Snowman");glutReshapeFunc(Reshape);glutSpecialFunc(SpecialKeys);glutDisplayFunc(Display);glutMainLoop();return0;}
查看更多