版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验报告课程名称:三维图形程序设计学院:计算机科学与工程专业:计算机科学与技术指导教师:曹跃学生姓名:郭小明学号:2011060100010实验成绩:日期:2013年5月10日电子科技大学计算机学院实验中心电 子 科 技 大 学实 验 报 告一、实验一:OpenGL光照与材质编程实验二、实验室名称:A2三、实验目的:1、理解OpenGL光照模型的相关原理,掌握与光照参数和对象材质设置相关的OpenGL API函数的用法,熟悉光照与材质参数设置的基本技巧;2、理解OpenGL混合(融合)的基本原理,掌握与混合相关的OpenGL API函数的用法。四、实验原理:OpenGL编程原理五、实验内容:(
2、一)编程任务1绘制一个具有光照的房间建立光照场景并为场景中的几何对象设置材质属性void CreateWorld()四面墙壁 void CreateWall()屋顶 void CreateCeiling()地板 void CreateGround()一个圆锥体和一个球体 void CreateFurnishings()在房间中创建并放置两个光源 void CreateLightAndProxy(void)一个是点光源一个是聚光灯;为光源创建代理几何体(Proxy),可以通过鼠标拖动光源代理来交互式的移动光源;绘制场景void DrawWorld(void)绘制四面墙壁 void DrawWal
3、l()绘制屋顶 void DrawCeiling()绘制地板 void DrawGround()绘制屋内物品 void DrawFurnishings()绘制光源代理 voidDrawLightProxy()其它要求:1、可交互式移动光源;2、可用右键菜单交互式的开启或关闭场景光照;3、可利用键盘快捷键调整球的材质属性,如辉度系数(GL_SHININESS)等。分析材质是如何影响几何对象的光照效果的。(二)编程任务2绘制一个具有地板反光效果的房间利用OpenGL混合功能可以模拟地板反光效果,这需要将地板和场景中其它物体分开处理,其基本思路如下:1、首先以上下颠倒的方式来绘制出地板镜像场景(即沿
4、着地板面将光源和场景进行镜像);2、接者利用混合在上述镜像场景之上绘制出半透明的地板;3、最后以正常的光源和场景位置来绘制场景。参考代码如下:void RenderScene(void) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); / 光源镜像移动到地板下,以照射这个“镜像”场景 glLightfv(GL_LIGHT0, GL_POSITION, fLightPosMirror); glPushMatrix(); /场景被镜像,同时交换正反面 glFrontFace(GL_CW); glScalef(1
5、.0f, -1.0f, 1.0f); DrawWorldExGround(); glFrontFace(GL_CCW); glPopMatrix(); / 在镜像场景上绘制一个半透明的地板 glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawGround(); glDisable(GL_BLEND); glEnable(GL_LIGHTING); / 恢复正常的光照,并正确绘制场景 glLightfv(GL_LIGHT0, GL_POSITION,
6、fLightPos); DrawWorldExGround(); glPopMatrix(); glutSwapBuffers(); 六、实验器材(设备、元器件):Microsoft Windows XP Professional 版本2002 Service Pack 3 VC+ 6.0七、实验数据及结果分析:(一)编程任务1绘制一个具有光照的房间#include #include #include #define SIZE 512GLint HITS;int flag_xyz = 1;int flag_light = 1;int mousex,mousey;float movex,move
7、y,movez;float PI = 3.1415926;void display();void drawSphere(GLfloat,GLfloat,GLfloat,int);float wide=0.8,height=0.8,Dept=0.8;void init()glEnable(GL_DEPTH_TEST);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);int wide_screen=300,height_screen=300;float eyex = 0.0,eyey = 0.0,eyez = 1.8;void reshape(
8、int w, int h)wide_screen = w;height_screen = h;glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60,1,1,3);/3.设置视景体,glFrustumgluLookAt(eyex,eyey,eyez,0,0,0,0,1,0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();float light_postion4=wide-0.2,height-0.2,-Dept,1;float light
9、_ambient 4=1.0,1.0,1.0,0.5;float light_diffuse 4=1.0,1.0,1.0,0.5;float light_specular 4=1.0,1.0,1.0,0.5;/float light_ambient 4=0.6,0.6,0.6,0.5;/float light_diffuse 4=0.4,0.4,0.4,0.5;/float light_specular 4=0.8,0.8,0.8,0.5;float proxy3 = wide-0.2,height-0.2,-Dept;void createLightAndProxy(GLenum mode)
10、glTranslatef(2*movex/wide_screen,2*movey/height_screen,2*movez/wide_screen);glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,1.5);glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0);/glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.0125);glLightfv(GL_LIGHT0,GL_POSITION,light_postion);glLightfv(GL_LIGHT0,GL_AMBIENT,l
11、ight_ambient);glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);if(mode = GL_SELECT)glLoadName(1);drawSphere(proxy0,proxy1-wide/12,proxy2,1);glTranslatef(-2*movex/wide_screen,-2*movey/height_screen,-2*movez/wide_screen);if(mode = GL_SELECT)glLoadName(2);vo
12、id create_wall()/glEnable(GL_FRONT_AND_BACK);/设置墙壁材质GLfloat Material_ambient4=0.6,0.2,0.5,0.5;GLfloat Material_diffuse4=0.8,0.2,0.5,0.5;GLfloat Material_specular4=0.0,0.0,0.5,1.0;GLfloat Material_shiness = 64.0;glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Material_ambient);glMaterialfv(GL_FRONT_AND_BAC
13、K,GL_DIFFUSE,Material_diffuse);glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Material_specular);glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,Material_shiness);glBegin(GL_QUADS);/近处的墙glColor3f(1.0,0,0.0);glNormal3f(0,0,-1);glVertex3f(wide,-height,Dept);glVertex3f(wide,height,Dept);glVertex3f(-wide,height,
14、Dept);glVertex3f(-wide,-height,Dept);/右边的墙glColor3f(1.0,0.5,0.8);glNormal3f(-1,0,0);glVertex3f(wide,-height,Dept);glVertex3f(wide,height,Dept);glVertex3f(wide,height,-Dept);glVertex3f(wide,-height,-Dept);/左边的墙glColor3f(0.0,1.0,0.0);glNormal3f(1,0,0);glVertex3f(-wide,-height,-Dept);glVertex3f(-wide,h
15、eight,-Dept);glVertex3f(-wide,height,Dept);glVertex3f(-wide,-height,Dept);/远处的墙glColor3f(1.0,0.5,0.4);glNormal3f(0,0,1);glVertex3f(wide,-height,-Dept);glVertex3f(wide,height,-Dept);glVertex3f(-wide,height,-Dept);glVertex3f(-wide,-height,-Dept);glEnd();void create_floor()glBegin(GL_QUADS);glColor4f(0
16、.5,0.4,0.4,0.6);glNormal3f(0,1,0);glVertex3f(-wide,-height,-Dept);glVertex3f(-wide,-height,Dept);glVertex3f(wide,-height,Dept);glVertex3f(wide,-height,-Dept);glEnd();void create_quad(int i,int j)if(i+j)%2 = 1 )glColor3f(0.0,0.5,0.5);elseglColor3f(0.0,0.0,0.0);glBegin(GL_QUADS);glVertex3f(-wide/16,0,
17、Dept/16);glVertex3f(-wide/16,0,-Dept/16);glVertex3f(wide/16,0,-Dept/16);glVertex3f(wide/16,0,Dept/16);glEnd();void create_ceil()int j =1;int i=1;glTranslatef(0,height,0);glNormal3f(0,-1,0);for(;j=16;j+)glTranslatef(-wide+j*wide/8-wide/16,0,0);/printf(%d ,j);for(i=1;i=16;i+)glTranslatef(0,0,-Dept+i*D
18、ept/8-Dept/16);create_quad(i,j);glTranslatef(0,0,Dept-i*Dept/8+Dept/16);glTranslatef(wide-j*wide/8+wide/16,0,0);glTranslatef(0,-height,0);void drawSphere(GLfloat xx=0,GLfloat yy=0,GLfloat zz=0,int flag=0)GLfloat radius;if(flag = 0)radius=2*wide/8;elseradius=wide/16;GLfloat M=20;GLfloat N=20;float st
19、ep_z = PI/M;float step_xy = 2*PI/N;float x4,y4,z4;float angle_z = 0.0;float angle_xy = 0.0;int i=0, j=0;if(flag = 0)glColor3f(0.5,0.25,0);elseglColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);for(i=0; iM; i+)angle_z = i * step_z;for(j=0; jN; j+)angle_xy = j * step_xy; x0 = radius * sin(angle_z) * cos(angle_x
20、y);y0 = radius * sin(angle_z) * sin(angle_xy);z0 = radius * cos(angle_z);x1 = radius * sin(angle_z + step_z) * cos(angle_xy);y1 = radius * sin(angle_z + step_z) * sin(angle_xy);z1 = radius * cos(angle_z + step_z);x2 = radius*sin(angle_z + step_z)*cos(angle_xy + step_xy);y2 = radius*sin(angle_z + ste
21、p_z)*sin(angle_xy + step_xy);z2 = radius*cos(angle_z + step_z);x3 = radius * sin(angle_z) * cos(angle_xy + step_xy);y3 = radius * sin(angle_z) * sin(angle_xy + step_xy);z3 = radius * cos(angle_z);for(int k=0; k4; k+)glNormal3f(xk,yk,zk);glVertex3f(xx+xk, yy+yk,zz+zk);glEnd();void yuanzhui()glTransla
22、tef(-wide/2,-height,-Dept/2);glBegin(GL_TRIANGLE_FAN);glColor3f(0,0.25,0.5);glNormal3f(1,1,1);glVertex3f(0,height/1.2,0);for(int i=0;i=32;i+)glVertex3f(0.2*cos(i*PI/16),0,0.2*sin(i*PI/16);glEnd();glTranslatef(wide/2,height,Dept/2);void createFurnishings()/glSolidSphere();glTranslatef(0,-height+2*wid
23、e/8,-Dept+2*Dept/8);drawSphere();glTranslatef(0,height-2*wide/8,Dept-2*Dept/8);yuanzhui();void draw(GLenum mode)glMatrixMode(GL_MODELVIEW);if(flag_light = 1)glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);elseglDisable(GL_LIGHTING);glDisable(GL_LIGHT0);createLightAndProxy(mode);create_wall();create_floor(
24、);create_ceil();createFurnishings();void RenderScene(GLenum mode)glTranslatef(0.0,2*height,0.0);glLightfv(GL_LIGHT0, GL_POSITION, light_postion);glFrontFace(GL_CW);glScalef(1.0f, -1.0f, 1.0f);create_wall();create_ceil();createFurnishings();/DrawWorldExGround();glScalef(1.0f, -1.0f, 1.0f);glFrontFace
25、(GL_CCW);glTranslatef(0.0,-2*height,0.0);glDisable(GL_LIGHTING);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);/DrawGround();create_floor();glDisable(GL_BLEND);glEnable(GL_LIGHTING);glLightfv(GL_LIGHT0, GL_POSITION, light_postion);/DrawWorldExGround();draw(GL_RENDER);void displ
26、ay()glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60,1,1,3);gluLookAt(eyex,eyey,eyez,0,0,0,0,1,0);draw(GL_RENDER);glFlush();glutSwapBuffers();int flag_move = 0 ;void process(GLint hits,GLuint buffer)unsigned int i, j;GLint names, *ptr;/p
27、rintf (hits = %dn, hits);ptr = (GLint *) buffer;for (i = 0; i hits; i+) /* for each hit */names = *ptr;ptr+=3;for (j = 0; j names; j+) /* for each name */if(*ptr=1)flag_move = 1;ptr+;GLuint select_BufferSIZE;void mouse(int key,int state,int x,int y)GLint hits;GLint viewport4;if(key = GLUT_LEFT_BUTTO
28、N & state = GLUT_DOWN)mousex = x;mousey = y;glGetIntegerv(GL_VIEWPORT,viewport);glSelectBuffer(SIZE,select_Buffer);glRenderMode(GL_SELECT);glInitNames();glPushName(0);glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();gluPickMatrix(GLdouble)x,(GLdouble)(viewport3-y),5,5,viewport);gluPerspec
29、tive(60,1,1,3);gluLookAt(eyex,eyey,eyez,0,0,0,0,1,0);draw(GL_SELECT);glMatrixMode(GL_PROJECTION);glPopMatrix();glFlush();hits = glRenderMode(GL_RENDER);process(hits,select_Buffer);HITS = hits;glutPostRedisplay();if(key = GLUT_LEFT_BUTTON & state = GLUT_UP)flag_move = 0;void motion(int x,int y)if(fla
30、g_move = 0)return;elseswitch(flag_xyz)case 1:case 2:movex = x-mousex+movex;movey = -y+mousey+movey;break;case 3:movez = x-mousex+movez;break;/display(GL_RENDER);glutPostRedisplay();mousex = x;mousey = y;/printf(%fn,movey);void keyboard(unsigned char key,int x,int y)/printf(%c ,key);switch(key)case x
31、:eyex -=0.1;break;case y:eyey -=0.1;break;case z:eyez -=0.1;break;case X:eyex +=0.1;break;case Y:eyey +=0.1;break;case Z:eyez +=0.1;break;case h:case H:flag_xyz = 1;break;case s:case S:flag_xyz = 2;break;case l:case L:flag_xyz = 3;break;default:return;break;/printf( %f %f %fn,eyex,eyey,eyez);glutPos
32、tRedisplay();void MenuFunc(int data)switch(data)case 1:flag_light = 0;break;case 2:flag_light = 1;break;default:break;glutPostRedisplay();int Menu;int main(int argc,char * argv)glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glutInit(&argc,argv);glutInitWindowSize(wide_screen,height_screen);glu
33、tCreateWindow(“郭小明的房间”);init();Menu = glutCreateMenu(MenuFunc);glutAddMenuEntry(关闭光源!,1);glutAddMenuEntry(打开光源!,2);glutAttachMenu(GLUT_RIGHT_BUTTON);glutDisplayFunc(display);glutKeyboardFunc(keyboard);glutMouseFunc(mouse);glutMotionFunc(motion);glutKeyboardFunc(keyboard);glutReshapeFunc(reshape);glu
34、tMainLoop();return 0;打开光源时郭小明的房间的情形通过右键菜单关闭光源之后郭小明房间的情形改变视角方向和位置之后的看到的房间的外围图形(二)编程任务2绘制一个具有地板反光效果的房间#include #include #include #define SIZE 512GLint HITS;int flag_xyz = 1;int flag_light = 1;int mousex,mousey;float movex,movey,movez;float PI = 3.1415926;void display();void drawSphere(GLfloat,GLfloat,
35、GLfloat,int);float wide=0.8,height=0.8,Dept=0.8;void init()glEnable(GL_DEPTH_TEST);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);int wide_screen=300,height_screen=300;float eyex = 0,eyey = 0,eyez = 1.7;void reshape(int w, int h)wide_screen = w;height_screen = h;glViewport(0, 0, w, h);glMatrixMo
36、de(GL_PROJECTION);glLoadIdentity();/gluOrtho2D (-2.0*wide, 2.0*wide, -2.0*height, 2.0*height);gluPerspective(60,1,1,30);/3.设置视景体,glFrustum/glFrustum(-0.8,0.8,-0.8,0.8,1,3);gluLookAt(eyex,eyey,eyez,0,0,0,0,1,0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();float light_postion4=wide-0.2,height-0.2,-Dept
37、,1;float light_ambient 4=1.0,1.0,1.0,0.5;float light_diffuse 4=1.0,1.0,1.0,0.5;float light_specular 4=1.0,1.0,1.0,0.5;float proxy3 = wide-0.2,height-0.2,-Dept;void createLightAndProxy(GLenum mode)glTranslatef(2*movex/wide_screen,2*movey/height_screen,2*movez/wide_screen);/设置光源相关glLightf(GL_LIGHT0,GL
38、_CONSTANT_ATTENUATION,1.5);glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0);glLightfv(GL_LIGHT0,GL_POSITION,light_postion);glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);if(mode = GL_SELECT)glLoadName(1);if(flag_
39、light = 1)drawSphere(proxy0,proxy1-wide/12,proxy2,1);glTranslatef(-2*movex/wide_screen,-2*movey/height_screen,-2*movez/wide_screen);if(mode = GL_SELECT)glLoadName(2);void create_wall()/glEnable(GL_FRONT_AND_BACK);/设置墙壁材质GLfloat Material_ambient4=0.6,0.2,0.5,0.5;GLfloat Material_diffuse4=0.8,0.2,0.5,
40、0.5;GLfloat Material_specular4=0.0,0.0,0.5,1.0;GLfloat Material_shiness = 64.0;glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Material_ambient);glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Material_diffuse);glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Material_specular);glMaterialf(GL_FRONT_AND_BACK,GL_SHININ
41、ESS,Material_shiness);glBegin(GL_QUADS);/近处的墙glColor3f(0.6,0,0.0);glNormal3f(0,0,-1);glVertex3f(wide,-height,Dept);glVertex3f(wide,height,Dept);glVertex3f(-wide,height,Dept);glVertex3f(-wide,-height,Dept);/右边的墙glColor3f(0.5,0.5,0.8);glNormal3f(-1,0,0);glVertex3f(wide,-height,Dept);glVertex3f(wide,he
42、ight,Dept);glVertex3f(wide,height,-Dept);glVertex3f(wide,-height,-Dept);/左边的墙glColor3f(0.5,0.5,0.8);glNormal3f(1,0,0);glVertex3f(-wide,-height,-Dept);glVertex3f(-wide,height,-Dept);glVertex3f(-wide,height,Dept);glVertex3f(-wide,-height,Dept);/远处的墙glColor3f(0.5,0.5,0.8);glNormal3f(0,0,1);glVertex3f(w
43、ide,-height,-Dept);glVertex3f(wide,height,-Dept);glVertex3f(-wide,height,-Dept);glVertex3f(-wide,-height,-Dept);glEnd();void create_floor()glBegin(GL_QUADS);glColor4f(0.4,0.3,0.3,0.6);glNormal3f(0,-1,0);glVertex3f(-wide,-height,-Dept);glVertex3f(wide,-height,-Dept);glVertex3f(wide,-height,Dept);glVe
44、rtex3f(-wide,-height,Dept);glEnd();void create_quad(int i,int j)if(i+j)%2 = 1 )glColor3f(0.0,0.5,0.5);elseglColor3f(0.0,0.0,0.0);glBegin(GL_QUADS);glVertex3f(-wide/16,0,Dept/16);glVertex3f(wide/16,0,Dept/16);glVertex3f(wide/16,0,-Dept/16);glVertex3f(-wide/16,0,-Dept/16);glEnd();void create_ceil()int
45、 j =1;int i=1;glTranslatef(0,height,0);glNormal3f(0,1,0);for(;j=16;j+)glTranslatef(-wide+j*wide/8-wide/16,0,0);/printf(%d ,j);for(i=1;i=16;i+)glTranslatef(0,0,-Dept+i*Dept/8-Dept/16);create_quad(i,j);glTranslatef(0,0,Dept-i*Dept/8+Dept/16);glTranslatef(wide-j*wide/8+wide/16,0,0);glTranslatef(0,-heig
46、ht,0);void drawSphere(GLfloat xx=0,GLfloat yy=0,GLfloat zz=0,int flag=0)GLfloat radius;if(flag = 0)radius=2*wide/8;elseradius=wide/16;GLfloat M=20;GLfloat N=20;float step_z = PI/M;float step_xy = 2*PI/N;float x4,y4,z4;float angle_z = 0.0;float angle_xy = 0.0;int i=0, j=0;if(flag = 0)glColor3f(0.5,0.
47、25,0);elseglColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);for(i=0; iM; i+)angle_z = i * step_z;for(j=0; jN; j+)angle_xy = j * step_xy; x0 = radius * sin(angle_z) * cos(angle_xy);y0 = radius * sin(angle_z) * sin(angle_xy);z0 = radius * cos(angle_z);x1 = radius * sin(angle_z + step_z) * cos(angle_xy);y1 = ra
48、dius * sin(angle_z + step_z) * sin(angle_xy);z1 = radius * cos(angle_z + step_z);x2 = radius*sin(angle_z + step_z)*cos(angle_xy + step_xy);y2 = radius*sin(angle_z + step_z)*sin(angle_xy + step_xy);z2 = radius*cos(angle_z + step_z);x3 = radius * sin(angle_z) * cos(angle_xy + step_xy);y3 = radius * si
49、n(angle_z) * sin(angle_xy + step_xy);z3 = radius * cos(angle_z);for(int k=0; k4; k+)glNormal3f(xk,yk,zk);glVertex3f(xx+xk, yy+yk,zz+zk);glEnd();void yuanzhui()glTranslatef(-wide/2,-height,-Dept/2);glBegin(GL_TRIANGLE_FAN);glColor3f(0,0.25,0.5);glNormal3f(1,1,1);glVertex3f(0,height/1.2,0);for(int i=0
50、;i=32;i+)glVertex3f(0.2*cos(i*PI/16),0,0.2*sin(i*PI/16);glEnd();glBegin(GL_TRIANGLE_FAN);glColor3f(0,0.25,0.5);glNormal3f(0,1,0);glVertex3f(0,0,0);for(int i=0;i=32;i+)glVertex3f(0.2*cos(i*PI/16), 0.01 , 0.2*sin(i*PI/16);glEnd();glTranslatef(wide/2,height,Dept/2);void createFurnishings()/glSolidSpher
51、e();glTranslatef(0,-height+2*wide/8,-Dept+2*Dept/8);drawSphere();glTranslatef(0,height-2*wide/8,Dept-2*Dept/8);yuanzhui();void draw(GLenum mode)glMatrixMode(GL_MODELVIEW);if(flag_light = 1)glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);elseglDisable(GL_LIGHTING);glDisable(GL_LIGHT0);createLightAndProxy(m
52、ode);create_wall();create_floor();create_ceil();createFurnishings();void RenderScene(GLenum mode)glMatrixMode(GL_MODELVIEW);if(flag_light = 1)glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);elseglDisable(GL_LIGHTING);glDisable(GL_LIGHT0);glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,1.5);glLightf(GL_LIGHT0,G
53、L_LINEAR_ATTENUATION,0);glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);glTranslatef(0.0 , -2*height , 0.0);glFrontFace(GL_CW);glScalef(1.0f, -1.0f, 1.0f);glTranslatef(2*movex/wide_screen,2*movey/height_scree
54、n,2*movez/wide_screen);glLightfv(GL_LIGHT0,GL_POSITION,light_postion);glTranslatef(-2*movex/wide_screen,-2*movey/height_screen,-2*movez/wide_screen);create_wall();create_ceil();createFurnishings();glScalef(1.0f, -1.0f, 1.0f);glTranslatef(0.0 , 2*height , 0.0);glFrontFace(GL_CCW);glDisable(GL_LIGHTIN
55、G);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);create_floor();glDisable(GL_BLEND);glEnable(GL_LIGHTING);draw(mode);void display()glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60,1,1,30);gluLookAt(eyex,eyey,eyez,0
56、,0,0,0,1,0);/draw(GL_RENDER);RenderScene(GL_RENDER);glFlush();glutSwapBuffers();int flag_move = 0 ;void process(GLint hits,GLuint buffer)unsigned int i, j;GLint names, *ptr;/printf (hits = %dn, hits);ptr = (GLint *) buffer;for (i = 0; i hits; i+) /* for each hit */names = *ptr;ptr+=3;for (j = 0; j n
57、ames; j+) /* for each name */if(*ptr=1)flag_move = 1;ptr+;GLuint select_BufferSIZE;void mouse(int key,int state,int x,int y)GLint hits;GLint viewport4;if(key = GLUT_LEFT_BUTTON & state = GLUT_DOWN)mousex = x;mousey = y;glGetIntegerv(GL_VIEWPORT,viewport);glSelectBuffer(SIZE,select_Buffer);glRenderMode(G
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 课程设计中表名规则
- 课程设计和优化的区别
- 2024至2030年中国变频恒温培养摇床数据监测研究报告
- 2024年相框钟项目可行性研究报告
- 2024至2030年中国成人手指血氧探头数据监测研究报告
- 2024年抑烟型三氧化二锑项目可行性研究报告
- 2024至2030年中国CMOS数码相机数据监测研究报告
- 电容流水灯实验课程设计
- 中国食品安全检测仪器行业消费动态及应用前景预测研究报告(2024-2030版)
- 中国除皱美容市场营销模式与竞争优势分析研究报告(2024-2030版)
- 《江苏省一年级上学期数学第二单元试卷》
- 2024-2025学年度第一学期七年级语文课内阅读练习含答案
- 上海市普通高中学业水平合格性考试地理基础知识点复习提纲
- 废旧风机叶片循环利用项目可行性研究报告-积极稳妥推进碳达峰碳中和
- 中医脑病科缺血性中风(脑梗死恢复期)中医诊疗方案临床疗效分析总结
- 中国人工智能系列白皮书一元宇宙技术(2024 版)
- 《甘肃省中医康复中心建设标准(2021版)》
- 高中英语外刊-小猫钓鱼50篇
- PowerPoint培训教程课件
- 医疗绿色通道医联体协议书
- 高考名句名篇《菩萨蛮 书江西造口壁》课件
评论
0/150
提交评论