资源描述:
《图形学实验报告四.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《计算机图形学》实验报告详细代码:@qq.com一、实验目的1,使用opengl函数完成一个图形动画程序,显示太阳、地球、月亮之间的运行关系。2,采用opengl材质、光照技术完成一个在小盒内的运动小球,要求小球作为移动光源,观察运行效果。二、实验要求1.掌握Window图形编程的基本方法;2.掌握如何进行简单动画制作3.掌握如何采用opengl材质、光照技术三、实验设备(环境)Windows系统,vs2017四、实验步骤与结果1.使用opengl函数完成一个图形动画程序,显示太阳、地球、月亮之间
2、的运行关系。使用的一些函数:glShadeModel(GL_FLAT);GL_FLAT则只是以指定的某一点的单一色绘制其他所有点glPushMatrix();//进栈gluLookAt(0.0,0.0,5,0.0,0.0,0.0,0.0,1.0,0.0);//观察角度glRotatef((GLfloat)year,0.0,1.0,0.0);//旋转,(GLfloat)year角度设置,0.0,1.0,0.0坐标设置glTranslatef(2.0,0.0,0.0);//平移,后面代表坐标,沿着x正
3、方向平移glPopMatrix();//出栈glutSwapBuffers();//实现双缓冲glViewport(0,0,(GLsizei)w,(GLsizei)h);//矩形大小的调整运行截图:完整代码:#include"stdafx.h"#include#defineGLUT_DISABLE_ATEXIT_HACK#includestaticfloatyear=0,day=0;voidinit(void){glClearColor(0.0,0.0,0.
4、0,0.0);glShadeModel(GL_FLAT);//设定着色模式,使用图元中某个顶点的颜色来渲染整个图元。}voiddisplay(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.0,1.0,0.0);glLoadIdentity();glPushMatrix();gluLookAt(0.0,0.0,5,0.0,0.0,0.0,0.0,1.0,0.0);//绘制太阳glRotatef((GLfloat)year,0.0,1.0,0.0);gl
5、utWireSphere(0.8,25,25);//绘制地球glRotatef((GLfloat)year,0.0,1.0,0.0);glTranslatef(2.0,0.0,0.0);glRotatef((GLfloat)day,0.0,1.0,0.0);glutWireSphere(0.2,20,20);//绘制月球glRotatef((GLfloat)year,0.0,1.0,0.0);glTranslatef(0.4,0.0,0.0);glRotatef((GLfloat)day,0.0,
6、1.0,0.0);glutWireSphere(0.1,15,15);//glutWireCube(2.0);glPopMatrix();glutSwapBuffers();}voidspinDisplay(void){year=year+0.03;if(year>360.0){year=year-360.0;}day=day+0.06;if(day>360.0){day=day-360.0;}glutPostRedisplay();}voidreshape(intw,inth){glViewpo
7、rt(0,0,(GLsizei)w,(GLsizei)h);//函数作用:用一个视景体截取图像//glFrustum(-1.0,1.0,-1.0,1.0,-1.0,1.0);glMatrixMode(GL_PROJECTION);//mode指定哪一个矩阵堆栈是下一个矩阵操作的目标,参数表示接下来要进行投影相关的操作glLoadIdentity();//设置当前变化矩阵为单位矩阵;单位矩阵就是对角线上都是1,其余元素皆为0的矩阵。然后复位//glOrtho(-3.0,3.0,-3.0,3.0,-3
8、.0,3.0);glFrustum(-1.0,1.0,-1.0,1.0,1.5,20);glMatrixMode(GL_MODELVIEW);//进行视景相关的操作//glLoadIdentity();}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE
9、GLUT_RGB);glutInitWindowSize(600,600);glutInitWindowPosition