毕业论文(设计)基于OpenGL 三维拾取技术研究.doc

上传人:仙人指路1688 文档编号:3974240 上传时间:2023-03-30 格式:DOC 页数:9 大小:185KB
返回 下载 相关 举报
毕业论文(设计)基于OpenGL 三维拾取技术研究.doc_第1页
第1页 / 共9页
毕业论文(设计)基于OpenGL 三维拾取技术研究.doc_第2页
第2页 / 共9页
毕业论文(设计)基于OpenGL 三维拾取技术研究.doc_第3页
第3页 / 共9页
毕业论文(设计)基于OpenGL 三维拾取技术研究.doc_第4页
第4页 / 共9页
毕业论文(设计)基于OpenGL 三维拾取技术研究.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《毕业论文(设计)基于OpenGL 三维拾取技术研究.doc》由会员分享,可在线阅读,更多相关《毕业论文(设计)基于OpenGL 三维拾取技术研究.doc(9页珍藏版)》请在三一办公上搜索。

1、基于OpenGL三维拾取技术研究刘彬 孙永 高明 马克 李晓诗(解放军信息工程大学测绘学院 河南郑州陇海中路66号 450052 )【摘要】在OpenGL环境中,三维场景是通过二维平面表现的,本文通过对这种表现原理的研究,介绍了“射线拾取法”和“包围盒法”两种算法,分析了其实现的原理,并介绍了相关的核心算法。在此基础之上,又提出了一种适用于基于DEM的三维系统的改进算法,把三维空间中的拾取问题转化到了二维平面上,大大简化了拾取的抽象性和复杂性,提高了拾取的效率,更易于理解和实现。【关键字】DEM OpenGL 拾取 光标投影模型1. 引言在三维图形系统中,现实世界中的物体要依次通过模型视点变换

2、,投影变换和视口变换才影射到屏幕窗口上的,而对物体的拾取操作,其实就是在二维屏幕上对三维空间中的物体的拾取技术。2. 射线拾取技术射线拾取算法是判断由视点发出经屏幕光标的射线是否与目标物体相交。其具体的实现实现方法如下所示:(1) 确定射线的位置及方向,可以通过取得射线与远近两个裁减面的交点来确定。(2) 判断射线与拾取目标是否有交点,因为在射线上,任意一点可以表 示为单位向量(L)与模(len)的乘积,所以交点可以表示为:X= P+L*len ;又因为三角形内的任意一点都可以用变量u、v和其三个顶点坐标来确定,其中0u1 0v1、,0u+v1。设三个顶点为T1,T2,T3则:X= T1 +

3、u*( T2T1) + v*( T3 T1) ;由此可以得出PT1 =( L*len) + u*( T2T1) + v*( T3 T1) ,即方程组:(-L.x)*len +( T2.x- T1.x)*u + (T3.x T1.x )*v = P.x T1.x(-L.y)*len +( T2.y- T1.y)*u + (T3.y T1.y )*v = P.y T1.y(-L.z)*len +( T2.z- T1.z)*u + (T3.z T1.z )*v = P.z T1.z这是一个线性方程组,根据克拉姆法则,当满足条件:0v1,0u0, ,0u+v1 和【L,T2T1,T3T1】不为零则射线

4、和三角形相交。具体的编程实现可以参考Micarosoft公司提供的相关算法,由于篇幅有限,在此就不做详细的说明。3. 包围盒技术31 包围盒技术的原理由于在具体的拾取操作中,我们并不需要非常精确的拾取目标物体上的某一点,而是对其选中后进行如平移、旋转、缩放等编辑工作,所以可以牺牲一部分拾取的精确度,而提高其效率。包围盒技术是基于射线拾取技术的一种更加简单高效的拾取方法,它对每个三维场景中需要进行拾取操作的对象设定一个包围域,这个包围域是能够包围对象的最小矩形,该矩形边与坐标轴是对齐的,其左下顶点的x 、y 、z坐标值为实体所有顶点相应坐标值的最小值,其右上顶点的坐标值为实体所有顶点相应坐标值的

5、最大值。由此可以大大降低实现拾取功能的复杂性。32包围盒技术的实现方法如今比较流行的一种包围盒的算法是在视点和鼠标点确定的直线上,找出以近裁减面交点为起点指向远裁减点的向量,求向量各分量和离起点最近的三个包围盒侧面所在平面的交点,如果各分量与平面的交点都在包围盒侧面上或者在包围盒内且在各分量上,则线段wnearwfar和包围盒相交(本文中我们把线段与包围盒相交和线段在包围盒内这两种情况统称为相交)。判断线段与包围盒相对位置的具体步骤如下5:(1) 判断起点wnear是否在包围盒内,如果在盒内,则线段wnearrwfar和包围盒相交,判断结束;如果不在盒内,则记下该包围盒离起点wnear最近的三

