2022年OGRE基础教程基础教程八 .pdf

上传人:Che****ry 文档编号:27255450 上传时间:2022-07-23 格式:PDF 页数:10 大小:102.74KB
返回 下载 相关 举报
2022年OGRE基础教程基础教程八 .pdf_第1页
第1页 / 共10页
2022年OGRE基础教程基础教程八 .pdf_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《2022年OGRE基础教程基础教程八 .pdf》由会员分享,可在线阅读,更多相关《2022年OGRE基础教程基础教程八 .pdf(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、文档: 教程: 基础教程 : 基础教程八出自 Ogre3D开放资源地带跳转到 : 导航, 搜索Basic Tutorial 8: Using Multiple Scene ManagersFile:Forum icon question2.gif Any problems you encounter while working with this tutorial should be posted to the Help Forum. 目录?1 摘要?2 先决条件?3 Setting up the Applicationo3.1 Creating the SceneManagerso3.2 C

2、reating the Cameraso3.3 Creating the Viewportso3.4 Creating the Scene?4 Adding Functionalityo4.1 Dual SceneManagerso4.2 Swapping SceneManagers?5 Conclusiono5.1 Overlayso5.2 One Last Note摘要在这个简短的教程中我们将介绍如何转换多场景管理器。你可以在here 中找到该教程的源码。当你学习本教程的时候,你应该逐步得添加代码到你自己创建的工程中并且观看执行结果。先决条件在你选定的 IDE中创建一个 cpp 文件,然后

3、添加如下代码:#include ExampleApplication.h #define CAMERA_NAME SceneCamera void setupViewport(RenderWindow *win, SceneManager *curr) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - void dualViewport(RenderWindow *win, SceneManager *primary, Scen

4、eManager *secondary) class SMTutorialListener : public ExampleFrameListener, public OIS:KeyListener public: SMTutorialListener(RenderWindow* win, SceneManager *primary, SceneManager *secondary) : ExampleFrameListener(win, primary-getCamera(CAMERA_NAME), true, false), mPrimary(primary), mSecondary(se

5、condary), mDual(false), mContinue(true) mKeyboard-setEventCallback(this); bool frameStarted(const FrameEvent& evt) mKeyboard-capture(); return mContinue; bool keyPressed(const OIS:KeyEvent &arg) switch (arg.key) case OIS:KC_ESCAPE: mContinue = false; break; default: break; return true; bool keyRelea

6、sed(const OIS:KeyEvent &) return true; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 10 页 - - - - - - - - - private: SceneManager *mPrimary, *mSecondary; bool mDual, mContinue; static void swap(SceneManager *&first, SceneManager *&second) SceneManager *tmp = f

7、irst; first = second; second = tmp; ; class SMTutorialApplication : public ExampleApplication public: SMTutorialApplication() SMTutorialApplication() protected: SceneManager *mPrimary, *mSecondary; void chooseSceneManager(void) void createCamera() void createViewports() void createScene(void) void c

8、reateFrameListener(void) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 10 页 - - - - - - - - - mFrameListener = new SMTutorialListener(mWindow, mPrimary, mSecondary); mFrameListener-showDebugOverlay(true); mRoot-addFrameListener(mFrameListener); ; #if OGRE_PLAT

9、FORM = OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include windows.h INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) #else int main(int argc, char *argv) #endif / Create application object SMTutorialApplication app; try app.go(); catch(Exception& e) #if OGRE_PLATFORM = OGR

10、E_PLATFORM_WIN32 MessageBoxA(NULL, e.getFullDescription().c_str(), An exception has occurred!, MB_OK | MB_ICONERROR | MB_TASKMODAL); #else fprintf(stderr, An exception has occurred: %sn, e.getFullDescription().c_str(); #endif return 0; 在你继续之前,请保证你可以成功编译这段代码。但是不要在这里就执行该程序。Setting up the Application C

11、reating the SceneManagers We have previously covered how to select your SceneManager, so I will not go into detail about this function. The only thing we have 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 10 页 - - - - - - - - - changed is that we are creating

12、two of them. Find the chooseSceneManager function and add the following code: mPrimary = mRoot-createSceneManager(ST_GENERIC, primary); mSecondary = mRoot-createSceneManager(ST_GENERIC, secondary); Creating the Cameras The next thing we need to do is create a Camera object for each of the two SceneM

13、anagers. The only difference from previous tutorials is that we are creating two of them, with the same name. Find the createCamera function and add the following code: mPrimary-createCamera(CAMERA_NAME); mSecondary-createCamera(CAMERA_NAME); Creating the Viewports In creating the Viewport for this

14、application, we will be taking a small departure from previous tutorials. When you create a Viewport, you must do two things: setup the Viewport itself and then set the aspect ratio of the camera you are using. To begin with, add the following code to the createViewports function: setupViewport(mWin

15、dow, mPrimary); The actual code for setting up the Viewport resides in this setupViewport function since we will use this code again elsewhere. The first thing we need to do is remove all the previously created Viewports. None have been created yet, but when we call this function again later, we wil

16、l need to make sure that they are all removed before creating new ones. After that we will setup the Viewports just like we have in previous tutorials. Add the following code to the setupViewport function at the top of the file: win-removeAllViewports(); Camera *cam = curr-getCamera(CAMERA_NAME); Vi

