[1163] | 1 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 2 | #define WIN32_LEAN_AND_MEAN
|
---|
| 3 | #include "windows.h"
|
---|
| 4 | #endif
|
---|
| 5 |
|
---|
[1203] | 6 | #include "TestKdTree.h"
|
---|
[1204] | 7 | #include "WinCmdLineParser.h"
|
---|
[1203] | 8 |
|
---|
[1163] | 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 | {
|
---|
[1202] | 19 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 20 | // parse windows-style command line
|
---|
| 21 |
|
---|
[1204] | 22 | WinCmdLineParser cmdparser(strCmdLine);
|
---|
| 23 | KdTreeAppListener::Options options;
|
---|
[1202] | 24 |
|
---|
[1204] | 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)
|
---|
[1220] | 32 | .addOpt("","buildmode", ARGUMENT_REQUIRED)
|
---|
[1204] | 33 | .addOpt("","maxdepth", ARGUMENT_REQUIRED)
|
---|
| 34 | .addOpt("","kt", ARGUMENT_REQUIRED)
|
---|
| 35 | .addOpt("","ki", ARGUMENT_REQUIRED)
|
---|
[1205] | 36 | .addOpt("r","rendermode", ARGUMENT_REQUIRED)
|
---|
[1215] | 37 | .addOpt("s","scenemgr", ARGUMENT_REQUIRED)
|
---|
| 38 | .addOpt("","comment", ARGUMENT_REQUIRED)
|
---|
| 39 | .addOpt("e","enhancevis", ARGUMENT_NONE);
|
---|
[1202] | 40 |
|
---|
[1203] | 41 |
|
---|
[1204] | 42 | cmdparser.getOpt("i", options.mDemoInfileName);
|
---|
| 43 | cmdparser.getOpt("o", options.mDemoOutfileName);
|
---|
| 44 | cmdparser.getOpt("l", options.mDemoLogfileName);
|
---|
[1215] | 45 | cmdparser.getOpt("comment", options.mComment);
|
---|
[1204] | 46 | options.mDemoMode = cmdparser.getOpt("d");
|
---|
[1215] | 47 | options.mEnhancedVisibility = cmdparser.getOpt("e");
|
---|
[1203] | 48 |
|
---|
[1204] | 49 | std::string tmp;
|
---|
| 50 | std::stringstream s;
|
---|
[1203] | 51 |
|
---|
[1220] | 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 |
|
---|
[1204] | 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 | {
|
---|
[1220] | 94 | int rm = KdTree::KDRM_NOTSET;
|
---|
| 95 | for (int i = 0; i < KdTree::KDRM_SIZE; i ++)
|
---|
[1204] | 96 | {
|
---|
[1220] | 97 | if (tmp == KdTreeAppListener::RENDERMETHOD[i])
|
---|
| 98 | rm = i;
|
---|
[1204] | 99 | }
|
---|
[1220] | 100 | if (rm != KdTree::KDRM_NOTSET)
|
---|
| 101 | {
|
---|
| 102 | options.mRenderMethod = rm;
|
---|
| 103 | }
|
---|
[1204] | 104 | else
|
---|
| 105 | {
|
---|
[1220] | 106 | MessageBox(NULL, ("Invalid argument for option --rendermode: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
[1204] | 107 | return -1;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[1205] | 111 | if (cmdparser.getOpt("s",tmp))
|
---|
| 112 | {
|
---|
[1220] | 113 | int sm = KdTreeAppListener::SM_NOTSET;
|
---|
| 114 | for (int i = 0; i < KdTreeAppListener::SM_SIZE; i ++)
|
---|
[1205] | 115 | {
|
---|
[1220] | 116 | if (tmp == KdTreeAppListener::SCENEMANAGER[i])
|
---|
| 117 | sm = i;
|
---|
[1205] | 118 | }
|
---|
[1220] | 119 | if (sm != KdTreeAppListener::SM_NOTSET)
|
---|
| 120 | {
|
---|
| 121 | options.mSceneManager = sm;
|
---|
| 122 | }
|
---|
[1205] | 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 |
|
---|
[1204] | 130 | }
|
---|
| 131 | catch (std::string s)
|
---|
| 132 | {
|
---|
| 133 | MessageBox(NULL, s.c_str(), "Error", MB_OK | MB_ICONERROR );
|
---|
| 134 | return -1;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[1163] | 137 | // Create application object
|
---|
[1204] | 138 | KdTreeApp app(options);
|
---|
[1202] | 139 | #else
|
---|
| 140 | // TODO: unix-style getopt
|
---|
| 141 | // Create application object
|
---|
[1163] | 142 | KdTreeApp app;
|
---|
[1202] | 143 | #endif
|
---|
[1163] | 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");
|
---|
[1204] | 212 | mOptions.mRotationPeriod = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
[1163] | 213 |
|
---|
| 214 | tmp = cfDeath.getSetting("movespeed");
|
---|
[1204] | 215 | mOptions.mMoveSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
[1163] | 216 |
|
---|
| 217 | tmp = cfDeath.getSetting("rotatespeed");
|
---|
[1204] | 218 | mOptions.mRotateSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr));
|
---|
[1163] | 219 |
|
---|
[1202] | 220 | // command line has preference over config file
|
---|
[1204] | 221 | if (mOptions.mDemoInfileName.empty())
|
---|
| 222 | mOptions.mDemoInfileName = cfDeath.getSetting("demoinfile");
|
---|
[1202] | 223 |
|
---|
[1204] | 224 | if (mOptions.mDemoOutfileName.empty())
|
---|
| 225 | mOptions.mDemoOutfileName = cfDeath.getSetting("demooutfile");
|
---|
[1202] | 226 |
|
---|
[1204] | 227 | if (mOptions.mDemoLogfileName.empty())
|
---|
| 228 | mOptions.mDemoLogfileName = cfDeath.getSetting("demologfile");
|
---|
| 229 |
|
---|
[1163] | 230 | ExampleApplication::setupResources();
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 | void KdTreeApp::createScene(void)
|
---|
| 235 | {
|
---|
[1200] | 236 | createMaterials();
|
---|
| 237 |
|
---|
[1163] | 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);
|
---|
[1215] | 252 | // top view
|
---|
[1163] | 253 | mTopCam->setPosition(Vector3(1232, 3990, -1477));
|
---|
[1165] | 254 | // walkthrough view
|
---|
[1215] | 255 | mCamNode->setPosition(Vector3(827.885, 184.435, -524.984));
|
---|
| 256 | mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945));
|
---|
[1187] | 257 |
|
---|
| 258 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true);
|
---|
[1163] | 259 | }
|
---|
| 260 | else
|
---|
| 261 | {
|
---|
[1187] | 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 |
|
---|
[1163] | 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");
|
---|
[1204] | 331 | mMoveNode = deathPivotNode->createChildSceneNode("movingNode", Vector3(0, 0, mRotationRadius)/*,
|
---|
[1163] | 332 | Quaternion(Radian(Math::HALF_PI), Vector3::UNIT_Y)*/);
|
---|
[1204] | 333 | mMoveNode->attachObject(movingDeath);
|
---|
[1163] | 334 |
|
---|
| 335 | Entity *ent_ball = mSceneMgr->createEntity("ball","sphere.mesh");
|
---|
[1204] | 336 | SceneNode *node_pivot = mMoveNode->createChildSceneNode("pivotNode");
|
---|
[1163] | 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 |
|
---|
[1204] | 342 | //mFollowCam->setAutoTracking(true, mMoveNode);
|
---|
[1163] | 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 | }
|
---|
[1195] | 379 | light->setDiffuseColour(ColourValue::White);
|
---|
[1163] | 380 | light->setSpecularColour(ColourValue(1, 1, 0.2));
|
---|
| 381 |
|
---|
| 382 | // Skybox
|
---|
[1187] | 383 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2);
|
---|
[1163] | 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 | {
|
---|
[1204] | 406 | mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mOptions);
|
---|
| 407 | //mFrameListener->showDebugOverlay( true );
|
---|
[1163] | 408 | mRoot->addFrameListener(mFrameListener);
|
---|
[1195] | 409 | mRenderTargerListener = new KdTreeAppRenderTargetListener(mSceneMgr);
|
---|
| 410 | mWindow->addListener(mRenderTargerListener);
|
---|
[1163] | 411 | }
|
---|
| 412 |
|
---|
| 413 | void KdTreeApp::chooseSceneManager(void)
|
---|
| 414 | {
|
---|
| 415 | // Get the SceneManager
|
---|
[1220] | 416 | mSceneMgr = mRoot->createSceneManager(
|
---|
| 417 | KdTreeAppListener::SCENEMANAGERNAME[mOptions.mSceneManager],
|
---|
| 418 | "MySceneManager");
|
---|
| 419 | // set params depending on 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 | }
|
---|
| 429 | // set algorithm when scene manager is OCM - numbering is different though
|
---|
| 430 | if (mOptions.mSceneManager == KdTreeAppListener::SM_OCM)
|
---|
| 431 | {
|
---|
| 432 | int alg = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod);
|
---|
| 433 | mSceneMgr->setOption("Algorithm", &alg);
|
---|
| 434 | }
|
---|
[1163] | 435 | }
|
---|
| 436 |
|
---|
| 437 | void KdTreeApp::createCamera(void)
|
---|
| 438 | {
|
---|
| 439 | // Create the camera
|
---|
| 440 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
[1187] | 441 | mCamera->setNearClipDistance(1);
|
---|
[1163] | 442 |
|
---|
[1187] | 443 | mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PlayerCamNode", Vector3(0,0,0));
|
---|
| 444 | mCamNode->attachObject(mCamera);
|
---|
| 445 |
|
---|
| 446 |
|
---|
[1163] | 447 | // Position it at 500 in Z direction
|
---|
| 448 | //mCamera->setPosition(Vector3(0,50,500));
|
---|
| 449 | //mCamera->setPosition(Vector3(500,256,666));
|
---|
[1187] | 450 | //mCamera->setPosition(Vector3(1280,600,1666));
|
---|
[1163] | 451 | // Look back along -Z
|
---|
| 452 | //mCamera->lookAt(Vector3(0,50,-300));
|
---|
[1187] | 453 | //mCamera->lookAt(Vector3(-20,30,10));
|
---|
[1163] | 454 |
|
---|
[1187] | 455 | //mFollowCam = mSceneMgr->createCamera("FollowCam");
|
---|
| 456 | //mFollowCam->setPosition(Vector3(800,150,800));
|
---|
| 457 | //mFollowCam->setNearClipDistance(5);
|
---|
| 458 | //mFollowCam->setFOVy(Angle(15));
|
---|
[1163] | 459 |
|
---|
| 460 | mTopCam = mSceneMgr->createCamera("TopCam");
|
---|
| 461 | mTopCam->setPosition(Vector3(0,mPlaneDim * 1.25,0));
|
---|
| 462 | mTopCam->setDirection(0,0,-1);
|
---|
| 463 | mTopCam->pitch(Radian(-Math::HALF_PI));
|
---|
[1220] | 464 | mTopCam->setCullingFrustum(mCamera);
|
---|
[1187] | 465 | mTopCam->setNearClipDistance(1);
|
---|
| 466 |
|
---|
| 467 | // infinite far plane?
|
---|
| 468 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
|
---|
| 469 | {
|
---|
| 470 | mTopCam->setFarClipDistance(0);
|
---|
| 471 | mCamera->setFarClipDistance(0);
|
---|
| 472 | }
|
---|
| 473 | else
|
---|
| 474 | {
|
---|
| 475 | mTopCam->setFarClipDistance(20000);
|
---|
| 476 | mCamera->setFarClipDistance(20000);
|
---|
| 477 | }
|
---|
[1163] | 478 | }
|
---|
| 479 |
|
---|
| 480 | void KdTreeApp::createViewports(void)
|
---|
| 481 | {
|
---|
| 482 | // Create one viewport, entire window
|
---|
| 483 | Viewport* vp = mWindow->addViewport(mCamera);
|
---|
| 484 | vp->setBackgroundColour(ColourValue(0,0,100));
|
---|
| 485 |
|
---|
| 486 | // Alter the camera aspect ratio to match the viewport
|
---|
| 487 | mCamera->setAspectRatio(
|
---|
| 488 | Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
|
---|
| 489 | /*
|
---|
| 490 | Viewport* fvp = mWindow->addViewport(mFollowCam,2,0.75,0.75,0.25,0.25);
|
---|
| 491 | fvp->setBackgroundColour(ColourValue(100,0,0));
|
---|
| 492 | fvp->setOverlaysEnabled( false );
|
---|
| 493 |
|
---|
| 494 | mFollowCam->setAspectRatio(
|
---|
| 495 | Real(fvp->getActualWidth()) / Real(fvp->getActualHeight()));
|
---|
| 496 | */
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | bool KdTreeApp::configure(void)
|
---|
| 500 | {
|
---|
| 501 | // Show the configuration dialog and initialise the system
|
---|
| 502 | // You can skip this and use root.restoreConfig() to load configuration
|
---|
| 503 | // settings if you were sure there are valid ones saved in ogre.cfg
|
---|
| 504 | #ifdef KDTREE_FASTSTART
|
---|
| 505 | if(mRoot->restoreConfig())
|
---|
| 506 | #else
|
---|
| 507 | if(mRoot->showConfigDialog())
|
---|
| 508 | #endif
|
---|
| 509 | {
|
---|
| 510 | // If returned true, user clicked OK so initialise
|
---|
| 511 | // Here we choose to let the system create a default rendering window by passing 'true'
|
---|
| 512 | mWindow = mRoot->initialise(true);
|
---|
| 513 | return true;
|
---|
| 514 | }
|
---|
| 515 | else
|
---|
| 516 | {
|
---|
| 517 | return false;
|
---|
| 518 | }
|
---|
| 519 | }
|
---|
| 520 |
|
---|
[1200] | 521 | void KdTreeApp::createMaterials()
|
---|
| 522 | {
|
---|
| 523 | MaterialPtr mat;
|
---|
| 524 | Technique * tech;
|
---|
| 525 | Pass * pass;
|
---|
| 526 | TextureUnitState * tex;
|
---|
[1163] | 527 |
|
---|
[1200] | 528 | // create play button
|
---|
| 529 | mat = MaterialManager::getSingleton().create("KdTree/DemoPlayButton", "General");
|
---|
| 530 | mat->setLightingEnabled(false);
|
---|
| 531 | tech = mat->getTechnique(0);
|
---|
| 532 | tech->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
| 533 | tech->setDepthCheckEnabled(false);
|
---|
| 534 | pass = tech->getPass(0);
|
---|
| 535 | tex = pass->createTextureUnitState();
|
---|
| 536 | tex->setTextureName("DemoPlayButton.png");
|
---|
| 537 |
|
---|
| 538 | // create record button
|
---|
| 539 | mat = MaterialManager::getSingleton().create("KdTree/DemoRecordButton", "General");
|
---|
| 540 | mat->setLightingEnabled(false);
|
---|
| 541 | tech = mat->getTechnique(0);
|
---|
| 542 | tech->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
| 543 | tech->setDepthCheckEnabled(false);
|
---|
| 544 | pass = tech->getPass(0);
|
---|
| 545 | tex = pass->createTextureUnitState();
|
---|
| 546 | tex->setTextureName("DemoRecordButton.png");
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 |
|
---|
[1163] | 550 | //-----------------------------------------------------------------------
|
---|
| 551 | // splits strings containing multiple file names
|
---|
| 552 | static int splitFilenames(const std::string str, std::vector<std::string> &filenames)
|
---|
| 553 | {
|
---|
| 554 | int pos = 0;
|
---|
| 555 |
|
---|
| 556 | while(1)
|
---|
| 557 | {
|
---|
| 558 | int npos = (int)str.find(';', pos);
|
---|
| 559 |
|
---|
| 560 | if (npos < 0 || npos - pos < 1)
|
---|
| 561 | break;
|
---|
| 562 | filenames.push_back(std::string(str, pos, npos - pos));
|
---|
| 563 | pos = npos + 1;
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | filenames.push_back(std::string(str, pos, str.size() - pos));
|
---|
| 567 | return (int)filenames.size();
|
---|
| 568 | }
|
---|
| 569 |
|
---|
| 570 | bool KdTreeApp::loadScene(const String &filename)
|
---|
| 571 | {
|
---|
| 572 | // use leaf nodes of the original spatial hierarchy as occludees
|
---|
| 573 | std::vector<std::string> filenames;
|
---|
| 574 | int files = splitFilenames(filename, filenames);
|
---|
| 575 |
|
---|
| 576 | std::stringstream d;
|
---|
| 577 | d << "number of input files: " << files << "\n";
|
---|
| 578 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 579 |
|
---|
| 580 | bool result = false;
|
---|
| 581 | std::vector<std::string>::const_iterator fit, fit_end = filenames.end();
|
---|
| 582 | int i = 0;
|
---|
| 583 | // root for different files
|
---|
| 584 | for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
|
---|
| 585 | {
|
---|
| 586 | const std::string fn = *fit;
|
---|
| 587 |
|
---|
| 588 | if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
|
---|
| 589 | {
|
---|
| 590 | // hack: set postion manually for vienna
|
---|
| 591 | //mCamNode->setPosition(Vector3(830, 300, -540));
|
---|
| 592 | //mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
|
---|
| 593 |
|
---|
| 594 | // load iv files
|
---|
| 595 | loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i);
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | result = true;
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 |
|
---|
| 602 | /*
|
---|
| 603 | if (result)
|
---|
| 604 | {
|
---|
| 605 | int intersectables, faces;
|
---|
| 606 |
|
---|
| 607 | std::stringstream d;
|
---|
| 608 | d << filename << " parsed successfully.\n"
|
---|
| 609 | << "#NUM_OBJECTS (Total numner of objects)\n" << intersectables << "\n"
|
---|
| 610 | << "#NUM_FACES (Total numner of faces)\n" << faces << "\n";
|
---|
| 611 | }
|
---|
| 612 | */
|
---|
| 613 |
|
---|
| 614 | return result;
|
---|
| 615 | }
|
---|
| 616 |
|
---|
| 617 | //-----------------------------------------------------------------------
|
---|
| 618 | bool KdTreeApp::loadSceneIV(const String &filename, SceneNode *root, const int index)
|
---|
| 619 | {
|
---|
| 620 | IVReader * mIVReader = new IVReader();
|
---|
| 621 |
|
---|
| 622 | if (1)
|
---|
| 623 | {
|
---|
| 624 | String logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log";
|
---|
| 625 |
|
---|
| 626 | Log *log = LogManager::getSingleton().createLog(logFilename);
|
---|
| 627 | mIVReader->setLog(log);
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | //viennaNode->translate(Vector3(-300, -300, 0));
|
---|
| 631 |
|
---|
| 632 | if (mIVReader->loadFile(filename.c_str()))
|
---|
| 633 | {
|
---|
| 634 | SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
|
---|
| 635 |
|
---|
| 636 | mIVReader->buildTree(mSceneMgr, node);
|
---|
| 637 |
|
---|
| 638 | mIVReader->collapse();
|
---|
| 639 | OGRE_DELETE(mIVReader);
|
---|
| 640 |
|
---|
| 641 | return true;
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | return false;
|
---|
[1187] | 645 | }
|
---|
| 646 |
|
---|
| 647 | /**********************************************************************/
|
---|
| 648 | /* VisualizationRenderTargetListener implementation */
|
---|
| 649 | /**********************************************************************/
|
---|
| 650 |
|
---|
| 651 |
|
---|
| 652 | //-----------------------------------------------------------------------
|
---|
| 653 | KdTreeAppRenderTargetListener::KdTreeAppRenderTargetListener(SceneManager *sceneMgr)
|
---|
| 654 | :RenderTargetListener(), mSceneMgr(sceneMgr)
|
---|
| 655 | {
|
---|
| 656 | }
|
---|
| 657 | //-----------------------------------------------------------------------
|
---|
| 658 | void KdTreeAppRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
|
---|
| 659 | {
|
---|
| 660 | // visualization viewport
|
---|
| 661 | const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
|
---|
| 662 | const bool nShowViz = !showViz;
|
---|
| 663 |
|
---|
| 664 | mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
|
---|
| 665 | mSavedAmbientLight = mSceneMgr->getAmbientLight();
|
---|
| 666 |
|
---|
| 667 | // -- ambient light must be full for visualization, shadows disabled
|
---|
| 668 | if (showViz)
|
---|
| 669 | {
|
---|
| 670 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 671 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | mSceneMgr->setOption("PrepareVisualization", &showViz);
|
---|
[1190] | 675 | SceneNode * skybox = mSceneMgr->getSkyBoxNode();
|
---|
| 676 | if (skybox != 0)
|
---|
| 677 | mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
|
---|
| 678 | //if ((SceneNode * skyplane = mSceneMgr->getSkyPlaneNode()) != 0)
|
---|
| 679 | // mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
|
---|
[1187] | 680 |
|
---|
| 681 | RenderTargetListener::preViewportUpdate(evt);
|
---|
| 682 | }
|
---|
| 683 | //-----------------------------------------------------------------------
|
---|
| 684 | void KdTreeAppRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
|
---|
| 685 | {
|
---|
| 686 | // reset values
|
---|
| 687 | mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
|
---|
| 688 | mSceneMgr->setAmbientLight(mSavedAmbientLight);
|
---|
| 689 |
|
---|
| 690 | RenderTargetListener::postRenderTargetUpdate(evt);
|
---|
[1163] | 691 | } |
---|