6、个侧面,这三个侧面必定共点且相互垂直;(2) 过起点wnear向各侧面做垂线,得到三个垂足,连接点wnear和各垂得到三个向量A1 、A2 、A3,并求A1 、A2 、A3和向量wnearrwfar各相应分量的比值ti=Aiwnearrwfar (i=1,2,3)。如果wnearrwfar的某个分量为零,则比值取一1。取t1、t2、t3中的最大值为tmax,如果tmax1,则wnearrwfar和包围盒不相交,判断结束;4. 基于DEM的三维拾取方法基于DEM的三维图形系统中,地面模型是在某一参考平面上构建均匀网格,并在的各顶点坐标中加入高度坐标Z得到的,它与参考平面具有固定的位置关系。系统中

7、的各种模型的都与DEM数据有着固定的位置关系,即与参考也有着固定的位置关系。在进行三维漫游的过程中,虽然改变了视点和透视窗口,但这种相对位置关系是保持固定的,我们可以利用这种关系把三维空间中的拾取问题转化到参考平面上,通过比较参考平面上光标投影和实体包围盒投影的位置关系判断是否进行拾取,其中参考平面的高度Z可以通过人机交互设置。4.1 拾取原理及实现4.1.1模型及空间实体模型与参考平面的位置关系LWZWXWYOL 图:1-1 世界坐标系下参考平面与DEM模型及实体模型的位置关系如上图1-1所示,世界坐标系下,在DEM构建的地形模型中,平面L为参考平面,K为三维空间中某模型的矩形包围盒,它的每

8、个边分别与坐标轴平行4。 参考平面在构建时亦是与坐标平面平行的,这里设置为平面L(WZ=0);平面L平行于L ,K为K与L的交平面,显然K为矩形,且其四个顶点坐标的XY值与包围盒上对应点的XY值相同。4.1.2 建立光标在参考平面上的投影模型光标通过鼠标控制在二维屏幕坐标系上运动。在实现拾取操作时,传统的算法是通过控制具有二维属性的光标实现对三维物体的拾取,拾取的实现算法比较复杂,结合DEM模型的特点,可以在三维世界坐标系中构建二维光标的投影模型,把对二维光标三维化,如图1-2所示。其实原理如下:l 找到从视点O出发经光标的射线与视景体远近裁减面ABCD和A,B,C,D,的交点P,P,将问题转

9、化到三维世界坐标系中。l 视景体内确定一条以远近裁减面交点为端点的线段P P,l 计算线段和参考平面的交点M,既为光标M在参考平面上的投影点, 可以通过交互实现对参考平面高度Z的控制,也即实现了投影点在Z方向上的自由度。0M,ML图:1-2 透视场景、屏幕及参考面在DEM构建的地形模型上,我们希望光标的投影模型是在地形表面上移动的,从而达到对地表模型(如树木、房屋、车辆)的拾取操作。本文给出一种OpengGL环境中的建立光标投影模的算法,以供参考:(1) 调用OpenGL实用库提供的gluUnProject函数得到从视点发出经光标点M的射线与远近裁减面的交点P(Wx,Wy,Wz)P,(Wx,W

10、y,Wz,)。gluUnProject函数具体使用方法如下所示: gluUnProject(GLdouble)xpos , (GLdouble)ypos , 1.0 , mvmatrix , projmatrix , viewport , &Wx , &Wy , &Wz);xpos 和ypos 是以屏幕左下角为原点的屏幕坐标,1.0代表返回zbuffer为1.0处(远剪切面交点)的世界坐标(为0.1则表示进裁剪面交点),mvmatrix为视矩阵,通过函数glGetDoublev(GL_MODELVIEW_MATRIX , mvmatrix)得到,projmatrix为投影矩阵,通过函数glGe

