虚拟现实与仿真实验报告_第1页
虚拟现实与仿真实验报告_第2页
虚拟现实与仿真实验报告_第3页
虚拟现实与仿真实验报告_第4页
虚拟现实与仿真实验报告_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

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

文档简介

1、合肥工业大学计算机与信息学院实验报告课 程:虚拟现实与仿真技术专业班级:计算机科学与技术11-2班 学 号:20112497姓 名: 谢云飞实验一 一. 实验名称从3Dmax8中导出mesh并添加mesh到场景。二. 实验过程或实验程序(增加的代码及代码注解)2.1启动3Dmax1.在安装有3Dmax8的计算机上,可以使用两种不同的方法来启动3Dmax8: (1)在桌面上双击“3Dmax8”图标 (2)点击“开始”菜单,在“程序”中的选择“3Dmax8”2.观察3Dmax8主窗口的布局。3Dmax8主要由若干元素组成:菜单栏、工具栏、以及停靠在右边的命令面板和底部的各种工具窗口2.2 使用3D

2、max8建模并导出mesh2.2.1导出mesh的步骤如下:1.启动3Dmax82.在停靠在右边的命令面板中,点击几何体按钮3.选择标准几何体4.在对象类型中选择对象(如:长方体),在“前”视口中,通过单击鼠标左键,创建出模型5.在工具栏中单击“材质编辑器”按钮,通过上步操作,可开启“材质编辑器”对话框6.在“材质编辑器”对话框中,点击漫反射旁方形按钮,进入到“材质/贴图浏览器”7.在“材质/贴图浏览器”中选择位图,鼠标左键双击位图8.弹出选择位图图像文件对话框,从本地电脑中选择一张图片9.选择好图片,在材质编辑器对话框中,点击将材质指令给选定对象10.点击菜单栏上的oFusion按钮,在弹出

3、的菜单栏中选择Export Scene11选择文件夹并输入文件名qiu,点击保存,在弹出的对话框中勾选Copy Textures,点击Export按钮,此时mesh文件已成功导出2.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

4、:OgreSDKmediamaterialsscripts)中4.将导出mesn文件时同时导出的图片放到OgreSDK的textures(C:OgreSDKmediamaterialstextures)中2.4 mesh文件导入到场景中2.4.1 mesh文件导入到场景中步骤:1.启动vs20082.在“文件”菜单中选择“打开”,然后单击“项目/解决方案”3.找到项目MFCOgre1,选择MFCOgre1.sln,点击打开按钮4.打开MFCOgre1View.h,创建节点变量,SceneNode *node1(MFCOgre1View.h 中的第55行),创建实体变量 Entity* ent1

5、(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行)

6、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(E

7、xamples/Chrome1);/设置实体的材质2.5生成项目使用“生成项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:如果源代码中存在语法错误,“输出”窗口会输出相应的错误信息(包括错误所在文件的路径,错误在文件中的位置,以及错误原因),并在最后提示生成失败。此时在“输出”窗口中双击错误信息所在的行,OS Lab会使用源代码编辑器打开错误所在的文件,并自动定位到错误对应的代码行。可以在源代码文件中故意输入一些

8、错误的代码(例如删除一个代码行结尾的分号),然后再次生成项目,然后在“输出”窗口中双击错误信息来定位存在错误的代码行,将代码修改正确后再生成项目。2.6执行项目在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果。三. 实验结果(包括必要的截图)3dmax中创建实体球模型:添加mesh到场景中后:注释:由于增加了九个球体,所以相应代码有所改变。具体如下(两例,其它七个相同): ent3 = m_pSceneManager-createEntity(Sphere1,qiu.mesh);/获取实体对象,第一个参数是实体的名字,第二个参数是要导

