当前位置:文档之家› 虚拟现实与仿真实验报告

虚拟现实与仿真实验报告

合肥工业大学计算机与信息学院实验报告课程:虚拟现实与仿真技术专业班级:计算机科学与技术11-2班学号:姓名:谢云飞实验一一.实验名称从3Dmax8中导出mesh并添加mesh到场景。

二.实验过程或实验程序(增加的代码及代码注解)启动3Dmax1.在安装有3Dmax8的计算机上,可以使用两种不同的方法来启动3Dmax8:(1)在桌面上双击“3Dmax8”图标(2)点击“开始”菜单,在“程序”中的选择“3Dmax8”2.观察3Dmax8主窗口的布局。

3Dmax8主要由若干元素组成:菜单栏、工具栏、以及停靠在右边的命令面板和底部的各种工具窗口使用3Dmax8建模并导出mesh导出mesh的步骤如下:1.启动3Dmax82.在停靠在右边的命令面板中,点击几何体按钮3.选择标准几何体4.在对象类型中选择对象(如:长方体),在“前”视口中,通过单击鼠标左键,创建出模型5.在工具栏中单击“材质编辑器”按钮,通过上步操作,可开启“材质编辑器”对话框6.在“材质编辑器”对话框中,点击漫反射旁方形按钮,进入到“材质/贴图浏览器”7.在“材质/贴图浏览器”中选择位图,鼠标左键双击位图8.弹出选择位图图像文件对话框,从本地电脑中选择一张图片9.选择好图片,在材质编辑器对话框中,点击将材质指令给选定对象10.点击菜单栏上的oFusion按钮,在弹出的菜单栏中选择Export Scene11.选择文件夹并输入文件名qiu,点击保存,在弹出的对话框中勾选Copy Textures,点击Export按钮,此时mesh文件已成功导出导出的mesh文件放入到指定位置1.找到mesh文件,把mesh文件放到当前电脑的OgreSDK的models中,以我的电脑为例,OgerSDK放在C盘中2.打开C盘,找到OgreSDK,打开OgreSDK,找到media,打开media文件夹,找到models,打开models文件夹,将mesh文件复制到此文件夹中3.将导出mesh文件附带的材质文件放到OgreSDK的scripts (C:\OgreSDK\media\materials\scripts)中4.将导出mesn文件时同时导出的图片放到OgreSDK的textures (C:\OgreSDK\media\materials\textures)中mesh文件导入到场景中mesh文件导入到场景中步骤:1.启动vs20082.在“文件”菜单中选择“打开”,然后单击“项目/解决方案”3.找到项目MFCOgre1,选择,点击打开按钮4.打开,创建节点变量,SceneNode *node1(中的第55行),创建实体变量 Entity* ent1(中的第57行);5.打开,在的构造函数中对创建的节点和实体对象初始化node1(NULL)、 ent1(NULL)(在的第37行和第39行)6.获取根节点的子节点,并将其赋值给节点node1(的第225行)7.给创建的实体对象ent1赋值(的第224行)8.设置节点的位置(的第226行)9.将实体附在节点上(的第227行)void CMFCOgre1View::CreateEntity(void){ent1 = m_pSceneManager->createEntity("Sphere","");菜单栏中选择视图2.点击视图,在弹出的菜单窗口中,选择类视图3.在类视图中,选择类MFCOgre1View4.再次选择菜单栏中的视图,在菜单的菜单窗口中,选择其他窗口5.在其他窗口中,选择属性窗口6.在属性窗口中,点击消息按钮7.找到WM_KEYDOWN,添加OnKeyDown()消息响应函数在OnKeyDown()消息响应函数中,添加按键控制1.找到的onKeyDown()(的第296行)2.创建一个3维变量Vector3 trans = Vector3::ZERO;3.使用switch语句,判断用户按下的按键4.如果用户按下的是A键,将变量trans的x坐标减10,然后将摄像机移动到当前的trans 坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动,代码如下:case'A':-=10;m_pCamera->moveRelative(trans);break;5. 如果用户按下的是D键,将变量trans的x坐标加10,然后将摄像机移动到当前的trans 坐标处(注:按键消息获取的都是大写字母),则摄像机向左移动case‘D':+=10;m_pCamera->moveRelative(trans);break;6.实现其它移动和旋转的代码如下:case'G':-=10;m_pCamera->moveRelative(trans);中创建voidCreateAnimation(Ogre::String MyAnimation);( MFCOgreView1 中第77行)2.创建一个全局变量AnimationState *as(中第17行)3.实现void CreateAnimation(Ogre::String MyAnimation);(中第319行)4.判断动画是否存在,如果动画存在,删除已有的动画5.使用sceneManager来创建一个animation,同时指定动画的名字和帧的长度6. 设置该段动画的关键帧间帧的插值方式,这里使用线性7. 使用animation创建为每个要驱动的node创建一个track,比如这里我们只想让一个结点(node,比如它上面挂着摄像机)运动,就只为他创建一个track就行了,第一个参数是这个track的编号8. 对于每个track创建它的每个关键帧9. 设置该帧的时间点10. 设置该帧处这个结点的位置和其他几何状态11.设置动画运动状态12.在项目解决方案资源管理器中,找到MFCOgre113.右击MFCOgre1,在弹出的界面中,选择添加类14.选择MFC类,点击添加,在类名中输入MyFrameListener15.在中类MyFrameListener继承FrameListener16.在中添加virtual bool frameStarted(const FrameEvent &evt);(在的第12行)17.在中重写frameStart()函数(在第14行),代码如下:bool MyFrameListener::frameStarted(const FrameEvent &evt){if(NULL != as){as->addTime;}return true;}18.在的构造函数中创建关联监听类对象(m_pRoot->addFrameListener(new MyFrameListener());)(在第50行)19. 找到的onKeyDown()(的第296行)使用switch语句,判断用户按下的按键,代码如下:case'M':CreateAnimation("MyAnimation");break;生成项目使用“生成项目”功能可以将程序的源代码文件编译为可执行的二进制文件,方法十分简单:在“生成”菜单中选择“生成解决方案”。

在项目生成过程中,“输出”窗口会实时显示生成的进度和结果。

如果源代码中不包含语法错误,会在最后提示生成成功,如下图所示:如果源代码中存在语法错误,“输出”窗口会输出相应的错误信息(包括错误所在文件的路径,错误在文件中的位置,以及错误原因),并在最后提示生成失败。

此时在“输出”窗口中双击错误信息所在的行,OS Lab会使用源代码编辑器打开错误所在的文件,并自动定位到错误对应的代码行。

可以在源代码文件中故意输入一些错误的代码(例如删除一个代码行结尾的分号),然后再次生成项目,然后在“输出”窗口中双击错误信息来定位存在错误的代码行,将代码修改正确后再生成项目。

执行项目在MFCOgre1中选择“调试”菜单中的“开始执行(不调试)”,可以执行刚刚生成的程序,运行出实验要求的结果三.实验结果(包括必要的截图)注释:由于实现了曲线运动,所以相应代码如下,每个球的曲线运动轨迹相同,故只实现了下面的两个球体。

/*判断动画是否存在,如果动画存在,删除已有的动画*/if (m_pSceneManager->hasAnimation(MyAnimation)){m_pSceneManager->destroyAnimation(MyAnimation);}To specify snap grid spacing:1. On the View menu, click Edit Snap Grid....2. In the Specify snap grid spacing menu, type . By default, length units will be in feet, however, you can type a value followed by a unit .: "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 .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 .4. In the coordinate boxes enter the following values: X1: , Y1: , X2: , Y2: .5. Click Create.Replicate the room to create three floors.1. In the View toolbar, click the Selection Too l 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 .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= ft. In the View toolbar, click Top View( ). In the Tools toolbar, click Add aRectangular Room ( ). In the Z Plane box,type . In the coordinate boxes enter the following values: X1: , Y1: , X2: , Y2: . Click Create.2. Replicate the landing. In the View toolbar, click the Selection Tool icon. Select the landing. In the Toolstoolbar, click the Move Objects icon . Select Copy Mode. In the Copies box type the Move Z box, type . 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 aRectangular Room( ). In the Z Plane box,type . In the coordinate boxes enter the following values: X1: , Y1: , X2: , Y2: . Click Create.4. Replicate the landing. In the View toolbar, click the Selection Tool icon. Select the landing. In the Toolstoolbar, click the Move Objects icon . Select Copy Mode. In the Copies box type 1. In the Move Z box, type . 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 in. In the Door 1 Width box and the Door 2 Width box, type 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 theMax Width box, type in.2. Place a door adjacent to both stairs on the lowest floor. These doors are wide enough that exitfrom 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 througheach 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 5.Figure 5: Pathfinder model with occupantsRun SimulationTo run the simulation:1. Save your document to a new folder. Use the name .1. On the toolbar, click Run Simulation( ). By default, the problem will besolved 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 seconds.View ResultsWhen 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 animation.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三.实验结果(包括必要的截图)建模效果如下:模拟人群疏散:通过建模以及仿真模拟,可以看出结果能够满足实验要求。

相关主题