计算机图形学曲线曲面

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

计算机图形学实验报告051北方工业大学计算机图形学课程实验报告题目:实验五曲线曲面学院:计算机学院专业:数字媒体技术指导教师:蔡兴泉学生班级:学生学号:学生姓名:教师评定:计算机图形学实验报告052实验报告5曲线曲面一.实验目的1.熟悉OpenGL图形库;2.掌握曲线曲面实现算法。二.实验环境1.软件环境:操作系统:WinXp应用软件:VC6.0,OpenGL2.硬件环境(查看自己的机子)CPU:IntelPIV2.80GHz内存RAM:1GB显卡:NVIDIAGeForce7650,256M显存三.实验内容1.写程序实现Bezier曲线2.写程序实现绘制3个半径不同、颜色不同的小球3.写程序实现一个场景,绘制1个立方体、1个圆锥、1个圆柱、1个茶壶四.程序及结果1.Bezier曲线实现关键程序及注释voidRenderScene(void){inti;glClear(GL_COLOR_BUFFER_BIT)//设置贝塞尔曲线glMap1f(GL_MAP1_VERTEX_3,//生成的数据类型0.0f,//u值的下界100.0f,///u值的上界3,//顶点在数据中的间隔,x,y,z所以间隔是3nNumPoints,//u方向上的阶,即控制点的个数&ctrlPoints[0][0]);//指向控制点数据的指针glEnable(GL_MAP1_VERTEX_3);////必须在绘制顶点之前开启glBegin(GL_LINE_STRIP);//使用画线的方式来连接点for(i=0;i=100;i++){glEvalCoord1f((GLfloat)i);//求的点坐标}glEnd();计算机图形学实验报告053DrawPoints();//画点glutSwapBuffers();//交换两个缓冲区指针}2.小球绘制实现关键程序及注释voidRenderScene(void){GLUquadricObj*pObj;//定义QuadricObjectglClear(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);//glPushMatrix();glColor3f(1.0f,1.0f,1.0f);//定义颜色为白glTranslatef(0.0f,1.0f,0.0f);//圆心坐标gluSphere(pObj,.3f,26,13);//绘制小球半径为0.3glPopMatrix();glPushMatrix();glColor3f(1.0f,0.0f,0.0f);//定义颜色为红glTranslatef(0.0f,0.0f,0.0f);//圆心坐标gluSphere(pObj,.5f,26,13);//绘制小球半径为0.5glPopMatrix();//glPushMatrix();//glColor3f(0.0f,0.0f,0.0f);//定义颜色为黑glTranslatef(0.0f,2.0f,0.0f);//圆心坐标gluSphere(pObj,0.2f,26,13);//绘制小球半径为0.2glPopMatrix();glPopMatrix();//恢复矩阵状态glutSwapBuffers();//交换缓冲}计算机图形学实验报告0543.场景绘制实现关键程序及注释voidRenderScene(void){GLUquadricObj*pObj;//定义QuadricObjectglClear(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);//绘制正方体glBegin(GL_QUADS);//顶面glNormal3f(0.0f,1.0f,0.0f);glVertex3f(0.5f,0.5f,0.5f);glVertex3f(0.5f,0.5f,-0.5f);glVertex3f(-0.5f,0.5f,-0.5f);glVertex3f(-0.5f,0.5f,0.5f);glEnd();glBegin(GL_QUADS);//底面glNormal3f(0.0f,-1.0f,0.0f);glVertex3f(0.5f,-0.5f,0.5f);glVertex3f(-0.5f,-0.5f,0.5f);glVertex3f(-0.5f,-0.5f,-0.5f);glVertex3f(0.5f,-0.5f,-0.5f);glEnd();glBegin(GL_QUADS);//前面计算机图形学实验报告055glNormal3f(0.0f,0.0f,1.0f);glVertex3f(0.5f,0.5f,0.5f);glVertex3f(-0.5f,0.5f,0.5f);glVertex3f(-0.5f,-0.5f,0.5f);glVertex3f(0.5f,-0.5f,0.5f);glEnd();glBegin(GL_QUADS);//背面glNormal3f(0.0f,0.0f,-1.0f);glVertex3f(0.5f,0.5f,-0.5f);glVertex3f(0.5f,-0.5f,-0.5f);glVertex3f(-0.5f,-0.5f,-0.5f);glVertex3f(-0.5f,0.5f,-0.5f);glEnd();glBegin(GL_QUADS);//左面glNormal3f(-1.0f,0.0f,0.0f);glVertex3f(-0.5f,0.5f,0.5f);glVertex3f(-0.5f,0.5f,-0.5f);glVertex3f(-0.5f,-0.5f,-0.5f);glVertex3f(-0.5f,-0.5f,0.5f);glEnd();glBegin(GL_QUADS);//右面glNormal3f(1.0f,0.0f,0.0f);glVertex3f(0.5f,0.5f,0.5f);glVertex3f(0.5f,-0.5f,0.5f);glVertex3f(0.5f,-0.5f,-0.5f);glVertex3f(0.5f,0.5f,-0.5f);glEnd();//绘制圆锥glPushMatrix();glColor3f(1.0f,0.6f,0.3f);glTranslatef(0.0f,0.5f,0.0f);glRotatef(-90.0f,1.0f,0.0f,0.0f);gluCylinder(pObj,0.18f,0.0f,0.3f,26,13);glPopMatrix();//绘制圆柱glPushMatrix();glColor3f(0.0f,0.0f,0.0f);glTranslatef(0.0f,1.3f,0.0f);glRotatef(-90.0f,1.0f,0.0f,0.0f);gluCylinder(pObj,0.17f,0.17f,0.4f,26,13);glDisable(GL_CULL_FACE);计算机图形学实验报告056gluDisk(pObj,0.28f,0.28f,26,13);glTranslatef(0.0f,0.0f,0.40f);gluDisk(pObj,0.0f,0.17f,26,13);glPopMatrix();/绘制/茶壶glPushMatrix();glColor3f(0.0f,1.0f,1.0f);glTranslatef(0.0f,1.0f,0.0f);glutSolidTeapot(0.25f);glPopMatrix();glPopMatrix();//glutSwapBuffers();//交换缓冲}五.实验收获通过这次实验,我熟悉了OpenGL图形库,掌握了曲线曲面的算法,.掌握了了Bezier曲线的实现,和基本基本几何体如球体、圆锥、圆柱、茶壶、立方体的画法。六.编程中遇到的问题,如何解决的在编程的过程中,我遇到了几何体只能显示部分的问题,后删除了glEnable(GL_CULL_FACE)语句解决该问题。遇到圆柱和圆锥不能同时出现在屏幕上,只能显示圆锥或圆柱,后来我在绘制圆锥和圆柱的时候都加上了glPushMatrix();和glPopMatrix();语句解决了问题。

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功