1 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
2 | #define WIN32_LEAN_AND_MEAN
|
---|
3 | #include "windows.h"
|
---|
4 | #endif
|
---|
5 |
|
---|
6 | #include "TestKdTree.h"
|
---|
7 | #include "WinCmdLineParser.h"
|
---|
8 |
|
---|
9 | #ifdef __cplusplus
|
---|
10 | extern "C" {
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
14 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
15 | #else
|
---|
16 | int main(int argc, char *argv[])
|
---|
17 | #endif
|
---|
18 | {
|
---|
19 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
20 | // parse windows-style command line
|
---|
21 |
|
---|
22 | WinCmdLineParser cmdparser(strCmdLine);
|
---|
23 | KdTreeAppListener::Options options;
|
---|
24 |
|
---|
25 | try
|
---|
26 | {
|
---|
27 | cmdparser
|
---|
28 | .addOpt("i","infile", ARGUMENT_REQUIRED)
|
---|
29 | .addOpt("o","outfile", ARGUMENT_REQUIRED)
|
---|
30 | .addOpt("l","logfile", ARGUMENT_REQUIRED)
|
---|
31 | .addOpt("d","demomode", ARGUMENT_NONE)
|
---|
32 | .addOpt("","buildmode", ARGUMENT_REQUIRED)
|
---|
33 | .addOpt("","maxdepth", ARGUMENT_REQUIRED)
|
---|
34 | .addOpt("","kt", ARGUMENT_REQUIRED)
|
---|
35 | .addOpt("","ki", ARGUMENT_REQUIRED)
|
---|
36 | .addOpt("r","rendermode", ARGUMENT_REQUIRED)
|
---|
37 | .addOpt("s","scenemgr", ARGUMENT_REQUIRED)
|
---|
38 | .addOpt("","comment", ARGUMENT_REQUIRED)
|
---|
39 | .addOpt("e","enhancevis", ARGUMENT_NONE);
|
---|
40 |
|
---|
41 |
|
---|
42 | cmdparser.getOpt("i", options.mDemoInfileName);
|
---|
43 | cmdparser.getOpt("o", options.mDemoOutfileName);
|
---|
44 | cmdparser.getOpt("l", options.mDemoLogfileName);
|
---|
45 | cmdparser.getOpt("comment", options.mComment);
|
---|
46 | options.mDemoMode = cmdparser.getOpt("d");
|
---|
47 | options.mEnhancedVisibility = cmdparser.getOpt("e");
|
---|
48 |
|
---|
49 | std::string tmp;
|
---|
50 | std::stringstream s;
|
---|
51 |
|
---|
52 | if (cmdparser.getOpt("buildmode", tmp))
|
---|
53 | {
|
---|
54 | int bm = KdTree::KDBM_NOTSET;
|
---|
55 | for (int i = 0; i < KdTree::KDBM_SIZE; i ++)
|
---|
56 | {
|
---|
57 | if (tmp == KdTreeAppListener::BUILDMETHOD[i])
|
---|
58 | bm = i;
|
---|
59 | }
|
---|
60 | if (bm != KdTree::KDBM_NOTSET)
|
---|
61 | {
|
---|
62 | options.mBuildMethod = bm;
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | MessageBox(NULL, ("Invalid argument for option --buildmode: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
67 | return -1;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (cmdparser.getOpt("maxdepth", tmp))
|
---|
72 | {
|
---|
73 | s << tmp;
|
---|
74 | s >> options.mMaxDepth;
|
---|
75 | s.clear();
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (cmdparser.getOpt("kt", tmp))
|
---|
79 | {
|
---|
80 | s << tmp;
|
---|
81 | s >> options.mKT;
|
---|
82 | s.clear();
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (cmdparser.getOpt("ki", tmp))
|
---|
86 | {
|
---|
87 | s << tmp;
|
---|
88 | s >> options.mKI;
|
---|
89 | s.clear();
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (cmdparser.getOpt("r",tmp))
|
---|
93 | {
|
---|
94 | int rm = KdTree::KDRM_NOTSET;
|
---|
95 | for (int i = 0; i < KdTree::KDRM_SIZE; i ++)
|
---|
96 | {
|
---|
97 | if (tmp == KdTreeAppListener::RENDERMETHOD[i])
|
---|
98 | rm = i;
|
---|
99 | }
|
---|
100 | if (rm != KdTree::KDRM_NOTSET)
|
---|
101 | {
|
---|
102 | options.mRenderMethod = rm;
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | MessageBox(NULL, ("Invalid argument for option --rendermode: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
107 | return -1;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (cmdparser.getOpt("s",tmp))
|
---|
112 | {
|
---|
113 | int sm = KdTreeAppListener::SM_NOTSET;
|
---|
114 | for (int i = 0; i < KdTreeAppListener::SM_SIZE; i ++)
|
---|
115 | {
|
---|
116 | if (tmp == KdTreeAppListener::SCENEMANAGER[i])
|
---|
117 | sm = i;
|
---|
118 | }
|
---|
119 | if (sm != KdTreeAppListener::SM_NOTSET)
|
---|
120 | {
|
---|
121 | options.mSceneManager = sm;
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | MessageBox(NULL, ("Invalid argument for option --scenemgr: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
126 | return -1;
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | }
|
---|
131 | catch (std::string s)
|
---|
132 | {
|
---|
133 | MessageBox(NULL, s.c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
134 | return -1;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // Create application object
|
---|
138 | KdTreeApp app(options);
|
---|
139 | #else
|
---|
140 | // TODO: unix-style getopt
|
---|
141 | // Create application object
|
---|
142 | KdTreeApp app;
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | SET_TERM_HANDLER;
|
---|
146 |
|
---|
147 | // init random number generator
|
---|
148 | // srand(time(0));
|
---|
149 |
|
---|
150 | try {
|
---|
151 | app.go();
|
---|
152 | } catch( Ogre::Exception& e ) {
|
---|
153 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
154 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
155 | #else
|
---|
156 | std::cerr << "An exception has occured: " <<
|
---|
157 | e.getFullDescription().c_str() << std::endl;
|
---|
158 | #endif
|
---|
159 | }
|
---|
160 |
|
---|
161 | return 0;
|
---|
162 | }
|
---|
163 |
|
---|
164 | #ifdef __cplusplus
|
---|
165 | }
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #define ENT_GRID 0x01
|
---|
169 | #define ENT_RND 0x02
|
---|
170 | #define ENT_SPC 0x04
|
---|
171 | #define ENT_MOV 0x08
|
---|
172 | #define ENT_PLN 0x10
|
---|
173 |
|
---|
174 | void KdTreeApp::setupResources(void)
|
---|
175 | {
|
---|
176 | String tmp;
|
---|
177 | ConfigFile cfDeath;
|
---|
178 | char *errptr;
|
---|
179 | int base = 10;
|
---|
180 |
|
---|
181 | cfDeath.load("testKdTree.cfg");
|
---|
182 |
|
---|
183 | mSceneFiles = cfDeath.getSetting("scene");
|
---|
184 |
|
---|
185 | tmp = cfDeath.getSetting("shadows");
|
---|
186 | StringUtil::toLowerCase(tmp);
|
---|
187 | if (tmp == "on")
|
---|
188 | mShadowsEnabled = true;
|
---|
189 | else
|
---|
190 | mShadowsEnabled = false;
|
---|
191 |
|
---|
192 |
|
---|
193 | tmp = cfDeath.getSetting("planedim");
|
---|
194 | mPlaneDim = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
195 |
|
---|
196 | tmp = cfDeath.getSetting("randomcount");
|
---|
197 | mRandomCount = static_cast<int>(strtol(tmp.c_str(), &errptr, base));
|
---|
198 |
|
---|
199 | tmp = cfDeath.getSetting("selectentities");
|
---|
200 | mSelectEntities = static_cast<int>(strtol(tmp.c_str(), &errptr, base));
|
---|
201 |
|
---|
202 | tmp = cfDeath.getSetting("count");
|
---|
203 | mModelCount = static_cast<int>(strtol(tmp.c_str(), &errptr, base));
|
---|
204 |
|
---|
205 | tmp = cfDeath.getSetting("spacing");
|
---|
206 | mModelSpacing = static_cast<int>(strtol(tmp.c_str(), &errptr, base));
|
---|
207 |
|
---|
208 | tmp = cfDeath.getSetting("radius");
|
---|
209 | mRotationRadius = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
210 |
|
---|
211 | tmp = cfDeath.getSetting("period");
|
---|
212 | mOptions.mRotationPeriod = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
213 |
|
---|
214 | tmp = cfDeath.getSetting("movespeed");
|
---|
215 | mOptions.mMoveSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
216 |
|
---|
217 | tmp = cfDeath.getSetting("rotatespeed");
|
---|
218 | mOptions.mRotateSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
219 |
|
---|
220 | // command line has preference over config file
|
---|
221 | if (mOptions.mDemoInfileName.empty())
|
---|
222 | mOptions.mDemoInfileName = cfDeath.getSetting("demoinfile");
|
---|
223 |
|
---|
224 | if (mOptions.mDemoOutfileName.empty())
|
---|
225 | mOptions.mDemoOutfileName = cfDeath.getSetting("demooutfile");
|
---|
226 |
|
---|
227 | if (mOptions.mDemoLogfileName.empty())
|
---|
228 | mOptions.mDemoLogfileName = cfDeath.getSetting("demologfile");
|
---|
229 |
|
---|
230 | ExampleApplication::setupResources();
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | void KdTreeApp::createScene(void)
|
---|
235 | {
|
---|
236 | createMaterials();
|
---|
237 |
|
---|
238 | Entity *deaths;
|
---|
239 | SceneNode *nodes;
|
---|
240 | std::string entName = "death";
|
---|
241 | std::string nodeName = "DeathNode";
|
---|
242 | int i, j, x, z;
|
---|
243 | Real planeHalf = mPlaneDim / 2;
|
---|
244 | Real planeThreeEights = mPlaneDim * 3 / 8;
|
---|
245 | Real planeSixth = mPlaneDim / 6;
|
---|
246 |
|
---|
247 | // load scene from file
|
---|
248 | if (mSceneFiles != "")
|
---|
249 | {
|
---|
250 | // don't load the other stuff
|
---|
251 | loadScene(mSceneFiles);
|
---|
252 | // top view
|
---|
253 | mTopCam->setPosition(Vector3(1232, 3990, -1477));
|
---|
254 | // walkthrough view
|
---|
255 | mCamNode->setPosition(Vector3(827.885, 184.435, -524.984));
|
---|
256 | mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945));
|
---|
257 |
|
---|
258 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true);
|
---|
259 | }
|
---|
260 | else
|
---|
261 | {
|
---|
262 | mCamNode->setPosition(Vector3(1280,600,1666));
|
---|
263 | mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306));
|
---|
264 | //mCamera->lookAt(Vector3(-20,30,10));
|
---|
265 |
|
---|
266 | SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode");
|
---|
267 | //SceneNode *grndan = anchor->createChildSceneNode("GroundAnchor");
|
---|
268 | SceneNode *grndan = mSceneMgr->getRootSceneNode();
|
---|
269 |
|
---|
270 | if (mSelectEntities & ENT_GRID)
|
---|
271 | {
|
---|
272 | for (j = 0, z = -(mModelCount / 2 * mModelSpacing); j < mModelCount; j++, z += mModelSpacing)
|
---|
273 | {
|
---|
274 | for (i = 0, x = -(mModelCount / 2 * mModelSpacing); i < mModelCount; i++, x += mModelSpacing)
|
---|
275 | {
|
---|
276 | deaths = mSceneMgr->createEntity(cat(entName, i, j).c_str(),"robot.mesh");
|
---|
277 | if (mShadowsEnabled)
|
---|
278 | deaths->setCastShadows(true);
|
---|
279 | nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName, i, j).c_str(), Vector3(x, 0 , z));
|
---|
280 | nodes->attachObject(deaths);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | if (mSelectEntities & ENT_RND)
|
---|
286 | {
|
---|
287 | entName = "randomdeath";
|
---|
288 | nodeName = "RandomDeathNode";
|
---|
289 | for (i = 0; i < mRandomCount; i++)
|
---|
290 | {
|
---|
291 | Vector3 pos(
|
---|
292 | Math::RangeRandom(-planeHalf,-planeSixth),
|
---|
293 | 0,
|
---|
294 | Math::RangeRandom(-planeThreeEights, planeThreeEights));
|
---|
295 | deaths = mSceneMgr->createEntity(cat(entName,666,i),"robot.mesh");
|
---|
296 | if (mShadowsEnabled)
|
---|
297 | deaths->setCastShadows(true);
|
---|
298 | nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos,
|
---|
299 | Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y));
|
---|
300 | nodes->attachObject(deaths);
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (mSelectEntities & ENT_SPC)
|
---|
305 | {
|
---|
306 | entName = "randomspaceship";
|
---|
307 | nodeName = "RandomSpaceshipNode";
|
---|
308 | for (i = 0; i < mRandomCount; i++)
|
---|
309 | {
|
---|
310 | Vector3 pos(
|
---|
311 | //Math::RangeRandom(-planeHalf,-planeSixth),
|
---|
312 | Math::RangeRandom(planeSixth,planeHalf),
|
---|
313 | Math::RangeRandom(planeHalf * 0.1, planeHalf),
|
---|
314 | Math::RangeRandom(-planeThreeEights, planeThreeEights));
|
---|
315 | deaths = mSceneMgr->createEntity(cat(entName,666,i),"razor.mesh");
|
---|
316 | if (mShadowsEnabled)
|
---|
317 | deaths->setCastShadows(true);
|
---|
318 | nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos,
|
---|
319 | Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y));
|
---|
320 | nodes->attachObject(deaths);
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | if (mSelectEntities & ENT_MOV)
|
---|
325 | {
|
---|
326 | Entity *movingDeath = mSceneMgr->createEntity("movingDeath","robot.mesh");
|
---|
327 | if (mShadowsEnabled)
|
---|
328 | movingDeath->setCastShadows( true );
|
---|
329 |
|
---|
330 | SceneNode *deathPivotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("deathPivotNode");
|
---|
331 | mMoveNode = deathPivotNode->createChildSceneNode("movingNode", Vector3(0, 0, mRotationRadius)/*,
|
---|
332 | Quaternion(Radian(Math::HALF_PI), Vector3::UNIT_Y)*/);
|
---|
333 | mMoveNode->attachObject(movingDeath);
|
---|
334 |
|
---|
335 | Entity *ent_ball = mSceneMgr->createEntity("ball","sphere.mesh");
|
---|
336 | SceneNode *node_pivot = mMoveNode->createChildSceneNode("pivotNode");
|
---|
337 | SceneNode *node_ball = node_pivot->createChildSceneNode("orbitNode", Vector3(120, 40, 0));
|
---|
338 | node_ball->attachObject(ent_ball);
|
---|
339 | node_ball->scale(0.1, 0.1, 0.1);
|
---|
340 |
|
---|
341 |
|
---|
342 | //mFollowCam->setAutoTracking(true, mMoveNode);
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (mSelectEntities & ENT_PLN)
|
---|
346 | {
|
---|
347 | Plane ground(Vector3::UNIT_Y, 0);
|
---|
348 | MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
349 | ground, mPlaneDim * 4 / 3, mPlaneDim, 20, 20, true, 1, 20, 20, Vector3::UNIT_Z);
|
---|
350 | Entity *ent_ground = mSceneMgr->createEntity("GroundEntity", "ground");
|
---|
351 | ent_ground->setCastShadows(false);
|
---|
352 | ent_ground->setMaterialName("Examples/RustySteel");//("Examples/Rockwall");
|
---|
353 | SceneNode *node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode", Vector3(0, 0, 0));
|
---|
354 | node_ground->attachObject(ent_ground);
|
---|
355 |
|
---|
356 | //MeshManager::getSingleton().createPlane("ground2", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
357 | // ground, mPlaneDim/2, mPlaneDim, 10, 20, true, 1, 10, 20, Vector3::UNIT_Z);
|
---|
358 | //ent_ground = mSceneMgr->createEntity("GroundEntity2", "ground2");
|
---|
359 | //ent_ground->setCastShadows(false);
|
---|
360 | //ent_ground->setMaterialName("Examples/RustySteel");
|
---|
361 | //node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode2", Vector3(-mPlaneDim/4, 0, 0));
|
---|
362 | //node_ground->attachObject(ent_ground);
|
---|
363 | }
|
---|
364 |
|
---|
365 | // Lights
|
---|
366 | mSceneMgr->setAmbientLight(ColourValue(0.1,0.1,0.1));
|
---|
367 | Light *light = mSceneMgr->createLight("light");
|
---|
368 | if (mShadowsEnabled)
|
---|
369 | {
|
---|
370 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
|
---|
371 | light->setType(Light::LT_POINT);
|
---|
372 | light->setPosition(Vector3(x, 300, z + 200));
|
---|
373 | }
|
---|
374 | else
|
---|
375 | {
|
---|
376 | light->setType(Light::LT_DIRECTIONAL);
|
---|
377 | light->setDirection(-1,-1,-1);
|
---|
378 | }
|
---|
379 | light->setDiffuseColour(ColourValue::White);
|
---|
380 | light->setSpecularColour(ColourValue(1, 1, 0.2));
|
---|
381 |
|
---|
382 | // Skybox
|
---|
383 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2);
|
---|
384 | }
|
---|
385 |
|
---|
386 | /* Some math tests
|
---|
387 | Plane planeX(Vector3::UNIT_X, Vector3(10,10,10));
|
---|
388 | Plane planeY(Vector3::UNIT_Y, Vector3(10,10,10));
|
---|
389 | Plane planeZ(Vector3::UNIT_Z, Vector3(10,10,10));
|
---|
390 | Vector3 vect(20,20,20);
|
---|
391 | Vector3 interX = planeX.projectVector(vect);
|
---|
392 | Vector3 interY = planeY.projectVector(vect);
|
---|
393 | Vector3 interZ = planeZ.projectVector(vect);
|
---|
394 | std::stringstream ssX, ssY, ssZ;
|
---|
395 | ssX << "The intersection of " << planeX << " and " << vect << " is at: " << interX;
|
---|
396 | ssY << "The intersection of " << planeY << " and " << vect << " is at: " << interY;
|
---|
397 | ssZ << "The intersection of " << planeZ << " and " << vect << " is at: " << interZ;
|
---|
398 | LogManager::getSingleton().logMessage(ssX.str());
|
---|
399 | LogManager::getSingleton().logMessage(ssY.str());
|
---|
400 | LogManager::getSingleton().logMessage(ssZ.str());
|
---|
401 | */
|
---|
402 | }
|
---|
403 |
|
---|
404 | void KdTreeApp::createFrameListener(void)
|
---|
405 | {
|
---|
406 | mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mOptions);
|
---|
407 | //mFrameListener->showDebugOverlay( true );
|
---|
408 | mRoot->addFrameListener(mFrameListener);
|
---|
409 | mRenderTargerListener = new KdTreeAppRenderTargetListener(mSceneMgr);
|
---|
410 | mWindow->addListener(mRenderTargerListener);
|
---|
411 | }
|
---|
412 |
|
---|
413 | void KdTreeApp::chooseSceneManager(void)
|
---|
414 | {
|
---|
415 | // Get the SceneManager
|
---|
416 | mSceneMgr = mRoot->createSceneManager(
|
---|
417 | KdTreeAppListener::SCENEMANAGERNAME[mOptions.mSceneManager],
|
---|
418 | "MySceneManager");
|
---|
419 | // set params for kdtree scene manager
|
---|
420 | if (mOptions.mSceneManager == KdTreeAppListener::SM_KDT)
|
---|
421 | {
|
---|
422 | mSceneMgr->setOption("BuildMethod", &mOptions.mBuildMethod);
|
---|
423 | mSceneMgr->setOption("KdTreeMaxDepth", &mOptions.mMaxDepth);
|
---|
424 | mSceneMgr->setOption("KT", &mOptions.mKT);
|
---|
425 | mSceneMgr->setOption("KI", &mOptions.mKI);
|
---|
426 | mSceneMgr->setOption("RenderMethod", &mOptions.mRenderMethod);
|
---|
427 | mSceneMgr->setOption("EnhancedVisibility", &mOptions.mEnhancedVisibility);
|
---|
428 | // fix
|
---|
429 | bool depthpass = false;
|
---|
430 | mSceneMgr->setOption("UseDepthPass", &depthpass);
|
---|
431 | }
|
---|
432 | // set algorithm when scene manager is OCM - numbering is different though
|
---|
433 | else if (mOptions.mSceneManager == KdTreeAppListener::SM_OCM)
|
---|
434 | {
|
---|
435 | int alg = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod);
|
---|
436 | mSceneMgr->setOption("Algorithm", &alg);
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | void KdTreeApp::createCamera(void)
|
---|
441 | {
|
---|
442 | // Create the camera
|
---|
443 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
444 | mCamera->setNearClipDistance(1);
|
---|
445 |
|
---|
446 | mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PlayerCamNode", Vector3(0,0,0));
|
---|
447 | mCamNode->attachObject(mCamera);
|
---|
448 |
|
---|
449 |
|
---|
450 | // Position it at 500 in Z direction
|
---|
451 | //mCamera->setPosition(Vector3(0,50,500));
|
---|
452 | //mCamera->setPosition(Vector3(500,256,666));
|
---|
453 | //mCamera->setPosition(Vector3(1280,600,1666));
|
---|
454 | // Look back along -Z
|
---|
455 | //mCamera->lookAt(Vector3(0,50,-300));
|
---|
456 | //mCamera->lookAt(Vector3(-20,30,10));
|
---|
457 |
|
---|
458 | //mFollowCam = mSceneMgr->createCamera("FollowCam");
|
---|
459 | //mFollowCam->setPosition(Vector3(800,150,800));
|
---|
460 | //mFollowCam->setNearClipDistance(5);
|
---|
461 | //mFollowCam->setFOVy(Angle(15));
|
---|
462 |
|
---|
463 | mTopCam = mSceneMgr->createCamera("TopCam");
|
---|
464 | mTopCam->setPosition(Vector3(0,mPlaneDim * 1.25,0));
|
---|
465 | mTopCam->setDirection(0,0,-1);
|
---|
466 | mTopCam->pitch(Radian(-Math::HALF_PI));
|
---|
467 | mTopCam->setCullingFrustum(mCamera);
|
---|
468 | mTopCam->setNearClipDistance(1);
|
---|
469 |
|
---|
470 | // infinite far plane?
|
---|
471 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
|
---|
472 | {
|
---|
473 | mTopCam->setFarClipDistance(0);
|
---|
474 | mCamera->setFarClipDistance(0);
|
---|
475 | }
|
---|
476 | else
|
---|
477 | {
|
---|
478 | mTopCam->setFarClipDistance(20000);
|
---|
479 | mCamera->setFarClipDistance(20000);
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | void KdTreeApp::createViewports(void)
|
---|
484 | {
|
---|
485 | // Create one viewport, entire window
|
---|
486 | Viewport* vp = mWindow->addViewport(mCamera);
|
---|
487 | vp->setBackgroundColour(ColourValue(0,0,100));
|
---|
488 |
|
---|
489 | // Alter the camera aspect ratio to match the viewport
|
---|
490 | mCamera->setAspectRatio(
|
---|
491 | Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
|
---|
492 | /*
|
---|
493 | Viewport* fvp = mWindow->addViewport(mFollowCam,2,0.75,0.75,0.25,0.25);
|
---|
494 | fvp->setBackgroundColour(ColourValue(100,0,0));
|
---|
495 | fvp->setOverlaysEnabled( false );
|
---|
496 |
|
---|
497 | mFollowCam->setAspectRatio(
|
---|
498 | Real(fvp->getActualWidth()) / Real(fvp->getActualHeight()));
|
---|
499 | */
|
---|
500 | }
|
---|
501 |
|
---|
502 | bool KdTreeApp::configure(void)
|
---|
503 | {
|
---|
504 | // Show the configuration dialog and initialise the system
|
---|
505 | // You can skip this and use root.restoreConfig() to load configuration
|
---|
506 | // settings if you were sure there are valid ones saved in ogre.cfg
|
---|
507 | #ifdef KDTREE_FASTSTART
|
---|
508 | if(mRoot->restoreConfig())
|
---|
509 | #else
|
---|
510 | if(mRoot->showConfigDialog())
|
---|
511 | #endif
|
---|
512 | {
|
---|
513 | // If returned true, user clicked OK so initialise
|
---|
514 | // Here we choose to let the system create a default rendering window by passing 'true'
|
---|
515 | mWindow = mRoot->initialise(true);
|
---|
516 | return true;
|
---|
517 | }
|
---|
518 | else
|
---|
519 | {
|
---|
520 | return false;
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | void KdTreeApp::createMaterials()
|
---|
525 | {
|
---|
526 | MaterialPtr mat;
|
---|
527 | Technique * tech;
|
---|
528 | Pass * pass;
|
---|
529 | TextureUnitState * tex;
|
---|
530 |
|
---|
531 | // create play button
|
---|
532 | mat = MaterialManager::getSingleton().create("KdTree/DemoPlayButton", "General");
|
---|
533 | mat->setLightingEnabled(false);
|
---|
534 | tech = mat->getTechnique(0);
|
---|
535 | tech->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
536 | tech->setDepthCheckEnabled(false);
|
---|
537 | pass = tech->getPass(0);
|
---|
538 | tex = pass->createTextureUnitState();
|
---|
539 | tex->setTextureName("DemoPlayButton.png");
|
---|
540 |
|
---|
541 | // create record button
|
---|
542 | mat = MaterialManager::getSingleton().create("KdTree/DemoRecordButton", "General");
|
---|
543 | mat->setLightingEnabled(false);
|
---|
544 | tech = mat->getTechnique(0);
|
---|
545 | tech->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
546 | tech->setDepthCheckEnabled(false);
|
---|
547 | pass = tech->getPass(0);
|
---|
548 | tex = pass->createTextureUnitState();
|
---|
549 | tex->setTextureName("DemoRecordButton.png");
|
---|
550 | }
|
---|
551 |
|
---|
552 |
|
---|
553 | //-----------------------------------------------------------------------
|
---|
554 | // splits strings containing multiple file names
|
---|
555 | static int splitFilenames(const std::string str, std::vector<std::string> &filenames)
|
---|
556 | {
|
---|
557 | int pos = 0;
|
---|
558 |
|
---|
559 | while(1)
|
---|
560 | {
|
---|
561 | int npos = (int)str.find(';', pos);
|
---|
562 |
|
---|
563 | if (npos < 0 || npos - pos < 1)
|
---|
564 | break;
|
---|
565 | filenames.push_back(std::string(str, pos, npos - pos));
|
---|
566 | pos = npos + 1;
|
---|
567 | }
|
---|
568 |
|
---|
569 | filenames.push_back(std::string(str, pos, str.size() - pos));
|
---|
570 | return (int)filenames.size();
|
---|
571 | }
|
---|
572 |
|
---|
573 | bool KdTreeApp::loadScene(const String &filename)
|
---|
574 | {
|
---|
575 | // use leaf nodes of the original spatial hierarchy as occludees
|
---|
576 | std::vector<std::string> filenames;
|
---|
577 | int files = splitFilenames(filename, filenames);
|
---|
578 |
|
---|
579 | std::stringstream d;
|
---|
580 | d << "number of input files: " << files << "\n";
|
---|
581 | LogManager::getSingleton().logMessage(d.str());
|
---|
582 |
|
---|
583 | bool result = false;
|
---|
584 | std::vector<std::string>::const_iterator fit, fit_end = filenames.end();
|
---|
585 | int i = 0;
|
---|
586 | // root for different files
|
---|
587 | for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
|
---|
588 | {
|
---|
589 | const std::string fn = *fit;
|
---|
590 |
|
---|
591 | if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
|
---|
592 | {
|
---|
593 | // hack: set postion manually for vienna
|
---|
594 | //mCamNode->setPosition(Vector3(830, 300, -540));
|
---|
595 | //mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
|
---|
596 |
|
---|
597 | // load iv files
|
---|
598 | loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i);
|
---|
599 | }
|
---|
600 |
|
---|
601 | result = true;
|
---|
602 | }
|
---|
603 |
|
---|
604 |
|
---|
605 | /*
|
---|
606 | if (result)
|
---|
607 | {
|
---|
608 | int intersectables, faces;
|
---|
609 |
|
---|
610 | std::stringstream d;
|
---|
611 | d << filename << " parsed successfully.\n"
|
---|
612 | << "#NUM_OBJECTS (Total numner of objects)\n" << intersectables << "\n"
|
---|
613 | << "#NUM_FACES (Total numner of faces)\n" << faces << "\n";
|
---|
614 | }
|
---|
615 | */
|
---|
616 |
|
---|
617 | return result;
|
---|
618 | }
|
---|
619 |
|
---|
620 | //-----------------------------------------------------------------------
|
---|
621 | bool KdTreeApp::loadSceneIV(const String &filename, SceneNode *root, const int index)
|
---|
622 | {
|
---|
623 | IVReader * mIVReader = new IVReader();
|
---|
624 |
|
---|
625 | if (1)
|
---|
626 | {
|
---|
627 | String logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log";
|
---|
628 |
|
---|
629 | Log *log = LogManager::getSingleton().createLog(logFilename);
|
---|
630 | mIVReader->setLog(log);
|
---|
631 | }
|
---|
632 |
|
---|
633 | //viennaNode->translate(Vector3(-300, -300, 0));
|
---|
634 |
|
---|
635 | if (mIVReader->loadFile(filename.c_str()))
|
---|
636 | {
|
---|
637 | SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
|
---|
638 |
|
---|
639 | mIVReader->buildTree(mSceneMgr, node);
|
---|
640 |
|
---|
641 | mIVReader->collapse();
|
---|
642 | OGRE_DELETE(mIVReader);
|
---|
643 |
|
---|
644 | return true;
|
---|
645 | }
|
---|
646 |
|
---|
647 | return false;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /**********************************************************************/
|
---|
651 | /* VisualizationRenderTargetListener implementation */
|
---|
652 | /**********************************************************************/
|
---|
653 |
|
---|
654 |
|
---|
655 | //-----------------------------------------------------------------------
|
---|
656 | KdTreeAppRenderTargetListener::KdTreeAppRenderTargetListener(SceneManager *sceneMgr)
|
---|
657 | :RenderTargetListener(), mSceneMgr(sceneMgr)
|
---|
658 | {
|
---|
659 | }
|
---|
660 | //-----------------------------------------------------------------------
|
---|
661 | void KdTreeAppRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
|
---|
662 | {
|
---|
663 | // visualization viewport
|
---|
664 | const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
|
---|
665 | const bool nShowViz = !showViz;
|
---|
666 |
|
---|
667 | mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
|
---|
668 | mSavedAmbientLight = mSceneMgr->getAmbientLight();
|
---|
669 |
|
---|
670 | // -- ambient light must be full for visualization, shadows disabled
|
---|
671 | if (showViz)
|
---|
672 | {
|
---|
673 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
674 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
675 | }
|
---|
676 |
|
---|
677 | mSceneMgr->setOption("PrepareVisualization", &showViz);
|
---|
678 | SceneNode * skybox = mSceneMgr->getSkyBoxNode();
|
---|
679 | if (skybox != 0)
|
---|
680 | mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
|
---|
681 | //if ((SceneNode * skyplane = mSceneMgr->getSkyPlaneNode()) != 0)
|
---|
682 | // mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
|
---|
683 |
|
---|
684 | RenderTargetListener::preViewportUpdate(evt);
|
---|
685 | }
|
---|
686 | //-----------------------------------------------------------------------
|
---|
687 | void KdTreeAppRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
|
---|
688 | {
|
---|
689 | // reset values
|
---|
690 | mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
|
---|
691 | mSceneMgr->setAmbientLight(mSavedAmbientLight);
|
---|
692 |
|
---|
693 | RenderTargetListener::postRenderTargetUpdate(evt);
|
---|
694 | } |
---|