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