收藏 分享(赏)

计算机图形学实验_透视茶壶源代码.doc

上传人:yjrm16270 文档编号:4572808 上传时间:2019-01-02 格式:DOC 页数:5 大小:28.50KB
下载 相关 举报
计算机图形学实验_透视茶壶源代码.doc_第1页
第1页 / 共5页
计算机图形学实验_透视茶壶源代码.doc_第2页
第2页 / 共5页
计算机图形学实验_透视茶壶源代码.doc_第3页
第3页 / 共5页
计算机图形学实验_透视茶壶源代码.doc_第4页
第4页 / 共5页
计算机图形学实验_透视茶壶源代码.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、#include#include#includeusing namespace std;float fTranslate;float fRotate;float fScale=1.0f;/set inital scale value to 1.0fbool bPersp=false;bool bAnim=false;bool bWire=false;int wHeight=0;int wWidth=0;/todo/hint:some additional parameters may needed here when you operate the teapotvoid Draw_Leg()g

2、lScalef(1,1,3);glutSolidCube(1.0f);/glutWireCone(1.0f);/定义操作茶壶的操作参数int tx=1;int ty=0;int tz=0;int tangle=90;/定义设置 scale 的参数float sx=0.3f;float sy=0.3f;float sz=0.3f;void Draw_Scene()glPushMatrix();glTranslatef(0,0,5);glRotatef(tangle,tx,ty,tz);/ glutSolidTeapot(1);glutSolidSphere(1.0f,10,10);glPopMa

3、trix();glPushMatrix();glTranslatef(0,0,3.5);glScalef(5,4,1);glutSolidCube(1.0);glPopMatrix();/leg1glPushMatrix();glTranslatef(1.5,1,1.5);Draw_Leg();glPopMatrix();/leg2glPushMatrix();glTranslatef(-1.5,1,1.5);Draw_Leg();glPopMatrix();/leg3glPushMatrix();glTranslatef(1.5,-1,1.5);Draw_Leg();glPopMatrix(

4、);/leg4glPushMatrix();glTranslatef(-1.5,-1,1.5);Draw_Leg();glPopMatrix();void updateView(int width,int height)glViewport(0,0,width,height);/reset the current viewportglMatrixMode(GL_PROJECTION);/select the projection matrixglLoadIdentity();/reset the projection matrixfloat whRatio=(GLfloat)width/(GL

5、float)height;if(bPersp)/todo when poperation ,hint:use function glupersPectiveelseglOrtho(-3,3,-3,3,-100,100);glMatrixMode(GL_MODELVIEW);/select the modelview matrixvoid reshape(int width,int height)if(height=0)/prevent a divide by zero byheight=1;wHeight=height;wWidth=width;updateView(wHeight,wWidt

6、h);void idle()glutPostRedisplay();float eye=0,0,8;float center=0,0,0;/todo:hint:you may need another array when you operate the teapotvoid key(unsigned char k,int x,int y)switch(k)case 27:case q:exit(0);break;case p:bPersp=!bPersp;updateView(wHeight,wWidth);break;case :bAnim=!bAnim;break;case o:bWir

7、e=!bWire;break;case a:center0=center0+1;break;/todo ,hint:eyeand centerare the keys to solve the problemscase d:center0=center0-1;break;case w:center2=center2+1;break;case s:center2=center2-1;break;case z:center1=center1+1;break;case c:center1=center1-1;break;case r:center0=0;center1=0;center2=0;/恢复

8、原状/茶壶相关操作case j:tx+;break;case l:tx-;break;case i:ty+;break;case k:ty-;break;case n:tz+;break;case m:tz-;ty-;break;case g:sx=sy=sz=sx+0.05;break;/放大case f:sx=sy=sz=sx-0.05;break;/缩小void redraw()glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glLoadIdentity();gluLookAt(eye0,eye1,eye2,center0,center1

9、,center2,0,1,0);/场景(0,0,0)扥视点中心(0,5,50)Y 轴向上if(bWire)glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);elseglPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);GLfloat white=1.0,1.0,1.0,1.0;GLfloat light_pos=5,5,5,1;glLightfv(GL_LIGHT0,GL_POSITION,light_pos);glLightfv(GL_LIG

10、HT0,GL_AMBIENT,white);glEnable(GL_LIGHT0);glRotatef(fRotate,0,0,1.0f);/ratate around y axisglRotatef(-90,1,0,0);glScalef(sx,sy,sz);Draw_Scene();if(bAnim)fRotate+=0.3f;/todo hint:when you want to rotate the teepot you may like to add another line here =glutSwapBuffers();int main(int argc,char*argv)glutInit(glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);glutInitWindowSize(480,480);int windowHandle=glutCreateWindow(“Simple GLUT App“);glutDisplayFunc(redraw);glutReshapeFunc(reshape);glutKeyboardFunc(key);glutIdleFunc(idle);glutMainLoop();return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 中等教育 > 中学实验

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报