9、入的mesh文件 node3 = m_pSceneManager-getRootSceneNode()-createChildSceneNode();/创建结点 node3-translate(Vector3(-20,20,30);/设置实体的位置 node3-attachObject(ent3);/将实体附在节点上 ent3-setMaterialName(Examples/Chrome1);/设置实体的材质 ent4= m_pSceneManager-createEntity(Sphere4,qiu.mesh);/获取实体对象,第一个参数是实体的名字,第二个参数是要导入的mesh文件 no

10、de4 = m_pSceneManager-getRootSceneNode()-createChildSceneNode();/创建结点 node4-translate(Vector3(-20,40,30);/设置实体的位置 node4-attachObject(ent4);/将实体附在节点上 ent4-setMaterialName(Examples/Chrome1);/设置实体的材质四. 实验体会 通过此次试验,不但复习了3dmax模型的创建过程,我还知道了对模型的导出,以及添加到ogre模型库中,并能通过看代码,自己添加实体模型到场景中,更改模型的材质。另外,我对orge也有了一定的了

11、解,知道了在VS里面配置库目录,能够把场景转到orge里面展示。这只是实验的开始,我希望随着后面的学习能够对其有进一步的掌握。实验二 一. 实验名称 键盘输入控制摄像机的移动。二. 实验过程或实验程序(增加的代码及代码注解)2.1添加按键消息响应1.在菜单栏中选择视图2.点击视图,在弹出的菜单窗口中,选择类视图3.在类视图中,选择类MFCOgre1View4.再次选择菜单栏中的视图,在菜单的菜单窗口中,选择其他窗口5.在其他窗口中,选择属性窗口6.在属性窗口中,点击消息按钮7.找到WM_KEYDOWN,添加OnKeyDown()消息响应函数2.2在OnKeyDown()消息响应函数中,添加按键

12、控制1.找到MFCOgre1View.cpp的onKeyDown()( MFCOgre1View.cpp 的第296行)2.创建一个3维变量Vector3 trans = Vector3:ZERO;3.使用switch语句,判断用户按下的按键4.如果用户按下的是A键,将变量trans的x坐标减10,然后将摄像机移动到当前的trans坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动,代码如下:caseA: trans.x -=10; m_pCamera-moveRelative(trans); break;5. 如果用户按下的是D键,将变量trans的x坐标加10,然后将摄像机移动到当

13、前的trans坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动caseD: trans.x +=10; m_pCamera-moveRelative(trans); break;6.实现其它移动和旋转的代码如下:caseG: trans.y -=10; m_pCamera-moveRelative(trans);/向下移动 break; caseT: trans.y += 10; m_pCamera-moveRelative(trans);/向上移动 caseW: trans.z -=10; m_pCamera-moveRelative(trans);/向前移动 break; cas

14、eS: trans.z += 10; m_pCamera-moveRelative(trans);/向后移动 break; caseM: CreateAnimation(MyAnimation);/模型曲线移动 break; caseQ: *pdegree=0.1; m_pCamera-yaw(*pdegree);/Y旋转 break; caseE: *pdegree=0.1; m_pCamera-pitch(*pdegree);/X旋转 break; caseR: *pdegree=0.1; m_pCamera-roll(*pdegree);/Z旋转 break;2.3生成项目使用“生成项目

15、”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:如果源代码中存在语法错误,“输出”窗口会输出相应的错误信息(包括错误所在文件的路径,错误在文件中的位置,以及错误原因),并在最后提示生成失败。此时在“输出”窗口中双击错误信息所在的行,OS Lab会使用源代码编辑器打开错误所在的文件,并自动定位到错误对应的代码行。可以在源代码文件中故意输入一些错误的代码(例如删除一个代码行结尾的分号),然后再次生成项目,然后在“输出”窗

16、口中双击错误信息来定位存在错误的代码行,将代码修改正确后再生成项目。2.4执行项目在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果三. 实验结果(包括必要的截图)通过控制相应的按键。可以按要求实现摄像机的视角的转变。四. 实验体会 本次实验主要是通过修改代码改变摄像机的视角,使之可以左右移动。首先需要对其坐标的情况掌握,这是基础。然后才能修改代码。由于左右移动实现起来比较简单,后面又做了上下前后一起围绕三个坐标的旋转移动。通过此次实验我对ogre以及其下的编程有了更进一步的把握,顿感收获颇丰。 实验三 一实验名称按下M键,控制实体球沿

17、着一条直线运动。二实验过程或实验程序(增加的代码及代码注解)2.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来创建一个ani

18、mation,同时指定动画的名字和帧的长度6. 设置该段动画的关键帧间帧的插值方式,这里使用线性7. 使用animation创建为每个要驱动的node创建一个track, 比如这里我们只想让一个结点(node,比如它上面挂着摄像机)运动,就只为他创建一个track就行了,第一个参数是这个track的编号8. 对于每个track创建它的每个关键帧9. 设置该帧的时间点10. 设置该帧处这个结点的位置和其他几何状态11.设置动画运动状态12.在项目解决方案资源管理器中,找到MFCOgre113.右击MFCOgre1,在弹出的界面中,选择添加类14.选择MFC类,点击添加,在类名中输入MyFrame

19、Listener15.在MyFrameListener.h中类MyFrameListener继承FrameListener16.在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 !=

20、 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;2.2生成项目使用“生成

21、项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。 在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:如果源代码中存在语法错误,“输出”窗口会输出相应的错误信息(包括错误所在文件的路径,错误在文件中的位置,以及错误原因),并在最后提示生成失败。此时在“输出”窗口中双击错误信息所在的行,OS Lab会使用源代码编辑器打开错误所在的文件,并自动定位到错误对应的代码行。可以在源代码文件中故意输入一些错误的代码(例如删除一个代码行结尾的分号),然后再次生成项目,然后在“输出

22、”窗口中双击错误信息来定位存在错误的代码行,将代码修改正确后再生成项目。2.3执行项目在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果3 实验结果(包括必要的截图)注释:由于实现了曲线运动,所以相应代码如下,每个球的曲线运动轨迹相同,故只实现了下面的两个球体。 /*判断动画是否存在,如果动画存在,删除已有的动画*/ if (m_pSceneManager-hasAnimation(MyAnimation) m_pSceneManager-destroyAnimation(MyAnimation); /使用sceneManager来创建

23、一个animation,同时指定动画的名字和帧的长度 Animation *pAni = m_pSceneManager-createAnimation(MyAnimation,Real(5); /设置该段动画的关键帧间帧的插值方式,这里使用线性 pAni-setInterpolationMode(Animation:IM_SPLINE); /*使用animation创建为每个要驱动的node创建一个track, 比如这里我们只想让一个结点(node,比如它上面挂着摄像机)运动, 就只为他创建一个track就行了,第一个参数是这个track的编号*/ NodeAnimationTrack *p

24、TrankOne = pAni-createNodeTrack(0,node1); NodeAnimationTrack *pTrankOne1 = pAni-createNodeTrack(1,node3); /对于每个track创建它的每个关键帧 TransformKeyFrame *pKeyFrame = NULL; TransformKeyFrame *pKeyFrame1 = NULL; /设置该帧的时间点 pKeyFrame = pTrankOne-createNodeKeyFrame(0); pKeyFrame1 = pTrankOne1-createNodeKeyFrame(0

25、); /设置该帧处这个结点的位置和其他几何状态 pKeyFrame-setTranslate(Vector3(-20,0,30);/起点坐标 pKeyFrame = pTrankOne-createNodeKeyFrame(1); pKeyFrame-setTranslate(Vector3(20,10,30); pKeyFrame = pTrankOne-createNodeKeyFrame(2); pKeyFrame-setTranslate(Vector3(20,20,-30); pKeyFrame = pTrankOne-createNodeKeyFrame(3); pKeyFrame

26、-setTranslate(Vector3(-20,30,30); pKeyFrame = pTrankOne-createNodeKeyFrame(4); pKeyFrame-setTranslate(Vector3(-20,0,30);/终点坐标 pKeyFrame1-setTranslate(Vector3(-20,20,30);/起点坐标 pKeyFrame1 = pTrankOne1-createNodeKeyFrame(1); pKeyFrame1-setTranslate(Vector3(20,30,30); pKeyFrame1 = pTrankOne1-createNodeK

27、eyFrame(2); pKeyFrame1-setTranslate(Vector3(20,40,-30); pKeyFrame1 = pTrankOne1-createNodeKeyFrame(3); pKeyFrame1-setTranslate(Vector3(-20,50,30); pKeyFrame1 = pTrankOne1-createNodeKeyFrame(4); pKeyFrame1-setTranslate(Vector3(-20,20,30);/终点坐标4 实验体会 本次实验主要是控制模型的移动路线,由于要求直线运动比较简单,所以后面改成了曲线运动。要知道的是,在og

28、re里面没有可以直接调用的曲线函数,所以只能通过折线运动来模拟曲线运动。如上代码所示,起点和终点之间的点越多,运动越接近曲线。实验四1 实验名称 Pathfinder软件实验2 实验过程或实验程序(增加的代码及代码注解)l 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

29、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

30、.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 flo

31、ors.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 no

32、w 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

33、: -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. Repea

34、t 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

35、 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 model

36、To 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 fron

37、t 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

38、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 t

39、he 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

40、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

41、type 100. Click OK.2. Repeat for each floor, selecting the corresponding pro each floor. When finished, your model should look like Figure 5.Figure 5: Pathfinder model with occupantsRun SimulationTo run the simulation: 1. Save your document to a new folder. Use the name test.pth.1. On the toolbar, c

42、lick Run Simulation ( ). By default, the problem will be solved using the Steering behavior mode.2. A summary report is provided in the analysis dialog. It provides FIRST IN and LAST OUT times for each room and door. The total time required for evacuation is approximately 89.8 seconds.View ResultsWh

43、en the simulation is finished, the 3D Pathfinder results window will display. To view results:1. Click the Play button. This will display the occupants as cylinders with their direction indicated by a triangle.2. At any time click the Pause or Stop button. You can drag the time line to control the a

44、nimation.3. To view occupants as people, click the Stop button, on the Agents menu, click Show as People, then click the Play button, Figure 6.Figure 6: Display of results三实验结果(包括必要的截图)建模效果如下:模拟人群疏散:通过建模以及仿真模拟,可以看出结果能够满足实验要求。4 实验体会 此次实验主要是通过构建楼层模型,添加必要的楼梯以及门和人群模型来模拟人群疏散。由于有者一定的3dmax场景建模的基础,所以做起来很顺手。

45、实验结果能够达到预定目标。我也考虑了其实现机制,并看了其代码,虽然不太懂,但还是有一定收获,至少知道了一些定义和参数的含义,希望后面能够有机会进一步深入了解。实验五一实验名称基于OGRE的Boids算法实验二实验过程或实验程序(增加的代码及代码注解)1.1 在OGRE中实现Boids算法,将OpenGL平台的MyBoids算法移植到OGRE中进行实现;1.2 在OGRE中添加以下交互功能,通过按键或者菜单均可:l 增加/减少Boids的速度;l 启动/停止Cube的移动,观察Boids的跟随效果;case Z:bCubeMotion = !bCubeMotion;break;case X: S

46、tepSpeed += 0.01;break;case C: StepSpeed -= 0.01;if(StepSpeed 0) StepSpeed=0;break;case : StepSpeed=0;bCubeMotion = !bCubeMotion;break;l 改变4个规则的权值(0-1之间),观察Boids的飞行效果;#define Separation 1.0#define Aligment 1.0#define Cohesion 1.0#define Follow 1.02.1基于OGRE的Boids算法实现1.拷贝MyBoids.h,MyBoids.cpp到E:MFCOgr

47、e1MFCOgre1(对应的项目位置)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的构造函数中对创建的节点和实体对象以及字符串数组初始化/

温馨提示

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

最新文档

评论

0/150

提交评论