11、tDoublev(GL_PROJECTION_MATRIX , projmatrix)得到,viewport为视口,通过函数glGetIntegerv(GL_VIEWPORT , viewport)得到,剩下的Wx、Wy、Wz 就是我们要得到的世界坐标系中的交点坐标。(2) 如图2-3所示,根据交点P P,得到向量F(WxWx,WyWy,WzWz,),并计算其与参考平面Wz =0的交点M,的x,y分量,计算公式如下,M,x= Wx+( Wx,Wx)* abs(Wz) /(abs(Wz)+abs(Wz,)M,y= Wy+( Wy,Wy)* abs(Wz) /(abs(Wz)+abs(Wz,)(3

12、) M,z的值可以通过M,x 和M,y在参考平面上计算得出M,点所在的DEM网格,然后通过查询网格四点高程进行插值运算求得。如此,便可以得到光标在在地形表面的投影模型。4.1.3 拾取判断经过上述步骤,对是否拾取目标物体的判断已经变的非常容易了,我们只需在参考平面上判断光标投影模型的(X,Y)值与包围盒在参考平面上投影的位置关系即可。4.2 存在的问题及改进如图2-4所示,上面介绍的方法存在以下两个方面的不足:(1) 光标投影模型的运动速率和鼠标的移动速率不匹配, 当光标在屏幕上移动等距的单位时,其在参考平面上的投影移动的距离是不同的,从而导致了投影模型运动的不均匀性,这对我们用鼠标进行控制增

13、加了难度。视点O1-4 光标与其投影模型运动情况的对比图1-4 光标与其投影模型运动情况的对比(2) 当从视点经光标的射线与参考平面的交角等于零时,就会出现没有交点或有无数交点两种情况,这都不是建立投影模型所预期的,而这种情况因为需要进行场景漫游而不可避免。基于以上考虑,本文总结出一种改进算法,其思想就是把对光标绝对位置在参考平面上的投影转化为光标相对位置在参考平面上的投影。(1) 确定光标投影模型的初始位置,根据人们观察习惯,将光标投影模型的初始位置设置在视口接近底步中央位置,其在世界坐标系下的坐标位置通过调用gluUnProject函数来确定从视点发出经屏幕中央的射线与远近裁减面的交点,并

14、求得其与参考平面的交点,即为光标投影模型的初始位置(2) 在响应鼠标滑动信息的函数OnMouseMove()中设置全局变量(Last_x,Last_y);记录每次函数响应时鼠标的位置信息(Mouse_x,Mouse_y),通过比较前后两次函数响应的鼠标位置关系来确定光标投影模型的移动。使用这种方法,可以避免应用绝对位置投影模型时出现的模型移动不均匀的现象,也不会出现因为由视点和光标确定的射线同参考平面平行而无法建立投影模型的问题了。5. 总结在基于DEM的三维图形系统中,对模型的拾取一般都是为了实现模型的选中,进而达到修改模型的各种属性信息的目的(如纹理,位置,形状),所以对拾取的精度要求并不

15、高。本文所介绍的拾取方式利用基于DEM的三维图形系统的几何特点,牺牲拾取的精度,简化了拾取算法,提高了拾取的效率,对基于DEM的三维图形系统而言,是一种很好的选择。参考文献1. Alan Watt、Fabio Policarpo. 3D Games real-time Rendering and Software Technology 2. Edward Angel. 交互式计算机图形学基于OpengGL的自顶向下的方法. 清华大学出版社3. Dave Shreiner、Mason Woo,Jackie Neider、Tom Dives. OpenGL编程指南(第四版).人民邮电出版社4. 姚

16、继权、李晓豁. 计算机图形学人机交互中三维拾取方法的研究. 工程设计学报,2004(4)5. 王剑、谭建荣、陆国栋. 三维场景中图形对象的拾取方法. 计算机技术应用,2004(7)更多测绘论文请登录测绘网论文频道查询:http:/ Editors note: Judson Jones is a meteorologist, journalist and photographer. He has freelanced with CNN for four years, covering severe weather from tornadoes to typhoons. Follow him on

17、 Twitter: jnjonesjr (CNN) - I will always wonder what it was like to huddle around a shortwave radio and through the crackling static from space hear the faint beeps of the worlds first satellite - Sputnik. I also missed watching Neil Armstrong step foot on the moon and the first space shuttle take

18、off for the stars. Those events were way before my time.As a kid, I was fascinated with what goes on in the sky, and when NASA pulled the plug on the shuttle program I was heartbroken. Yet the privatized space race has renewed my childhood dreams to reach for the stars.As a meteorologist, Ive still

19、seen many important weather and space events, but right now, if you were sitting next to me, youd hear my foot tapping rapidly under my desk. Im anxious for the next one: a space capsule hanging from a crane in the New Mexico desert.Its like the set for a George Lucas movie floating to the edge of s

20、pace.You and I will have the chance to watch a man take a leap into an unimaginable free fall from the edge of space - live.The (lack of) air up there Watch man jump from 96,000 feet Tuesday, I sat at work glued to the live stream of the Red Bull Stratos Mission. I watched the balloons positioned at

21、 different altitudes in the sky to test the winds, knowing that if they would just line up in a vertical straight line we would be go for launch.I feel this mission was created for me because I am also a journalist and a photographer, but above all I live for taking a leap of faith - the feeling of

22、pushing the envelope into uncharted territory.The guy who is going to do this, Felix Baumgartner, must have that same feeling, at a level I will never reach. However, it did not stop me from feeling his pain when a gust of swirling wind kicked up and twisted the partially filled balloon that would t

23、ake him to the upper end of our atmosphere. As soon as the 40-acre balloon, with skin no thicker than a dry cleaning bag, scraped the ground I knew it was over.How claustrophobia almost grounded supersonic skydiverWith each twist, you could see the wrinkles of disappointment on the face of the curre

24、nt record holder and capcom (capsule communications), Col. Joe Kittinger. He hung his head low in mission control as he told Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunday.The weather plays an important role in this mission. Starting at the

25、 ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip

26、 of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause), he can expect a lot of turbulence.The balloon will slowly drift to t

27、he edge of space at 120,000 feet (22.7 miles/36.53 kilometers). Here, Fearless Felix will unclip. He will roll back the door.Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he want

28、s to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110

29、kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow

30、him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will o

31、pen automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).It might not be the moon, but Kittinger free fell from 102,800 feet in 1960 - at the dawn of an infamous space race that captured the hearts of many. Baumgartner will attempt to break that record, a feat that boggles the mind. This is one of those monumental moments I will always remember, because there is no way Id miss this.

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

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号