


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、设置裁剪窗口几何变换矩阵模50.0,-25.0,0.0,实验五 2D观察、3D观察、实验目的1 理解裁剪窗口和视口的区别2. 掌握 3D 编程概念:主要掌握视点和目标的改变对场景生成的影响二、实验环境硬件要求:PC机,主流配置,最好为独立显卡,显存 512M以上 软件环境:操作系统: Windows XP。语言开发工具: VC6.0。三、实验内容与要求1 在一个窗口中画出三个视口,每个视口画一个六边形,后面两个视 口中六边形是在第一个视口中六边形的基础上分别旋转了 120 度和240 度。/ 样本程序:两个视口中分别画两个三角形#include <glut.h>class wcPt
2、2D public: GLfloat x, y; ;void init (void) glClearColor (1.0, 1.0, 1.0, 0.0);/glMatrixMode (GL_PROJECTION); gluOrtho2D (-100.0, 100.0, -100.0, 100.0);/ 式glMatrixMode (GL_MODELVIEW);void triangle (wcPt2D *verts) GLint k;glBegin (GL_TRIANGLES);for (k = 0; k < 3; k+)glVertex2f (verts k.x, verts k.y)
3、; glEnd ( );void display (void)wcPt2D verts 3 = -50.0,-25.0,50.0 ;glClear (GL_COLOR_BUFFER_BIT); glLoadIdentity(); glColor3f (0.0, 0.0, 1.0); glViewport (0, 0, 300, 300);triangle (verts); /* 旋转三角形 并在右半窗口 */ glColor3f (1.0, 0.0, 0.0);glViewport (300, 0, 300, 300); glRotatef (180.0, 0.0, 0.0, 1.0); tr
4、iangle (verts); glFlush ( );int main (int argc, char * argv)glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition (50, 50); glutInitWindowSize (600, 300);glutCreateWindow ("Split-Screen Example"); init ( );glutDisplayFunc (display); glutMainLoop (
5、 );return 0;2. 附属程序为移动视点、 旋转物体的观察立方体的三维观察程序。 要求改 变立方体为规则八面体或十二面体,多面体经过多种几何变换(平移、 缩放)生成的三维观察场景。附属程序#include <stdlib.h>#include <glut.h>GLfloat vertices3 = -1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0, -1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0, 1.0,1.0,1.0, -1.0,1.0,1.0;GLfloat colors3 = 0.0,0
6、.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0,1.0,0.0,1.0, 1.0,1.0,1.0, 0.0,1.0,1.0;void polygon(int a, int b, int c , int d) glBegin(GL_POL YGON); glColor3fv(colorsd);glVertex3fv(verticesa); glVertex3fv(verticesb); glVertex3fv(verticesc); glVertex3fv(verticesd);glEnd();static GLfloat the
7、ta = 0.0,0.0,0.0;static GLint axis = 2;static GLdouble viewer= 0.0, 0.0, 5.0; void colorcube()polygon(0,3,2,1);polygon(2,3,7,6); polygon(0,4,7,3);polygon(1,2,6,5);polygon(4,5,6,7); polygon(0,1,5,4); void display() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();/更新视点位置 gluLookAt
8、(viewer0,viewer1,viewer2, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glRotatef(theta0, 1.0, 0.0, 0.0);glRotatef(theta1, 0.0, 1.0, 0.0); /* 旋转立方体 */glRotatef(theta2, 0.0, 0.0, 1.0);colorcube();glutSwapBuffers();void mouse(int btn, int state, int x, int y) if(btn=GLUT_LEFT_BUTTON && state = GLUT_DOWN) axi
9、s = 0; if(btn=GLUT_MIDDLE_BUTTON && state = GLUT_DOWN) axis = 1; if(btn=GLUT_RIGHT_BUTTON && state = GLUT_DOWN) axis = 2; thetaaxis += 2.0;if( thetaaxis > 360.0 ) thetaaxis -= 360.0; glutPostRedisplay ();void keys(unsigned char key, int x, int y)/* 用 x, X, y, Y, z, and Z 键 移动视点 */
10、if(key = 'x') viewer0-= 1.0; if(key = 'X') viewer0+= 1.0;if(key = 'y') viewer1-= 1.0; if(key = 'Y') viewer1+= 1.0;if(key = 'z') viewer2-= 1.0; if(key = 'Z') viewer2+= 1.0; glutPostRedisplay ();void myReshape(int w, int h) glViewport(0, 0, w, h); glMatr
11、ixMode(GL_PROJECTION); glLoadIdentity();if(w<=h) glFrustum(-2.0, 2.0, -2.0 * (GLfloat) h/ (GLfloat) w,2.0* (GLfloat) h / (GLfloat) w, 2.0, 20.0);else glFrustum(-2.0, 2.0, -2.0 * (GLfloat) w/ (GLfloat) h,2.0* (GLfloat) w / (GLfloat) h, 2.0, 20.0);/* 或者用 gluPerspective(45.0, w/h, 1.0, 10.0); */ glM
12、atrixMode(GL_MODELVIEW);int main (i nt argc, char *argv) glut In it (&argc, argv);glutl ni tDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutl nitWin dowSize(500, 500); glutCreateWi ndow("colorcube");glutReshapeF un c(myReshape); glutDisplay Fun c(display);glutMouseF un c(mouse);
13、glutKeyboard Fun c(keys);glE nable(GL_DEPTH_TEST); glutMai nLoop(); return 0;3、编程实现自己的project.选作:4. 2D裁剪要求将实验三的画线程序按如下步骤修改:(1)按下键盘"1",可用鼠标在窗口画若干任意条直线。如图 5-1所示。(2)按下键盘"2",可用鼠标在窗口添加一个任意大小的裁剪窗口,窗口画完即完成直线的裁剪,使用编码裁剪算法,如图5-2所示。提示:画矩形结束时,同时把若干条直线的起点坐标和终点作为参数循环调 用裁剪算法,达到线段裁剪的目的。图5-1图5-2四
14、、附录: 编码裁剪法伪代码class wcPt2D public: float x,y; const GLint winLeftBitCode=0x1;const GLint winRightBitCode=0x2;const GLint winBottomBitCode=0x4;const GLint winTopBitCode=0x8;inline GLint inside (Glint code) return GLint (!code);inline GLint reject (GLint code1,GLint code2) return GLint (code1 & cod
15、e2);inline GLint accept (GLint code1, GLint code2) return GLint (!(code1|code2);GLubyte encode(wcPt2D pt,wcPt2D winMin, wcPt2D winMax) GLubyte code=0x00;if (pt.x<winMin.x) code=code|winLeftBitCode;if (pt.x>winMax.x) code=code|winRightBitCode;if (pt.y<winMin.y) code=code|winBottomBitCode;if
16、(pt.y>winMax.y) code=code|winTopBitCode;return (code); void swapPts(wcPt2D *p1, wcPt2D *p2) wcPt2D tmp;tmp=*p1;*p1=*p2;*p2=tmp; void swapCodes(GLubyte *c1,GLubyte *c2) GLubyte tmp;tmp=*c1;*c1=*c2;*c2=tmp; void lineClipCohSuth(wcPt2D winMin, wcPt2D winMax,wcPt2D p1, wcPt2D p2) GLubyte code1,code2;
17、Glint done=false, plotLine=false;GLfloat m;while(!done) code1=encode(p1,winMin,winMax); code2=encode(p2,winMin,winMax);if (accept (code1,code2) done=true;plotLine=true; elseif (reject(code1,code2) done=true;else /* Label the point outside the window as p1*/if ( inside (code1) swapPts(&p1,&p2
18、); swapCodes(&code1,&code2);if (p2.x!=p1.x) m=(p2.y-p1.y)/(p2.x-p1.x);if (code1 & winLeftBitCode) p1.y+=(winMin.x-p1.x)*m; p1.x=winMin.x;elseif (code1 & winRightBitCode) p1.y+=(winMax.x-p1.x)*m; p1.x=winMax.x;elseif (code1 & winBottomBitCode) /*Need to update p1.x for nonvertical lin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版闭口采购合同精简版:范文解读与实施策略
- 二零二五年度出差人员行为规范与培训合同
- 二零二五年度家居用品购销合同范本:现代智能家居产品采购协议
- 二零二五年金融机构视频监控设备采购合同
- 二零二五版工程地质勘察与设计地勘合同示范
- 二零二五年美容院美容原料与产品供应链合同
- 二零二五年度水电安装工程绿色环保技术服务合同
- 二零二五年度艺术装饰地板砖供货合同书
- 2025版一对一家教服务合同范本
- 2025版夫妻自愿离婚房产分割及补偿协议书
- GB/T 1766-2008色漆和清漆涂层老化的评级方法
- 中学生暑期学习计划主题班会PPT模板
- 门诊特殊药品使用申请表
- 2022年7月安徽省萧县教育系统幼儿招聘考试《幼儿保教知识与能力》真题试卷及答案【解析】
- 广西建工80塔吊使用说明书TCT5512
- DB15T 1889-2020 防风栽培技术规程
- (完整word版)高考英语作文练习纸(标准答题卡)
- 混凝土基本性能试验报告
- 海洋时代2探索发现物
- 公路水运工程试验检测机构资质评审培训共34页课件
- 数据结构课件:第3章 栈和队列1栈
评论
0/150
提交评论