17、ewport *vp = win-addViewport(cam); vp-setBackgroundColour(ColourValue(0,0,0); cam-setAspectRatio(Real(vp-getActualWidth() / Real(vp-getActualHeight(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 10 页 - - - - - - - - - Creating the Scene Lastly, we need to cr

18、eate a scene for each SceneManager to contain. We wont make anything complex, just something different so that we know when we have swapped between the two. Find the createScene function and add the following code: / Setup the TerrainSceneManager mPrimary-setSkyBox(true, Examples/SpaceSkyBox); / Set

19、up the Generic SceneManager mSecondary-setSkyDome(true, Examples/CloudySky, 5, 8); Be sure your code compiles before continuing. You may run the program at this point, but it currently has no functionality other than exiting when you press Escape. Adding Functionality Dual SceneManagers The first pi

20、ece of functionality we want to add to the program is to allow the user to render both SceneManagers side by side. When the V key is pressed we will toggle dual Viewport mode. The basic plan for this is simple. To turn off dual Viewport mode, we simply call setupViewport (which we created in the pre

21、vious section) with the primary SceneManager to recreate the Viewport in single mode. When we want to turn it on, we will call a new function called dualViewport. We will keep track of the state of the Viewport with the mDual variable. Add the following code to the switch in the keyPressed function:

22、 case OIS:KC_V: mDual = !mDual; if (mDual) dualViewport(mWindow, mPrimary, mSecondary); else setupViewport(mWindow, mPrimary); break; Now we have swapped the mDual variable and called the appropriate function based on which mode we are in. Now we will define the 名师资料总结 - - -精品资料欢迎下载 - - - - - - - -

23、- - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 10 页 - - - - - - - - - dualViewport function which actually contains the code to show two Viewports at once. In order to display two SceneManagers side by side, we basically do the same thing we have already done in the setupViewport function. The onl

24、y difference is that we will create two Viewports, one for each Camera in our SceneManagers. Add the following code to the dualViewport function: win-removeAllViewports(); Viewport *vp = 0; Camera *cam = primary-getCamera(CAMERA_NAME); vp = win-addViewport(cam, 0, 0, 0, 0.5, 1); vp-setBackgroundColo

25、ur(ColourValue(0,0,0); cam-setAspectRatio(Real(vp-getActualWidth() / Real(vp-getActualHeight(); cam = secondary-getCamera(CAMERA_NAME); vp = win-addViewport(cam, 1, 0.5, 0, 0.5, 1); vp-setBackgroundColour(ColourValue(0,0,0); cam-setAspectRatio(Real(vp-getActualWidth() / Real(vp-getActualHeight(); Al

26、l of this should be familiar except for the extra parameters we have added to the addViewport function call. The first parameter to this function is still the Camera we are using. The second parameter is the z order of the Viewport. A higher z order sits on top of the lower z orders. Note that you c

27、annot have two Viewports with the same z order, even if they do not overlap. The next two parameters are the left and top positions of the Viewport, which must be between 0 and 1. Finally, the last two parameters are the width and the height of the Viewport as a percentage of the screen (again, they

28、 must be between 0 and 1). So in this case, the first Viewport we create will be at the position (0, 0) and will take up half of the screen horizontally and all of the screen vertically. The second Viewport will be at position (0.5, 0) and also take up half the horizontal space and all of the vertic

29、al space. Compile and run the application. By pressing V you can now display two SceneManagers at the same time. Swapping SceneManagers 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 10 页 - - - - - - - - - The last piece of functionality we want to add to our p

30、rogram is to swap the SceneManagers whenever the C key is pressed. To do that, we will first swap the mPrimary and mSecondary variables so that when the setupViewport or dualViewport functions are called, we never need to worry about which SceneManager is in which variable. The primary SceneManager

31、will always be displayed in single mode, and the primary will always be on the left side in dualViewport mode. Add the following code to the switch in the keyPressed function: case OIS:KC_C: swap(mPrimary, mSecondary); After we swap the variables, we need to actually perform the change. All we have

32、to do is call the appropriate Viewport setup function depending on whether we are in dual or single mode: if (mDual) dualViewport(mWindow, mPrimary, mSecondary); else setupViewport(mWindow, mPrimary); break; Thats it! Compile and run the application. We can now swap the SceneManagers with the C key,

33、 and swap single and dual mode with the V key. Conclusion Overlays Im sure you have noticed in your program that when you run in dual Viewport mode, the Ogre debug Overlay shows up on both sides. You may turn off Overlay rendering on a per-Viewport basis. Use the Viewport:setOverlaysEnabled function

34、 to turn them on and off. I have made this relatively simple change to the full source of this tutorial, so if you are confused as to how this is done, see that page for the details. One Last Note Always keep in mind that the Viewport class, while not having a lot of functionality itself, is the key

35、 to all Ogre rendering. It doesnt matter how many SceneManagers you create or how many Cameras in each SceneManager, none of them will be rendered to the window unless you 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 10 页 - - - - - - - - - setup a Viewport fo

36、r each Camera you are showing. Also dont forget to clear out Viewports you are not using before creating more. Template:Ogre Tutorial取自 http:/ 1 个分类: Tutorials查看?页面?讨论?源码?历史个人工具?登录 创建账户导航?首页?社区?当前事件?最近更改?随机页面?帮助搜索进入搜索Google 搜索名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - -

37、- - 第 9 页,共 10 页 - - - - - - - - - your search terms t search form earch工具箱?链入页面?链出更改?特殊页面?可打印版?永久链接Google Adsense ?这页的最后修订在 2009 年 6 月 13日 ( 星期六 ) 14:16 。?本页面已经被浏览 1,056 次。?隐私政策?关于 Ogre3D开放资 源地带?沪 ICP备 09049564号名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 10 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com