1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | You may use this sample code for anything you like, it is not covered by the |
---|
11 | LGPL like the rest of the engine. |
---|
12 | ----------------------------------------------------------------------------- |
---|
13 | */ |
---|
14 | |
---|
15 | #include "Ogre.h" |
---|
16 | #include "ExampleApplication.h" |
---|
17 | #include "ExampleLoadingBar.h" |
---|
18 | |
---|
19 | /** |
---|
20 | \file |
---|
21 | BSP.cpp |
---|
22 | \brief |
---|
23 | Shows the indoor level rendering (Binary Space Partition or BSP based). |
---|
24 | \par |
---|
25 | Also demonstrates loading levels from Quake3Arena and using |
---|
26 | curved bezier surfaces (as demonstrated in the Bezier example) |
---|
27 | in a large level. |
---|
28 | */ |
---|
29 | |
---|
30 | class BspApplication : public ExampleApplication |
---|
31 | { |
---|
32 | public: |
---|
33 | BspApplication() |
---|
34 | { |
---|
35 | |
---|
36 | |
---|
37 | } |
---|
38 | |
---|
39 | protected: |
---|
40 | |
---|
41 | String mQuakePk3; |
---|
42 | String mQuakeLevel; |
---|
43 | ExampleLoadingBar mLoadingBar; |
---|
44 | |
---|
45 | void loadResources(void) |
---|
46 | { |
---|
47 | |
---|
48 | mLoadingBar.start(mWindow, 1, 1, 0.75); |
---|
49 | |
---|
50 | // Turn off rendering of everything except overlays |
---|
51 | mSceneMgr->clearSpecialCaseRenderQueues(); |
---|
52 | mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); |
---|
53 | mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE); |
---|
54 | |
---|
55 | // Set up the world geometry link |
---|
56 | ResourceGroupManager::getSingleton().linkWorldGeometryToResourceGroup( |
---|
57 | ResourceGroupManager::getSingleton().getWorldResourceGroupName(), |
---|
58 | mQuakeLevel, mSceneMgr); |
---|
59 | |
---|
60 | // Initialise the rest of the resource groups, parse scripts etc |
---|
61 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
62 | ResourceGroupManager::getSingleton().loadResourceGroup( |
---|
63 | ResourceGroupManager::getSingleton().getWorldResourceGroupName(), |
---|
64 | false, true); |
---|
65 | |
---|
66 | // Back to full rendering |
---|
67 | mSceneMgr->clearSpecialCaseRenderQueues(); |
---|
68 | mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); |
---|
69 | |
---|
70 | mLoadingBar.finish(); |
---|
71 | |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | // Override resource sources (include Quake3 archives) |
---|
76 | void setupResources(void) |
---|
77 | { |
---|
78 | |
---|
79 | // Load Quake3 locations from a file |
---|
80 | ConfigFile cf; |
---|
81 | |
---|
82 | cf.load("quake3settings.cfg"); |
---|
83 | |
---|
84 | mQuakePk3 = cf.getSetting("Pak0Location"); |
---|
85 | mQuakeLevel = cf.getSetting("Map"); |
---|
86 | |
---|
87 | ExampleApplication::setupResources(); |
---|
88 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
89 | mQuakePk3, "Zip", ResourceGroupManager::getSingleton().getWorldResourceGroupName(), true); |
---|
90 | |
---|
91 | } |
---|
92 | // Override scene manager (use indoor instead of generic) |
---|
93 | void chooseSceneManager(void) |
---|
94 | { |
---|
95 | mSceneMgr = mRoot->createSceneManager("BspSceneManager"); |
---|
96 | } |
---|
97 | // Scene creation |
---|
98 | void createScene(void) |
---|
99 | { |
---|
100 | |
---|
101 | // modify camera for close work |
---|
102 | mCamera->setNearClipDistance(4); |
---|
103 | mCamera->setFarClipDistance(4000); |
---|
104 | |
---|
105 | // Also change position, and set Quake-type orientation |
---|
106 | // Get random player start point |
---|
107 | ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true); |
---|
108 | mCamera->setPosition(vp.position); |
---|
109 | mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up |
---|
110 | mCamera->rotate(vp.orientation); |
---|
111 | // Don't yaw along variable axis, causes leaning |
---|
112 | mCamera->setFixedYawAxis(true, Vector3::UNIT_Z); |
---|
113 | |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | }; |
---|
118 | |
---|
119 | |
---|
120 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
121 | #define WIN32_LEAN_AND_MEAN |
---|
122 | #include "windows.h" |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifdef __cplusplus |
---|
126 | extern "C" { |
---|
127 | #endif |
---|
128 | |
---|
129 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
130 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) |
---|
131 | #else |
---|
132 | int main(int argc, char**argv) |
---|
133 | #endif |
---|
134 | { |
---|
135 | // Create application object |
---|
136 | BspApplication app; |
---|
137 | |
---|
138 | try { |
---|
139 | app.go(); |
---|
140 | } catch( Ogre::Exception& e ) { |
---|
141 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
142 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
143 | #else |
---|
144 | std::cerr << "An exception has occured: " << |
---|
145 | e.getFullDescription().c_str() << std::endl; |
---|
146 | #endif |
---|
147 | } |
---|
148 | |
---|
149 | return 0; |
---|
150 | } |
---|
151 | |
---|
152 | #ifdef __cplusplus |
---|
153 | } |
---|
154 | #endif |
---|