虚拟现实与仿真技术-实验报告.doc_第1页
虚拟现实与仿真技术-实验报告.doc_第2页
虚拟现实与仿真技术-实验报告.doc_第3页
虚拟现实与仿真技术-实验报告.doc_第4页
虚拟现实与仿真技术-实验报告.doc_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验一一. 实验名称Ogre部分仿真实验二. 实验过程或实验程序(增加的代码及代码注解)1.从3Dmax8中导出mesh并添加mesh到场景1.1启动3Dmax1.在安装有3Dmax8的计算机上,可以使用两种不同的方法来启动3Dmax8: (1)在桌面上双击“3Dmax8”图标 (2)点击“开始”菜单,在“程序”中的选择“3Dmax8”2. 观察3Dmax8主窗口的布局。3Dmax8主要由若干元素组成:菜单栏、工具栏、以及停靠在右边的命令面板和底部的各种工具窗口。1.2使用3Dmax8建模并导出mesh1.2.1导出mesh的步骤如下: 1.启动3Dmax8 2.在停靠在右边的命令面板中,点击几何体按钮 3.选择标准几何体 4.在对象类型中选择对象(如:长方体),在“前”视口中,通过单击鼠标左键,创建出模型 5.在工具栏中单击“材质编辑器”按钮,通过上步操作,可开启“材质编辑器”对话框 6.在“材质编辑器”对话框中,点击漫反射旁方形按钮,进入到“材质/贴图浏览器” 7.在“材质/贴图浏览器”中选择位图,鼠标左键双击位图 8.弹出选择位图图像文件对话框,从本地电脑中选择一张图片 9.选择好图片,在材质编辑器对话框中,点击将材质指令给选定对象 10.点击菜单栏上的oFusion按钮,在弹出的菜单栏中选择Export Scene 11选择文件夹并输入文件名qiu,点击保存,在弹出的对话框中勾选Copy Textures,点击Export按钮,此时mesh文件已成功导出1.3导出的mesh文件放入到指定位置 1.找到mesh文件,把mesh文件放到当前电脑的OgreSDK的models中,以我的电脑为例,OgerSDK放在C盘中; 2.打开C盘,找到OgreSDK,打开OgreSDK,找到media,打开media文件夹,找到models,打开models文件夹,将mesh文件复制到此文件夹中; 3.将导出mesh文件附带的材质文件qiu.material放到OgreSDK的scripts(C:OgreSDKmediamaterialsscripts)中;4.将导出mesn文件时同时导出的图片放到OgreSDK的textures(C:OgreSDKmediamaterialstextures)中。1.4 mesh文件导入到场景中1.4.1 mesh文件导入到场景中步骤: 1.启动vs2008 2.在“文件”菜单中选择“打开”,然后单击“项目/解决方案” 3.找到项目MFCOgre1,选择MFCOgre1.sln,点击打开按钮 4.打开MFCOgre1View.h,创建节点变量,SceneNode *node1(MFCOgre1View.h 中的第55行),创建实体变量 Entity* ent1(MFCOgre1View.h 中的第57行); 5.打开MFCOgre1View.cpp, 在MFCOgre1View.cpp的构造函数中对创建的节点和实体对象初始化node1(NULL)、 ent1(NULL)(在MFCOgre1View.cpp 的第37行和第39行) 6.获取根节点的子节点,并将其赋值给节点node1( MFCOgre1View.cpp 的第225行) 7.给创建的实体对象ent1赋值( MFCOgre1View.cpp 的第224行) 8.设置节点的位置( MFCOgre1View.cpp 的第226行)9.将实体附在节点上( MFCOgre1View.cpp 的第227行)1.5生成项目 使用“生成项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:1.6执行项目 在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果。2. 键盘输入控制摄像机的移动2.1添加按键消息响应 1.在菜单栏中选择视图 2.点击视图,在弹出的菜单窗口中,选择类视图 3.在类视图中,选择类MFCOgre1View 4.再次选择菜单栏中的视图,在菜单的菜单窗口中,选择其他窗口 5.在其他窗口中,选择属性窗口 6.在属性窗口中,点击消息按钮7.找到WM_KEYDOWN,添加OnKeyDown()消息响应函数2.2在OnKeyDown()消息响应函数中,添加按键控制1.找到MFCOgre1View.cpp的onKeyDown()( MFCOgre1View.cpp 的第296行)2.创建一个3维变量Vector3 trans = Vector3:ZERO;2.使用switch语句,判断用户按下的按键3.如果用户按下的是A键,将变量trans的x坐标减10,然后将摄像机移动到当前的trans坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动,代码如下:caseA: trans.x -=10; m_pCamera-moveRelative(trans); break;4. 如果用户按下的是D键,将变量trans的x坐标加10,然后将摄像机移动到当前的trans坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动caseD: trans.x +=10; m_pCamera-moveRelative(trans); break;2.3生成项目 使用“生成项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:2.4执行项目 在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果。3. 添加动画3.1添加动画 1.在MFCOgreView1.h中创建void CreateAnimation(Ogre:String MyAnimation);( MFCOgreView1 中第77行) 2.创建一个全局变量AnimationState *as( MFCOgreView1.cpp 中第17行) 3.实现void CreateAnimation(Ogre:String MyAnimation);(MFCOgre1View.cpp中第319行) 4.判断动画是否存在,如果动画存在,删除已有的动画 5.使用sceneManager来创建一个animation,同时指定动画的名字和帧的长度 6. 设置该段动画的关键帧间帧的插值方式,这里使用线性 7. 使用animation创建为每个要驱动的node创建一个track, 比如这里我们只想让一个结点(node,比如它上面挂着摄像机)运动,就只为他创建一个track就行了,第一个参数是这个track的编号 8. 对于每个track创建它的每个关键帧 9. 设置该帧的时间点 10. 设置该帧处这个结点的位置和其他几何状态 11.设置动画运动状态 12.在项目解决方案资源管理器中,找到MFCOgre1 13.右击MFCOgre1,在弹出的界面中,选择添加类 14.选择MFC类,点击添加,在类名中输入MyFrameListener 15.在MyFrameListener.h中类MyFrameListener继承FrameListener 16.在MyFrameListener.h中添加virtual bool frameStarted(const FrameEvent &evt);( 在MyFrameListener.h的第12行 ) 17.在MyFrameListener.cpp中重写frameStart()函数(在MyFrameListener.cpp第14行),代码如下:bool MyFrameListener:frameStarted(const FrameEvent &evt) if(NULL != as) as-addTime(evt.timeSinceLastFrame); return true; 18.在MFCOgre1View.cpp的构造函数中创建关联监听类对象(m_pRoot-addFrameListener(new MyFrameListener();)(在MFCOgre1View.cpp第50行) 19. 找到MFCOgre1View.cpp的onKeyDown()( MFCOgre1View.cpp 的第296行)使用switch语句,判断用户按下的按键,代码如下:caseM: CreateAnimation(MyAnimation);break;三. 实验结果(包括必要的截图)根据前面的实验步骤,最终得到下面的截图:1. 将桌子这个实体模型导入到Ogre中,如下图所示:该截图说明mesh文件添加到场景中成功。2. 将场景分别绕X轴、Y轴和Z轴旋转,如下图所示(1) 绕X轴旋转:(2)绕Y轴旋转:(2) 绕Z轴旋转:同样可以通过添加如下代码控制摄像机的移动:caseA: trans.x -=10; m_pCamera-moveRelative(trans); break;因此,在执行程序的时候,按键“A”可以实现场景的向左移动;caseD: trans.x +=10; m_pCamera-moveRelative(trans); break;因此执行程序的时候,按键“D”可以实现场景的向右移动。四. 实验体会1、 思考题解答:(1) 如何控制摄像机的上下移动、前后移动?解:控制摄像机的上下移动可以通过控制摄像机的Z坐标,例如要是想要向上移动,则可以使tran.z+=10,向下移动的话则可以使tran.z-=10;控制摄像机的前后移动则需要改变摄像机的Y坐标,例如要是想要向前移动,则可以使tran.y+=10,向后移动的话则可以使tran.y-=10。(2)如何控制摄像机的旋转?(函数 void pitch(const Radian& angle); /绕X轴旋转 函数 void yaw(const Radian& angle); /绕Y轴旋转 函数 void roll(const Radian& angle); /绕Z轴旋转)解:控制摄像机的旋转已经在程序中实现,如上面的截图所示,通过函数 void pitch(const Radian& angle),使得摄像机绕轴X旋转,具体每次旋转的角度可以在函数的参数中进行设置;通过函数 void yaw(const Radian& angle),使得摄像机绕轴Y旋转;通过函数 void roll(const Radian& angle),使得摄像机绕轴Z旋转。(3) 按下M键,实体球可以沿着直线运动,通过键盘控制实体球,实体球是否可以沿着曲线运动?解:通过键盘控制实体球,实体球是可以沿着曲线运动的,只需要在相应的控制按键的开关语句中调用一个能够让实体球沿着曲线运动的函数,该实体球的运动曲线可以设置为BS曲线等等。2、 实验感想 通过本次实验,我初步认识和了解了Ogre这款软件,该软件能够创建三维场景,所以被用于游戏等等场合中。本次实验,我自己按照实验指导书一步步的从用3Dmax创建三维实体模型,然后生成mesh文件,将mesh文件导入到Ogre场景中,给实体模型添加材质,并且通过添加相应的代码使得实体球能够运动起来,添加相应的代码使得场景左右移动、上下移动、前后移动和绕轴旋转等等,这些所有的内容虽然做的不是很漂亮,但是让自己尝试了在Ogre中如何完整的创建简单的三维模型。 实验二 一. 实验名称PathFinder疏散仿真实验二. 实验过程或实验程序(增加的代码及代码注解)1、Create Geometry1. On the View menu, click Units and select EN to display measurements using the English system.To specify snap grid spacing:1. On the View menu, click Edit Snap Grid.2. In the Specify snap grid spacing menu, type 2.0. By default, length units will be in feet, however, you can type a value followed by a unit (e.g.: in or m) and the length will be converted to feet.3. Click OK.To define the default floor height:1. In the Floor Height box(on the above Toolbar), type 12.0.To create the room:1. In the View toolbar, click Top View ( ).2. In the Tools toolbar, click Add a Rectangular Room ( ).3. In the Z Plane box, type 0.0.4. In the coordinate boxes enter the following values: X1: 0.0, Y1: 0.0, X2: 60.0, Y2: 40.0. 5. Click Create.Replicate the room to create three floors.1. In the View toolbar, click the Selection Tool icon . 2. Select the room.3. In the Tools toolbar, click the Move Objects icon .4. Select Copy Mode. 5. In the Copies box type 2.6. In the Move Z box, type 12.0.7. Click Copy/Move.8. Click the Zoom Fit icon to rescale the view.Your model should now look like Figure 1. Figure 1: The floors in the modelTo define the landings:1. Create the first landing at Z=6.0 ft. In the View toolbar, click Top View ( ). In the Tools toolbar, click Add a Rectangular Room ( ). In the Z Plane box, type 6.0. In the coordinate boxes enter the following values: X1: -13.5, Y1: 16.0, X2: -9.5, Y2: 24.0. Click Create.2. Replicate the landing. In the View toolbar, click the Selection Tool icon . Select the landing. In the Tools toolbar, click the Move Objects icon . Select Copy Mode. In the Copies box type 1.In the Move Z box, type 12.0. Click Copy/Move.3. Repeat for the landing on the opposite side. In the View toolbar, click Top View ( ). In the Tools toolbar, click Add a Rectangular Room ( ). In the Z Plane box, type 6.0. In the coordinate boxes enter the following values: X1: 69.5, Y1: 16.0, X2: 73.5, Y2: 24.0. Click Create.4. Replicate the landing. In the View toolbar, click the Selection Tool icon . Select the landing. In the Tools toolbar, click the Move Objects icon . Select Copy Mode. In the Copies box type 1. In the Move Z box, type 12.0. Click Copy/Move.Your model should now look like Figure 2. Figure 2:The floors and landings in the modelTo add the first stairway on the left side of the building:1. In the Tools toolbar, click Create Stairs between two edges ( ).2. In the Stair Width box, type 44.0 in. In the Door 1 Width box and the Door 2 Width box, type 32.0 in. 3. Click on the lower landing and position the stair towards the front side of the landing. Click on the lower floor to create the stairs from the landing to the lower floor, Figure 3.4. Use the Move Objects tool to make 1 copies of the stair, separated by 12 ft in the Z direction.5. Add the stairs that go up from the landing. Click on the lower landing and position the stair opposite the first stairs. Click on the second floor to create the stairs from the landing to the second floor.6. Use the Move Objects tool to make a copy of the stair, separated by 12 ft in the Z direction.7. Repeat on the other side of the model. This time, position the first stairs on the back side of the landing. Figure 3 : First stairs on left side of buildingAdd the exit doors:1. Select the door tool ( ) and in the Max Width box, type 120.0 in.2. Place a door adjacent to both stairs on the lowest floor. These doors are wide enough that exit from the first floor does not affect the egress time. 3. Name the doors Right Exit and Left Exit to aid in later plotting of the exit rates through each door, Figure 4. Figure 4: The left ExitAdd OccupantsTo add occupants:1. Select the first (lowest) floor. On the Model menu click Add Occupants. For Occupant Count select By Number and type 100. Click OK.2. Repeat for each floor, selecting the corresponding profile for each floor. When finished, your model should look like Figure 5Figure 5: Pathfinder model with occupants三实验结果(包括必要的截图)1、实验最终结果截图显示:2、仿真截图显示:3、 人群疏散仿真模拟截图显示:四实验体会本次实验主要就是熟悉Pathfinder软件的使用,在本次实验的过程中,我觉得这款软件的功能还是很强大的,也很有趣,我们可以在这个平台上来进行人群疏散的仿真。该平台能够很好的将模型疏散和人群疏散显示出来。但是我觉得这款软件有一个缺点,那就是楼梯的边缘检测做的不够细致,直接导致人群疏散的时候下楼的人们的脚可以被看见。 实验三 一实验名称基于OGRE的Boids算法实验二实验过程或实验程序(增加的代码及代码注解)3.1基于OGRE的Boids算法实现1.拷贝MyBoids.h,MyBoids.cpp到E:MFCOgre1MFCOgre1(对应的项目位置)2.添加MyBoids.h、MyBoids.cpp到工程中3.在MFCOgre1View.h中引入头文件MyBoids.h(#include MyBoids.h)4.在MFCOgre1View.cpp的OnInitialUpdate()函数(OnInitialUpdate()在MFCOgre1View的第115行)中,添加函数AllInit();5.打开MFCOgre1View.h,在类中创建节点变量SceneNode* node,实体变量Entity* ent,节点变量数组SceneNode* node4BoidsNum,实体变量数组Entity* ent4BoidsNum,字符串数组Ogre:String NameBoidsNum。6.打开MFCOgre1View.cpp,在MFCOgre1View.cpp的构造函数中对创建的节点和实体对象以及字符串数组初始化7.在MFCOgre1View.cpp的CreateEntity函数中创建实体,并将实体绑定到节点上8.在MFCOgre1View.cpp的OnTimer消息响应函数中添加CubMotion(), 设置节点的node的位置;添加BoidsMotion(),设置节点数组node4BoidsNum的位置3.2生成项目使用“生成项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:3.3执行项目在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果。3.4添加代码及注解1、添加代码 (1)for(int i=0;iBoidsNum;i+)/给每个Boids模型初始化名称 if(i=0) Namei=a; else Namei=Namei-1+a; for(int i=0;iBoidsNum;i+)/为每个实体初始化 ent4i=NULL; for(int i=0;iRecalcLayout();ResizeParentToFit();(3)void CMFCOgre1View:CreateEntity(void)/将每个实体附着在结点上,并且给结点赋值 /ent1 = m_pSceneManager-createEntity(Sphere,qiu.mesh);/获取实体对象,第一个参数是实体的名字,第二个参数是要导入的mesh文件 /node1 = m_pSceneManager-getRootSceneNode()-createChildSceneNode();/创建结点 /node1-translate(Vector3(-20,0,30);/设置实体的位置 /node1-attachObject(ent1);/将实体附在节点上 /ent1-setMaterialName(Examples/Chrome1);/设置实体的材质 /ent2 = m_pSceneManager-createEntity(tree,tree02.mesh); /node2 = m_pSceneManager-getRootSceneNode()-createChildSceneNode(); /node2-translate(Vector3(0,500,0);/设置实体的位置 /node2-attachObject(ent2);/将实体附在场景上 ent =m_pSceneManager-createEntity(cube,ninja.mesh); node = m_pSceneManager-getRootSceneNode()-creat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论