




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、實驗一一. 實驗名稱Ogre部分仿真實驗二. 實驗過程或?qū)嶒灣绦颍ㄔ黾拥拇a及代碼注解)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.在??吭谟疫叺拿蠲姘逯?,點擊
2、幾何體按鈕 3.選擇標準幾何體 4.在對象類型中選擇對象(如:長方體),在“前”視口中,通過單擊鼠標左鍵,創(chuàng)建出模型 5.在工具欄中單擊“材質(zhì)編輯器”按鈕,通過上步操作,可開啟“材質(zhì)編輯器”對話框 6.在“材質(zhì)編輯器”對話框中,點擊漫反射旁方形按鈕,進入到“材質(zhì)/貼圖瀏覽器” 7.在“材質(zhì)/貼圖瀏覽器”中選擇位圖,鼠標左鍵雙擊位圖 8.彈出選擇位圖圖像文件對話框,從本地電腦中選擇一張圖片 9.選擇好圖片,在材質(zhì)編輯器對話框中,點擊將材質(zhì)指令給選定對象 10.點擊菜單欄上的oFusion按鈕,在彈出的菜單欄中選擇Export Scene 11選擇文件夾并輸入文件名qiu,點擊保存,在彈出的對話框
3、中勾選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文件附帶的材質(zhì)文件qiu.material放到OgreSDK的scripts(C:OgreSDKmediamaterialsscripts)中;4.將導出mesn文件
4、時同時導出的圖片放到OgreSDK的textures(C:OgreSDKmediamaterialstextures)中。1.4 mesh文件導入到場景中1.4.1 mesh文件導入到場景中步驟: 1.啟動vs2008 2.在“文件”菜單中選擇“打開”,然后單擊“項目/解決方案” 3.找到項目MFCOgre1,選擇MFCOgre1.sln,點擊打開按鈕 4.打開MFCOgre1View.h,創(chuàng)建節(jié)點變量,SceneNode *node1(MFCOgre1View.h 中的第55行),創(chuàng)建實體變量 Entity* ent1(MFCOgre1View.h 中的第57行); 5.打開MFCOgre1
5、View.cpp, 在MFCOgre1View.cpp的構造函數(shù)中對創(chuàng)建的節(jié)點和實體對象初始化node1(NULL)、 ent1(NULL)(在MFCOgre1View.cpp 的第37行和第39行) 6.獲取根節(jié)點的子節(jié)點,并將其賦值給節(jié)點node1( MFCOgre1View.cpp 的第225行) 7.給創(chuàng)建的實體對象ent1賦值( MFCOgre1View.cpp 的第224行) 8.設置節(jié)點的位置( MFCOgre1View.cpp 的第226行)9.將實體附在節(jié)點上( MFCOgre1View.cpp 的第227行)1.5生成項目 使用“生成項目”功能可以將程序的源代碼文件編譯為可
6、執(zhí)行的二進制文件,方法十分簡單:在“生成”菜單中選擇“生成解決方案”。 在項目生成過程中,“輸出”窗口會實時顯示生成的進度和結果。如果源代碼中不包含語法錯誤,會在最后提示生成成功,如下圖所示:1.6執(zhí)行項目 在MFCOgre1中選擇“調(diào)試”菜單中的“開始執(zhí)行(不調(diào)試)”,可以執(zhí)行剛剛生成的程序,運行出實驗要求的結果。2. 鍵盤輸入控制攝像機的移動2.1添加按鍵消息響應 1.在菜單欄中選擇視圖 2.點擊視圖,在彈出的菜單窗口中,選擇類視圖 3.在類視圖中,選擇類MFCOgre1View 4.再次選擇菜單欄中的視圖,在菜單的菜單窗口中,選擇其他窗口 5.在其他窗口中,選擇屬性窗口 6.在屬性窗口中
7、,點擊消息按鈕7.找到WM_KEYDOWN,添加OnKeyDown()消息響應函數(shù)2.2在OnKeyDown()消息響應函數(shù)中,添加按鍵控制1.找到MFCOgre1View.cpp的onKeyDown()( MFCOgre1View.cpp 的第296行)2.創(chuàng)建一個3維變量Vector3 trans = Vector3:ZERO;2.使用switch語句,判斷用戶按下的按鍵3.如果用戶按下的是A鍵,將變量trans的x坐標減10,然后將攝像機移動到當前的trans坐標處(注:按鍵消息獲取的都是大寫字母),則攝像機向左移動,代碼如下:case'A': trans.x -=10;
8、 m_pCamera->moveRelative(trans); break;4. 如果用戶按下的是D鍵,將變量trans的x坐標加10,然后將攝像機移動到當前的trans坐標處(注:按鍵消息獲取的都是大寫字母),則攝像機向左移動caseD': trans.x +=10; m_pCamera->moveRelative(trans); break;2.3生成項目 使用“生成項目”功能可以將程序的源代碼文件編譯為可執(zhí)行的二進制文件,方法十分簡單:在“生成”菜單中選擇“生成解決方案”。 在項目生成過程中,“輸出”窗口會實時顯示生成的進度和結果。如果源代碼中不包含語法錯誤,會在最
9、后提示生成成功,如下圖所示:2.4執(zhí)行項目 在MFCOgre1中選擇“調(diào)試”菜單中的“開始執(zhí)行(不調(diào)試)”,可以執(zhí)行剛剛生成的程序,運行出實驗要求的結果。3. 添加動畫3.1添加動畫 1.在MFCOgreView1.h中創(chuàng)建void CreateAnimation(Ogre:String MyAnimation);( MFCOgreView1 中第77行) 2.創(chuàng)建一個全局變量AnimationState *as( MFCOgreView1.cpp 中第17行) 3.實現(xiàn)void CreateAnimation(Ogre:String MyAnimation);(MFCOgre1View.cp
10、p中第319行) 4.判斷動畫是否存在,如果動畫存在,刪除已有的動畫 5.使用sceneManager來創(chuàng)建一個animation,同時指定動畫的名字和幀的長度 6. 設置該段動畫的關鍵幀間幀的插值方式,這里使用線性 7. 使用animation創(chuàng)建為每個要驅(qū)動的node創(chuàng)建一個track, 比如這里我們只想讓一個結點(node,比如它上面掛著攝像機)運動,就只為他創(chuàng)建一個track就行了,第一個參數(shù)是這個track的編號 8. 對于每個track創(chuàng)建它的每個關鍵幀 9. 設置該幀的時間點 10. 設置該幀處這個結點的位置和其他幾何狀態(tài) 11.設置動畫運動狀態(tài) 12.在項目解決方案資源管理器中
11、,找到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()函數(shù)(在MyFrameListener.cpp第14
12、行),代碼如下:bool MyFrameListener:frameStarted(const FrameEvent &evt) if(NULL != as) as->addTime(evt.timeSinceLastFrame); return true; 18.在MFCOgre1View.cpp的構造函數(shù)中創(chuàng)建關聯(lián)監(jiān)聽類對象(m_pRoot->addFrameListener(new MyFrameListener();)(在MFCOgre1View.cpp第50行) 19. 找到MFCOgre1View.cpp的onKeyDown()( MFCOgre1View.cp
13、p 的第296行)使用switch語句,判斷用戶按下的按鍵,代碼如下:case'M': CreateAnimation("MyAnimation");break;三. 實驗結果(包括必要的截圖)根據(jù)前面的實驗步驟,最終得到下面的截圖:1. 將桌子這個實體模型導入到Ogre中,如下圖所示:該截圖說明mesh文件添加到場景中成功。2. 將場景分別繞X軸、Y軸和Z軸旋轉(zhuǎn),如下圖所示(1) 繞X軸旋轉(zhuǎn):(2)繞Y軸旋轉(zhuǎn):(2) 繞Z軸旋轉(zhuǎn):同樣可以通過添加如下代碼控制攝像機的移動:case'A': trans.x -=10; m_pCamera-&g
14、t;moveRelative(trans); break;因此,在執(zhí)行程序的時候,按鍵“A”可以實現(xiàn)場景的向左移動;caseD': trans.x +=10; m_pCamera->moveRelative(trans); break;因此執(zhí)行程序的時候,按鍵“D”可以實現(xiàn)場景的向右移動。四. 實驗體會1、 思考題解答:(1) 如何控制攝像機的上下移動、前后移動?解:控制攝像機的上下移動可以通過控制攝像機的Z坐標,例如要是想要向上移動,則可以使tran.z+=10,向下移動的話則可以使tran.z-=10;控制攝像機的前后移動則需要改變攝像機的Y坐標,例如要是想要向前移動,則可以
15、使tran.y+=10,向后移動的話則可以使tran.y-=10。(2)如何控制攝像機的旋轉(zhuǎn)?(函數(shù) void pitch(const Radian& angle); /繞X軸旋轉(zhuǎn) 函數(shù) void yaw(const Radian& angle); /繞Y軸旋轉(zhuǎn) 函數(shù) void roll(const Radian& angle); /繞Z軸旋轉(zhuǎn))解:控制攝像機的旋轉(zhuǎn)已經(jīng)在程序中實現(xiàn),如上面的截圖所示,通過函數(shù) void pitch(const Radian& angle),使得攝像機繞軸X旋轉(zhuǎn),具體每次旋轉(zhuǎn)的角度可以在函數(shù)的參數(shù)中進行設置;通過函數(shù) void y
16、aw(const Radian& angle),使得攝像機繞軸Y旋轉(zhuǎn);通過函數(shù) void roll(const Radian& angle),使得攝像機繞軸Z旋轉(zhuǎn)。(3) 按下M鍵,實體球可以沿著直線運動,通過鍵盤控制實體球,實體球是否可以沿著曲線運動?解:通過鍵盤控制實體球,實體球是可以沿著曲線運動的,只需要在相應的控制按鍵的開關語句中調(diào)用一個能夠讓實體球沿著曲線運動的函數(shù),該實體球的運動曲線可以設置為BS曲線等等。2、 實驗感想 通過本次實驗,我初步認識和了解了Ogre這款軟件,該軟件能夠創(chuàng)建三維場景,所以被用于游戲等等場合中。本次實驗,我自己按照實驗指導書一步步的從用3D
17、max創(chuàng)建三維實體模型,然后生成mesh文件,將mesh文件導入到Ogre場景中,給實體模型添加材質(zhì),并且通過添加相應的代碼使得實體球能夠運動起來,添加相應的代碼使得場景左右移動、上下移動、前后移動和繞軸旋轉(zhuǎn)等等,這些所有的內(nèi)容雖然做的不是很漂亮,但是讓自己嘗試了在Ogre中如何完整的創(chuàng)建簡單的三維模型。 實驗二 一. 實驗名稱PathFinder疏散仿真實驗二. 實驗過程或?qū)嶒灣绦颍ㄔ黾拥拇a及代碼注解)1、Create Geometry1. On the View menu, click Units and select EN to display measurements using t
18、he 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 conve
19、rted 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 e
20、nter 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
21、.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,
22、 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 th
23、e 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 coordin
24、ate 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
25、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
26、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, separa
27、ted 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, se
28、parated 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 a
29、djacent 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 occupa
30、nts: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 o
31、ccupants三實驗結果(包括必要的截圖)1、實驗最終結果截圖顯示:2、仿真截圖顯示:3、 人群疏散仿真模擬截圖顯示:四實驗體會本次實驗主要就是熟悉Pathfinder軟件的使用,在本次實驗的過程中,我覺得這款軟件的功能還是很強大的,也很有趣,我們可以在這個平臺上來進行人群疏散的仿真。該平臺能夠很好的將模型疏散和人群疏散顯示出來。但是我覺得這款軟件有一個缺點,那就是樓梯的邊緣檢測做的不夠細致,直接導致人群疏散的時候下樓的人們的腳可以被看見。 實驗三 一實驗名稱基于OGRE的Boids算法實驗二實驗過程或?qū)嶒灣绦颍ㄔ黾拥拇a及代碼注解)3.1基于OGRE的Boids算法實現(xiàn)1.拷貝MyBoid
32、s.h,MyBoids.cpp到E:MFCOgre1MFCOgre1(對應的項目位置)2.添加MyBoids.h、MyBoids.cpp到工程中3.在MFCOgre1View.h中引入頭文件MyBoids.h(#include "MyBoids.h")4.在MFCOgre1View.cpp的OnInitialUpdate()函數(shù)(OnInitialUpdate()在MFCOgre1View的第115行)中,添加函數(shù)AllInit();5.打開MFCOgre1View.h,在類中創(chuàng)建節(jié)點變量SceneNode* node,實體變量Entity* ent,節(jié)點變量數(shù)組Scene
33、Node* node4BoidsNum,實體變量數(shù)組Entity* ent4BoidsNum,字符串數(shù)組Ogre:String NameBoidsNum。6.打開MFCOgre1View.cpp,在MFCOgre1View.cpp的構造函數(shù)中對創(chuàng)建的節(jié)點和實體對象以及字符串數(shù)組初始化7.在MFCOgre1View.cpp的CreateEntity函數(shù)中創(chuàng)建實體,并將實體綁定到節(jié)點上8.在MFCOgre1View.cpp的OnTimer消息響應函數(shù)中添加CubMotion(), 設置節(jié)點的node的位置;添加BoidsMotion(),設置節(jié)點數(shù)組node4BoidsNum的位置3.2生成項目使
34、用“生成項目”功能可以將程序的源代碼文件編譯為可執(zhí)行的二進制文件,方法十分簡單:在“生成”菜單中選擇“生成解決方案”。 在項目生成過程中,“輸出”窗口會實時顯示生成的進度和結果。如果源代碼中不包含語法錯誤,會在最后提示生成成功,如下圖所示:3.3執(zhí)行項目在MFCOgre1中選擇“調(diào)試”菜單中的“開始執(zhí)行(不調(diào)試)”,可以執(zhí)行剛剛生成的程序,運行出實驗要求的結果。3.4添加代碼及注解1、添加代碼 (1)for(int i=0;i<BoidsNum;i+)/給每個Boids模型初始化名稱 if(i=0) Namei="a" else Namei=Namei-1+"
35、;a" for(int i=0;i<BoidsNum;i+)/為每個實體初始化 ent4i=NULL; for(int i=0;i<BoidsNum;i+)/為每個節(jié)點初始化 node4i=NULL; (2)void CMFCOgre1View:OnInitialUpdate()/為場景進行初始化 AllInit();CFormView:OnInitialUpdate();GetParentFrame()->RecalcLayout();ResizeParentToFit();(3)void CMFCOgre1View:CreateEntity(void)/將每個實
36、體附著在結點上,并且給結點賦值 /ent1 = m_pSceneManager->createEntity("Sphere","qiu.mesh");/獲取實體對象,第一個參數(shù)是實體的名字,第二個參數(shù)是要導入的mesh文件 /node1 = m_pSceneManager->getRootSceneNode()->createChildSceneNode();/創(chuàng)建結點 /node1->translate(Vector3(-20,0,30);/設置實體的位置 /node1->attachObject(ent1);/將實體附在
37、節(jié)點上 /ent1->setMaterialName("Examples/Chrome1");/設置實體的材質(zhì) /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()->createChildSceneNode("node"); node->setScale(0.02f,0.02f,0.02f); node->setPosition
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 在線叉車考試試題及答案
- 會計機考試題及答案
- aopa考試題及答案
- c1科一考試題及答案
- 醫(yī)美培訓試題及答案
- 法學通論考試題及答案
- 專職隊員招聘考試試題及答案
- 2025年分子科學與工程專業(yè)畢業(yè)設計開題報告
- 2025年材料科學與工程專業(yè)畢業(yè)設計開題報告
- 2025年浙江社工招聘考試題庫
- 2023年新高考全國Ⅱ卷英語試題真題及答案詳解(含作文范文)
- 2023年中國郵輪游船游艇行業(yè)發(fā)展報告
- 中國鐵路高速綜合檢測列車
- JGJT193-2009 混凝土耐久性檢驗評定標準
- 農(nóng)藥田間藥效試驗技術課件
- 新版FMEA表單模板(帶AP明細)(OK)
- 新高三開學第一課主題班會(共28張PPT)
- 藍契斯特法則-營銷類
- 優(yōu)研發(fā)技術專用OKR績效考核表模版
- GA 1205-2014滅火毯
- 社區(qū)工作者經(jīng)典備考題庫(必背300題)
評論
0/150
提交評論