资源描述:
《《opengl计算机三维图形程序设计》魏刘宏11054126opengl第三次作业》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、魏刘宏11054126OpenGI第三次作业效果截图:点击运行后是这样的:其中包含Nurbs曲线和曲面;绿色的是曲面的控制顶点,红色的是曲线的控制顶点。按a键可向一个方向旋转:按d键可向另一个方向旋转:按C键可改变曲面的显示模式(有三种):改过的变形:代码:#ineludevwindows.h>#ineludeGLUnurbsObj*theNurb;GLfloatctrlpoints[5]⑸⑶={{{-3,0.5,0},{-1,1.5,0},{-2,2,0},{1,-5,0},{-4,0,0}},{{-3,0.5,-1},[
2、-1,1.5,-1},[-2,2,-1},{1,-5,-1},{-4,0,-1}},{{-3,0.5,-2},{J,1.5,-2},{-2,2,-2},{1,-5,-2},{-4,0,-2}},{{-3,0.5,-3},{-1,1.5,-3},{・2,2,-3},{1,-5,-3},{-4,0,-3}},{{-3,0.5,-4},{•],1.5,-4},{-2,2.-4}.{1,-5,-4},{-4,0,-4}}};〃控制点GLUnurbsObj*theNurb2;GLfloatctrlpoints2[8][3]={{4,0,0},{2.828,
3、2.828,0},{0,4,0},{-2.828,2.828,0},{-4,0,0},{-2.828,-2.828,0},{0,-4,0},{2.828,-2.828,0},};〃控制点GLfloatcolor[8][3]={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},{1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0},{1.0,1.0,1.0},{0.0,0.0,1.0}};voidmylnit(void){glClearColor(0.0,0.5,0.5,0.7);//设
4、置背景色glDepthFunc(GL_LEQUAL);glEnable(GL_DEPTH_TEST);glEnable(GL_LEQUAL);glEnable(GL_AUTO_NORMAL);glEnable(GL_NORMALIZE);glBlendFunc(GL_SRC_ALPHAzGL_ONE_MINUS_SRC_ALPHA);glHint(GL_UNE_SMOOTH_HINT,GL_DONT_CARE);glEnable(GL_BLEND);glFrontFace(GL_CW);glShadeModel(GL_SMOOTH);glEnab
5、le(GL_LINE_SMOOTH);theNurb二gluNewNurbsRenderer();//创建NURBS对象theNurbgluNurbsPropertyftheNurb,GLU_SAMPLING_TOLERANCE,20);gluNurbsProperty(theNurbzGLU_DISPLAY_MODE,GLU_OUTLINE_POLYGON);theNurb2=gluNewNurbsRenderer();//创建NURBS对象theNurb2gluNurbsProperty(theNurb2,GLU_SAMPLING_TOLER
6、ANCE,5);}intspin=10;//旋转的角度;intmode=0;〃曲面显示模式;staticvoidmyKey(unsignedcharkey,intx,inty){switch(key){cased':glRotatef(-spin,1.0,1.0,0.0);glutPostRedisplayO;break;cased:glRotatef(spin,1.0,1.0,0.0);glutPostRedisplayO;break;easel:mode++;讦(mode%3==0)gluNurbsProperty(theNurb,GLU_D
7、ISPLAY_MODE,GLU_OUTLINE_POLYGON);elseif(mode%3==1)gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);else讦(mode%3==2)gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_OUTLINE_PATCH);glutPostRedisplayO;break;case27:exit(O);default:break;}}voidmyDisplay(void){GLfloatknots[10]={0.0
8、,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0};glClear(GL_COLOR_BUFFER_BIT
9、GL