[61] | 1 | /**
|
---|
| 2 | \file
|
---|
| 3 | TestCullingTerrainApplication.cpp
|
---|
| 4 | \brief
|
---|
[74] | 5 | Tests the visibility culling algorithm
|
---|
[61] | 6 | */
|
---|
| 7 |
|
---|
| 8 | #include <OgreNoMemoryMacros.h>
|
---|
| 9 | #include <CEGUI/CEGUI.h>
|
---|
| 10 | #include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
|
---|
| 11 | #include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
|
---|
| 12 | #include <../CEGUIRenderer/include/OgreCEGUITexture.h>
|
---|
| 13 | #include <OgreMemoryMacros.h>
|
---|
| 14 |
|
---|
[100] | 15 | #include <Ogre.h>
|
---|
| 16 | #include "OgreReferenceAppLayer.h"
|
---|
| 17 | //#include "OgreRefAppWorld.h"
|
---|
[61] | 18 | #include "TestCullingTerrainApplication.h"
|
---|
| 19 |
|
---|
| 20 | #define WIN32_LEAN_AND_MEAN
|
---|
[94] | 21 | #include <windows.h>
|
---|
[61] | 22 |
|
---|
[100] | 23 | #define VIZ_VIEWPORT_Z_ORDER 10
|
---|
[61] | 24 |
|
---|
[107] | 25 | const char* frame_outfile = "frame.out";
|
---|
| 26 | const char* objects_outfile = "objects.out";
|
---|
| 27 |
|
---|
[80] | 28 | /*******************************************************/
|
---|
| 29 | /* TestCullingTerrainApplication implementation */
|
---|
| 30 | /*******************************************************/
|
---|
[100] | 31 |
|
---|
| 32 | //-----------------------------------------------------------------------
|
---|
[61] | 33 | TestCullingTerrainApplication::~TestCullingTerrainApplication()
|
---|
| 34 | {
|
---|
[93] | 35 | if(mTerrainContentGenerator)
|
---|
| 36 | delete mTerrainContentGenerator;
|
---|
[99] | 37 | //if(mRenderTargetListener) delete mRenderTargetListener;
|
---|
[61] | 38 | }
|
---|
| 39 | //-----------------------------------------------------------------------
|
---|
[93] | 40 | void TestCullingTerrainApplication::createCamera()
|
---|
[61] | 41 | {
|
---|
[99] | 42 | // create the camera
|
---|
[103] | 43 | mCamera = mSceneMgr->createCamera("PlayerCam");
|
---|
[93] | 44 |
|
---|
[100] | 45 | /** set a nice viewpoint
|
---|
| 46 | * we use a camera node here and apply all transformations on it instead
|
---|
| 47 | * of applying all transformations directly to the camera
|
---|
| 48 | * because then the camera is displayed correctly in the visualization
|
---|
| 49 | */
|
---|
| 50 | mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
| 51 | "CamNode1", Vector3(707, 5000, 528));
|
---|
| 52 | //mCamera->setPosition(707, 5000, 528);
|
---|
| 53 | mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
|
---|
| 54 | mCamNode->attachObject(mCamera);
|
---|
[61] | 55 |
|
---|
[100] | 56 | //-- create visualization camera
|
---|
| 57 | mVizCamera = mSceneMgr->createCamera("VizCam");
|
---|
| 58 | mVizCamera->setPosition(mCamNode->getPosition());
|
---|
| 59 |
|
---|
| 60 | mVizCamera->setNearClipDistance(1);
|
---|
[93] | 61 | mCamera->setNearClipDistance(1);
|
---|
[61] | 62 |
|
---|
[99] | 63 | // infinite far plane?
|
---|
[93] | 64 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
|
---|
| 65 | {
|
---|
[100] | 66 | mVizCamera->setFarClipDistance(0);
|
---|
[93] | 67 | mCamera->setFarClipDistance(0);
|
---|
| 68 | }
|
---|
| 69 | else
|
---|
| 70 | {
|
---|
[104] | 71 | mVizCamera->setFarClipDistance(20000);
|
---|
| 72 | mCamera->setFarClipDistance(20000);
|
---|
[99] | 73 | }
|
---|
[61] | 74 | }
|
---|
[99] | 75 |
|
---|
[61] | 76 | //-----------------------------------------------------------------------
|
---|
[99] | 77 | bool TestCullingTerrainApplication::setup()
|
---|
| 78 | {
|
---|
| 79 | bool result = ExampleApplication::setup();
|
---|
| 80 |
|
---|
| 81 | createRenderTargetListener();
|
---|
| 82 |
|
---|
| 83 | return result;
|
---|
| 84 | }
|
---|
| 85 | //-----------------------------------------------------------------------
|
---|
| 86 | void TestCullingTerrainApplication::createRenderTargetListener()
|
---|
| 87 | {
|
---|
| 88 | mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr));
|
---|
| 89 | }
|
---|
| 90 | //-----------------------------------------------------------------------
|
---|
[75] | 91 | void TestCullingTerrainApplication::createScene()
|
---|
[61] | 92 | {
|
---|
| 93 | // Set ambient light
|
---|
[112] | 94 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
[113] | 95 |
|
---|
[110] | 96 | //-- create light
|
---|
[111] | 97 | mSunLight = mSceneMgr->createLight("SunLight");
|
---|
| 98 | mSunLight->setType(Light::LT_DIRECTIONAL);
|
---|
| 99 | //mSunLight->setType(Light::LT_SPOTLIGHT);
|
---|
[112] | 100 | //mSunLight->setSpotlightRange(Degree(30), Degree(50));
|
---|
| 101 |
|
---|
[111] | 102 | mSunLight->setPosition(707, 2000, 500);
|
---|
| 103 | mSunLight->setCastShadows(true);
|
---|
| 104 |
|
---|
[113] | 105 | Vector3 dir(0.5, 1, 0.5);
|
---|
[110] | 106 | dir.normalise();
|
---|
[112] | 107 | mSunLight->setDirection(dir);
|
---|
| 108 | //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
|
---|
[110] | 109 |
|
---|
[111] | 110 | mSunLight->setDiffuseColour(1, 1, 1);
|
---|
| 111 | mSunLight->setSpecularColour(1, 1, 1);
|
---|
[110] | 112 |
|
---|
[61] | 113 | // --Fog
|
---|
| 114 | // NB it's VERY important to set this before calling setWorldGeometry
|
---|
| 115 | // because the vertex program picked will be different
|
---|
| 116 | ColourValue fadeColour(0.93, 0.86, 0.76);
|
---|
| 117 | mWindow->getViewport(0)->setBackgroundColour(fadeColour);
|
---|
| 118 | //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
|
---|
[94] | 119 |
|
---|
[61] | 120 | // Create a skybox
|
---|
[103] | 121 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false);
|
---|
| 122 |
|
---|
[61] | 123 | std::string terrain_cfg("terrain.cfg");
|
---|
| 124 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
---|
| 125 | terrain_cfg = mResourcePath + terrain_cfg;
|
---|
| 126 | #endif
|
---|
[74] | 127 | mSceneMgr->setWorldGeometry(terrain_cfg);
|
---|
[75] | 128 |
|
---|
[100] | 129 | //-- CEGUI setup
|
---|
[61] | 130 | setupGui();
|
---|
[100] | 131 |
|
---|
[111] | 132 | // Floor plane
|
---|
[112] | 133 | /*Plane plane;
|
---|
[111] | 134 | plane.normal = Vector3::UNIT_Y;
|
---|
| 135 | plane.d = -60;
|
---|
| 136 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
| 137 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
| 138 | 5000,5000,100,100,true,1,5,5,Vector3::UNIT_Z);
|
---|
| 139 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
| 140 | pPlaneEnt->setMaterialName("Examples/Rockwall");
|
---|
| 141 | pPlaneEnt->setCastShadows(true);
|
---|
[112] | 142 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);*/
|
---|
[111] | 143 |
|
---|
| 144 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE))
|
---|
| 145 | {
|
---|
| 146 | // In D3D, use a 1024x1024 shadow texture
|
---|
| 147 | mSceneMgr->setShadowTextureSettings(1024, 2);
|
---|
| 148 | }
|
---|
| 149 | else
|
---|
| 150 | {
|
---|
| 151 | // Use 512x512 texture in GL since we can't go higher than the window res
|
---|
| 152 | mSceneMgr->setShadowTextureSettings(512, 2);
|
---|
| 153 | }
|
---|
[112] | 154 | //mSceneMgr->setShadowColour(ColourValue(0, 0, 0));
|
---|
| 155 | mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
|
---|
| 156 | // mSceneMgr->setShowDebugShadows(true);
|
---|
[111] | 157 |
|
---|
| 158 |
|
---|
[100] | 159 | //-- terrain content setup
|
---|
| 160 |
|
---|
[80] | 161 | // HACK: necessary to call once before the content creation for
|
---|
| 162 | // terrain initialisation
|
---|
| 163 | mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true);
|
---|
[74] | 164 |
|
---|
[82] | 165 | mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
|
---|
[110] | 166 |
|
---|
[107] | 167 | // if no objects file generate yourself
|
---|
[110] | 168 | if (!mTerrainContentGenerator->LoadObjects("objects.out"))
|
---|
| 169 | {
|
---|
[107] | 170 | // height is restricted to 50, so no objects appear on peaks
|
---|
| 171 | // => there is much occlusion
|
---|
| 172 | mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f));
|
---|
[111] | 173 | mTerrainContentGenerator->SetOffset(0);
|
---|
[110] | 174 |
|
---|
| 175 | // the objects are generated on the whole terrain
|
---|
[112] | 176 | //mTerrainContentGenerator->GenerateScene(1500, "athene");
|
---|
| 177 | mTerrainContentGenerator->GenerateScene(1500, "robot");
|
---|
[107] | 178 | // mTerrainContentGenerator->GenerateScene(500, "ninja");
|
---|
[110] | 179 | }
|
---|
[86] | 180 |
|
---|
[84] | 181 | // no limitations needed anymore: the user can set
|
---|
| 182 | // objects also on peaks of terrain
|
---|
[107] | 183 | mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
|
---|
[61] | 184 | }
|
---|
| 185 | //-----------------------------------------------------------------------
|
---|
[80] | 186 | void TestCullingTerrainApplication::setupGui()
|
---|
[61] | 187 | {
|
---|
[75] | 188 | mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
|
---|
| 189 | false, 3000, ST_EXTERIOR_CLOSE);
|
---|
[61] | 190 | mGUISystem = new CEGUI::System(mGUIRenderer);
|
---|
| 191 |
|
---|
| 192 | // Mouse
|
---|
| 193 | CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
|
---|
| 194 | CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
|
---|
| 195 | mGUISystem->setDefaultMouseCursor(
|
---|
| 196 | (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
|
---|
| 197 |
|
---|
[75] | 198 | CEGUI::MouseCursor::getSingleton().show();
|
---|
[61] | 199 | }
|
---|
| 200 | //-----------------------------------------------------------------------
|
---|
[80] | 201 | void TestCullingTerrainApplication::createFrameListener()
|
---|
[61] | 202 | {
|
---|
[80] | 203 | mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr,
|
---|
[100] | 204 | mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode);
|
---|
[61] | 205 | mFrameListener->showDebugOverlay(true);
|
---|
| 206 | mRoot->addFrameListener(mFrameListener);
|
---|
| 207 | }
|
---|
| 208 | //-----------------------------------------------------------------------
|
---|
[80] | 209 | void TestCullingTerrainApplication::chooseSceneManager()
|
---|
[61] | 210 | {
|
---|
| 211 | mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
|
---|
| 212 | }
|
---|
| 213 | /***********************************************/
|
---|
[80] | 214 | /* MouseQueryListener implementation */
|
---|
[61] | 215 | /***********************************************/
|
---|
| 216 | //-----------------------------------------------------------------------
|
---|
[75] | 217 | MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam,
|
---|
| 218 | SceneManager *sceneManager,
|
---|
[80] | 219 | CEGUI::Renderer *renderer,
|
---|
[93] | 220 | TerrainContentGenerator *sceneGenerator,
|
---|
[100] | 221 | Camera *vizCamera,
|
---|
| 222 | SceneNode *camNode):
|
---|
[86] | 223 | ExampleFrameListener(win, cam, false, true),
|
---|
| 224 | mGUIRenderer(renderer),
|
---|
| 225 | mShutdownRequested(false),
|
---|
| 226 | mLMouseDown(false),
|
---|
| 227 | mRMouseDown(false),
|
---|
| 228 | mSceneMgr(sceneManager),
|
---|
| 229 | mCurrentObject(NULL),
|
---|
| 230 | mTerrainContentGenerator(sceneGenerator),
|
---|
| 231 | mVisibilityThreshold(0),
|
---|
[87] | 232 | mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
|
---|
[93] | 233 | mShowOctree(false),
|
---|
[99] | 234 | mUseVisibilityCulling(true),
|
---|
[94] | 235 | mUseOptimization(true),
|
---|
[100] | 236 | mVizCamera(vizCamera),
|
---|
| 237 | mShowVisualization(false),
|
---|
[113] | 238 | mNodeVizMode(NODEVIZ_NONE),
|
---|
[100] | 239 | mVizCameraHeight(Real(2500.0)),
|
---|
| 240 | mCamNode(camNode),
|
---|
[104] | 241 | mCullCamera(false),
|
---|
[107] | 242 | mAppState(WALKTHROUGH),
|
---|
| 243 | mCurrentFrame(0),
|
---|
| 244 | mRecord(false),
|
---|
[111] | 245 | mTimeElapsed(0),
|
---|
[112] | 246 | mUseShadows(false),
|
---|
| 247 | mVisualizeCulledNodes(false)
|
---|
[61] | 248 | {
|
---|
[86] | 249 | // Reduce move speed
|
---|
[61] | 250 | mMoveSpeed = 50;
|
---|
| 251 | mRotateSpeed *= 2;
|
---|
| 252 |
|
---|
| 253 | // Register this so that we get mouse events.
|
---|
| 254 | mEventProcessor->addMouseListener(this);
|
---|
| 255 | mEventProcessor->addMouseMotionListener(this);
|
---|
| 256 | mEventProcessor->addKeyListener(this);
|
---|
| 257 |
|
---|
[74] | 258 | mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
|
---|
[75] | 259 |
|
---|
[61] | 260 | // show overlay
|
---|
| 261 | Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay");
|
---|
| 262 |
|
---|
[74] | 263 | mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo");
|
---|
| 264 | mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo");
|
---|
[84] | 265 |
|
---|
[74] | 266 | mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/FrustumCulledNodesInfo");
|
---|
| 267 | mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueryCulledNodesInfo");
|
---|
| 268 | mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TraversedNodesInfo");
|
---|
| 269 | mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo");
|
---|
| 270 | mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
|
---|
[87] | 271 | mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
|
---|
[86] | 272 | mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
|
---|
[87] | 273 | mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
|
---|
| 274 |
|
---|
[61] | 275 | mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
|
---|
| 276 | mThresholdInfo->setCaption(": 0");
|
---|
| 277 | mFrustumCulledNodesInfo->setCaption(": 0");
|
---|
| 278 | mQueryCulledNodesInfo->setCaption(": 0");
|
---|
| 279 | mTraversedNodesInfo->setCaption(": 0");
|
---|
| 280 | mHierarchyNodesInfo->setCaption(": 0");
|
---|
| 281 | mRenderedNodesInfo->setCaption(": 0");
|
---|
[87] | 282 | mObjectsInfo->setCaption(": 0");
|
---|
[86] | 283 | mUseOptimizationInfo->setCaption(": true");
|
---|
[87] | 284 | mQueriesIssuedInfo->setCaption(": 0");
|
---|
[84] | 285 |
|
---|
[85] | 286 | setAlgorithm(mCurrentAlgorithm);
|
---|
| 287 |
|
---|
[93] | 288 | mSceneMgr->setOption("UseOptimization", &mUseOptimization);
|
---|
[99] | 289 | mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling);
|
---|
[93] | 290 | mSceneMgr->setOption("ShowOctree", &mShowOctree);
|
---|
[100] | 291 | mSceneMgr->setOption("CullCamera", &mCullCamera);
|
---|
[103] | 292 | mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
|
---|
[113] | 293 |
|
---|
[103] | 294 | pOver->show();
|
---|
[61] | 295 | }
|
---|
| 296 | //-----------------------------------------------------------------------
|
---|
[100] | 297 | MouseQueryListener::~MouseQueryListener()
|
---|
[61] | 298 | {
|
---|
[74] | 299 | delete mRayQueryExecutor;
|
---|
[61] | 300 | }
|
---|
| 301 | //-----------------------------------------------------------------------
|
---|
[100] | 302 | void MouseQueryListener::mouseMoved(MouseEvent *e)
|
---|
[61] | 303 | {
|
---|
| 304 | // Update CEGUI with the mouse motion
|
---|
[100] | 305 | CEGUI::System::getSingleton().injectMouseMove(e->getRelX() *
|
---|
| 306 | mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
|
---|
[61] | 307 | }
|
---|
| 308 | //-----------------------------------------------------------------------
|
---|
| 309 | void MouseQueryListener::mousePressed(MouseEvent* e)
|
---|
| 310 | {
|
---|
| 311 | // Left mouse button down
|
---|
| 312 | if (e->getButtonID() & InputEvent::BUTTON0_MASK)
|
---|
| 313 | {
|
---|
[76] | 314 | CEGUI::MouseCursor::getSingleton().hide();
|
---|
[61] | 315 |
|
---|
| 316 | // Setup the ray scene query
|
---|
[80] | 317 | Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
|
---|
[74] | 318 |
|
---|
| 319 | Vector3 queryResult;
|
---|
[80] | 320 |
|
---|
| 321 | // Get results, create a node/entity on the position
|
---|
[82] | 322 | mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
|
---|
[111] | 323 | mouseRay.getOrigin(), Vector3(0,0,0), "robot");
|
---|
[80] | 324 |
|
---|
[61] | 325 | mLMouseDown = true;
|
---|
| 326 | }
|
---|
| 327 | // Right mouse button down
|
---|
| 328 | else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
|
---|
| 329 | {
|
---|
[75] | 330 | CEGUI::MouseCursor::getSingleton().hide();
|
---|
[61] | 331 | mRMouseDown = true;
|
---|
[100] | 332 | }
|
---|
[61] | 333 | } // mousePressed
|
---|
[99] | 334 | //-----------------------------------------------------------------------
|
---|
[61] | 335 | void MouseQueryListener::mouseReleased(MouseEvent* e)
|
---|
| 336 | {
|
---|
| 337 | // Left mouse button up
|
---|
| 338 | if (e->getButtonID() & InputEvent::BUTTON0_MASK)
|
---|
| 339 | {
|
---|
[75] | 340 | CEGUI::MouseCursor::getSingleton().show();
|
---|
[61] | 341 | mLMouseDown = false;
|
---|
| 342 | }
|
---|
| 343 | // Right mouse button up
|
---|
| 344 | else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
|
---|
| 345 | {
|
---|
[75] | 346 | CEGUI::MouseCursor::getSingleton().show();
|
---|
[61] | 347 | mRMouseDown = false;
|
---|
| 348 | }
|
---|
| 349 | }
|
---|
| 350 | //-----------------------------------------------------------------------
|
---|
[75] | 351 | void MouseQueryListener::mouseDragged(MouseEvent *e)
|
---|
[61] | 352 | {
|
---|
| 353 | // If we are dragging the left mouse button.
|
---|
[75] | 354 | if (mLMouseDown)
|
---|
[61] | 355 | {
|
---|
[74] | 356 | Vector3 queryResult;
|
---|
| 357 | Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
|
---|
[61] | 358 |
|
---|
[100] | 359 | if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
|
---|
[61] | 360 | {
|
---|
[100] | 361 | if (mCurrentObject)
|
---|
| 362 | {
|
---|
[80] | 363 | mCurrentObject->setPosition(queryResult);
|
---|
[100] | 364 | }
|
---|
[74] | 365 | }
|
---|
[61] | 366 | }
|
---|
| 367 | // If we are dragging the right mouse button.
|
---|
[75] | 368 | if (mRMouseDown)
|
---|
[61] | 369 | {
|
---|
[100] | 370 | //mCamera->yaw(-e->getRelX() * mRotateSpeed);
|
---|
| 371 | //mCamera->pitch(-e->getRelY() * mRotateSpeed);
|
---|
| 372 | mCamNode->yaw(-e->getRelX() * mRotateSpeed);
|
---|
| 373 | mCamNode->pitch(-e->getRelY() * mRotateSpeed);
|
---|
[61] | 374 | }
|
---|
| 375 | }
|
---|
| 376 | //-----------------------------------------------------------------------
|
---|
[105] | 377 | bool MouseQueryListener::frameStarted(const FrameEvent &evt)
|
---|
[104] | 378 | {
|
---|
[107] | 379 | switch (mAppState)
|
---|
[104] | 380 | {
|
---|
[106] | 381 | case REPLAY:
|
---|
[107] | 382 | setCurrentFrameInfo(evt.timeSinceLastFrame);
|
---|
[106] | 383 | break;
|
---|
| 384 | case WALKTHROUGH:
|
---|
[107] | 385 | if (mRecord)
|
---|
| 386 | {
|
---|
| 387 | addFrameInfo(mCamNode, evt.timeSinceLastFrame);
|
---|
| 388 | // print recording message
|
---|
| 389 | mWindow->setDebugText("Recording frame " +
|
---|
| 390 | StringConverter::toString(mFrameInfo.size() - 1));
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[105] | 393 | Clamp2Terrain();
|
---|
[106] | 394 | break;
|
---|
| 395 | default:
|
---|
| 396 | break;
|
---|
[107] | 397 | };
|
---|
[105] | 398 |
|
---|
[100] | 399 | if (mShowVisualization)
|
---|
| 400 | {
|
---|
| 401 | // important for visualization => draw octree bounding boxes
|
---|
| 402 | mSceneMgr->setOption("ShowOctree", &mShowVisualization);
|
---|
[113] | 403 | // also render nodew content?
|
---|
| 404 | //mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz);
|
---|
[100] | 405 |
|
---|
| 406 | // -- setup visualization camera
|
---|
| 407 | mVizCamera->setPosition(0, 0, 0);
|
---|
| 408 | mVizCamera->setOrientation(Quaternion::IDENTITY);
|
---|
| 409 |
|
---|
| 410 | Vector3 camPos = mCamNode->getPosition();
|
---|
| 411 | mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z);
|
---|
| 412 |
|
---|
[107] | 413 | // point down -Z axis
|
---|
[100] | 414 | mVizCamera->pitch(Radian(Degree(270.0)));
|
---|
| 415 |
|
---|
[107] | 416 | // rotation arounnd X axis
|
---|
[100] | 417 | mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x,
|
---|
| 418 | -mCamera->getDerivedDirection().z));
|
---|
[104] | 419 |
|
---|
[107] | 420 | // move by a constant so view plane is on bottom of viewport
|
---|
[104] | 421 | mVizCamera->moveRelative(Vector3(0, 800, 0));
|
---|
[100] | 422 | }
|
---|
| 423 |
|
---|
[94] | 424 | return ExampleFrameListener::frameStarted(evt);
|
---|
| 425 | }
|
---|
[100] | 426 | //-----------------------------------------------------------------------
|
---|
[104] | 427 | void MouseQueryListener::Clamp2Terrain()
|
---|
[94] | 428 | {
|
---|
[61] | 429 | // clamp to terrain
|
---|
[100] | 430 | Vector3 camPos = mCamNode->getPosition();
|
---|
[74] | 431 | Vector3 queryResult;
|
---|
[61] | 432 |
|
---|
[100] | 433 | if (mRayQueryExecutor->executeRayQuery(&queryResult,
|
---|
[94] | 434 | Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
|
---|
[93] | 435 | {
|
---|
[100] | 436 | mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z);
|
---|
[93] | 437 | }
|
---|
[61] | 438 | }
|
---|
| 439 | //-----------------------------------------------------------------------
|
---|
| 440 | bool MouseQueryListener::frameEnded(const FrameEvent& evt)
|
---|
| 441 | {
|
---|
| 442 | if (mShutdownRequested)
|
---|
| 443 | return false;
|
---|
| 444 |
|
---|
| 445 | if (timeDelay >= 0)
|
---|
| 446 | timeDelay -= evt.timeSinceLastFrame;
|
---|
| 447 |
|
---|
[107] | 448 | KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
|
---|
[61] | 449 |
|
---|
[86] | 450 | KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
|
---|
[103] | 451 | KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
|
---|
[99] | 452 | KEY_PRESSED(KC_C, 0.3, toggleUseVisibilityCulling());
|
---|
[103] | 453 | KEY_PRESSED(KC_1, 0.3, toggleShowViz());
|
---|
[113] | 454 | KEY_PRESSED(KC_2, 0.3, nextNodeVizMode());
|
---|
[107] | 455 |
|
---|
[104] | 456 | KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
|
---|
| 457 | KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
|
---|
[107] | 458 |
|
---|
[113] | 459 | KEY_PRESSED(KC_4, 0, zoomVizCamera(50));
|
---|
| 460 | KEY_PRESSED(KC_5, 0, zoomVizCamera(-50));
|
---|
[107] | 461 |
|
---|
| 462 | KEY_PRESSED(KC_F1, 0.3, nextAppState());
|
---|
| 463 | KEY_PRESSED(KC_F2, 0.3, toggleRecord());
|
---|
| 464 | KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_outfile));
|
---|
[111] | 465 | KEY_PRESSED(KC_F4, 0.3, toggleUseShadows());
|
---|
[107] | 466 | //KEY_PRESSED(KC_F3, 0.3, writeFrames());
|
---|
| 467 | //KEY_PRESSED(KC_F4, 0.3, loadFrames());
|
---|
| 468 |
|
---|
[87] | 469 | updateStats();
|
---|
[61] | 470 |
|
---|
[107] | 471 | //return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
|
---|
| 472 | return ExampleFrameListener::frameEnded(evt);
|
---|
[61] | 473 | }
|
---|
[107] | 474 | //-----------------------------------------------------------------------
|
---|
[100] | 475 | void MouseQueryListener::moveCamera()
|
---|
| 476 | {
|
---|
| 477 | mCamNode->yaw(mRotX);
|
---|
| 478 | mCamNode->pitch(mRotY);
|
---|
| 479 | mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector);
|
---|
| 480 | }
|
---|
[61] | 481 | //-----------------------------------------------------------------------
|
---|
[107] | 482 | void MouseQueryListener::writeFrames()
|
---|
| 483 | {
|
---|
| 484 | std::ofstream ofstr(frame_outfile);
|
---|
| 485 |
|
---|
| 486 | std::vector<frame_info>::const_iterator it, it_end;
|
---|
| 487 |
|
---|
| 488 | it_end = mFrameInfo.end();
|
---|
| 489 | for(it = mFrameInfo.begin(); it < it_end; ++it)
|
---|
| 490 | {
|
---|
| 491 | ofstr << StringConverter::toString((*it).position) << " "
|
---|
| 492 | << StringConverter::toString((*it).orientation) << " "
|
---|
| 493 | << StringConverter::toString((*it).timeElapsed) << "\n";
|
---|
| 494 | }
|
---|
| 495 | ofstr.close();
|
---|
| 496 | }
|
---|
| 497 | //-----------------------------------------------------------------------
|
---|
| 498 | void MouseQueryListener::loadFrames()
|
---|
| 499 | {
|
---|
| 500 | std::ifstream ifstr(frame_outfile);
|
---|
| 501 | char line[256];
|
---|
| 502 | frame_info info;
|
---|
| 503 |
|
---|
| 504 | // reset current values
|
---|
| 505 | mFrameInfo.clear();
|
---|
| 506 | mCurrentFrame = 0;
|
---|
| 507 |
|
---|
| 508 | while (!ifstr.eof())
|
---|
| 509 | {
|
---|
| 510 | ifstr.getline(line, 256);
|
---|
| 511 | sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z,
|
---|
| 512 | &info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
|
---|
| 513 | &info.timeElapsed);
|
---|
| 514 |
|
---|
| 515 | mFrameInfo.push_back(info);
|
---|
| 516 |
|
---|
| 517 | /*
|
---|
| 518 | std::stringstream d;
|
---|
| 519 | d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation);
|
---|
| 520 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 521 | */
|
---|
| 522 | }
|
---|
| 523 | ifstr.close();
|
---|
| 524 | }
|
---|
| 525 | //-----------------------------------------------------------------------
|
---|
| 526 | void MouseQueryListener::setAppState(int state)
|
---|
| 527 | {
|
---|
| 528 | mAppState = state;
|
---|
| 529 | }
|
---|
| 530 | //-----------------------------------------------------------------------
|
---|
| 531 | void MouseQueryListener::nextAppState()
|
---|
| 532 | {
|
---|
| 533 | mCurrentFrame = 0;
|
---|
| 534 |
|
---|
| 535 | // if last state was replay state
|
---|
| 536 | if (mAppState == REPLAY)
|
---|
| 537 | {
|
---|
| 538 | // reset debug text and write frame info to file
|
---|
| 539 | mWindow->setDebugText("");
|
---|
| 540 | writeFrames();
|
---|
| 541 |
|
---|
| 542 | //-- write out stats
|
---|
| 543 | std::stringstream d;
|
---|
| 544 | d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
|
---|
| 545 | << "avg. FPS: " << mWindow->getAverageFPS() << "\n"
|
---|
| 546 | << "best FPS: " << mWindow->getBestFPS() << "\n"
|
---|
| 547 | << "worst FPS: " << mWindow->getWorstFPS() << "\n"
|
---|
| 548 | << "best frame time: " << mWindow->getBestFrameTime() << "\n"
|
---|
| 549 | << "worst frame time: " << mWindow->getWorstFrameTime();
|
---|
| 550 |
|
---|
| 551 | LogManager::getSingleton().logMessage(d.str());
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 | //-- set the next státe
|
---|
| 555 | mAppState = (mAppState + 1) % STATE_NUM;
|
---|
| 556 |
|
---|
| 557 | // replay recorded walkthrough
|
---|
| 558 | if (mAppState == REPLAY)
|
---|
| 559 | {
|
---|
| 560 | // no recording during replay
|
---|
| 561 | mRecord = false;
|
---|
| 562 |
|
---|
| 563 | // load recorded walkthrough
|
---|
| 564 | if (mFrameInfo.size() == 0)
|
---|
| 565 | {
|
---|
| 566 | loadFrames();
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | // if there are no recorded frames => set next state
|
---|
| 570 | if (mFrameInfo.size() == 0)
|
---|
| 571 | {
|
---|
| 572 | nextAppState();
|
---|
| 573 | }
|
---|
| 574 | else
|
---|
| 575 | {
|
---|
| 576 | mWindow->setDebugText("Replay");
|
---|
| 577 |
|
---|
| 578 | // reset, because we measure fps stats during walkthrough
|
---|
| 579 | mWindow->resetStatistics();
|
---|
| 580 |
|
---|
| 581 | //-- initialise frame data
|
---|
| 582 | mTimeElapsed = 0;
|
---|
| 583 |
|
---|
| 584 | mCamNode->setPosition(mFrameInfo[0].position);
|
---|
| 585 | mCamNode->setOrientation(mFrameInfo[0].orientation);
|
---|
| 586 | }
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | }
|
---|
| 590 | //-----------------------------------------------------------------------
|
---|
| 591 | void MouseQueryListener::toggleRecord()
|
---|
| 592 | {
|
---|
| 593 | mRecord = !mRecord;
|
---|
| 594 |
|
---|
| 595 | // clear previous camera path
|
---|
| 596 | if (mRecord)
|
---|
| 597 | mFrameInfo.clear();
|
---|
| 598 | else
|
---|
| 599 | mWindow->setDebugText("");
|
---|
| 600 | }
|
---|
| 601 | //-----------------------------------------------------------------------
|
---|
[61] | 602 | void MouseQueryListener::changeThreshold(int incr)
|
---|
| 603 | {
|
---|
[85] | 604 | mVisibilityThreshold += incr;
|
---|
| 605 | if(mVisibilityThreshold < 0) mVisibilityThreshold = 0;
|
---|
[61] | 606 |
|
---|
[85] | 607 | char str[100]; sprintf(str,": %d", mVisibilityThreshold);
|
---|
[61] | 608 |
|
---|
[85] | 609 | mSceneMgr->setOption("Threshold", &mVisibilityThreshold);
|
---|
[61] | 610 | mThresholdInfo->setCaption(str);
|
---|
| 611 | }
|
---|
| 612 | //-----------------------------------------------------------------------
|
---|
[100] | 613 | bool MouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
|
---|
| 614 | {
|
---|
| 615 | if (mInputDevice->isKeyDown(KC_RIGHT))
|
---|
| 616 | {
|
---|
| 617 | mCamNode->yaw(-mRotScale);
|
---|
| 618 | return true;
|
---|
| 619 | }
|
---|
| 620 | if (mInputDevice->isKeyDown(KC_LEFT))
|
---|
| 621 | {
|
---|
| 622 | mCamNode->yaw(mRotScale);
|
---|
| 623 | return true;
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | return ExampleFrameListener::processUnbufferedKeyInput(evt);
|
---|
| 627 | }
|
---|
| 628 | //-----------------------------------------------------------------------
|
---|
| 629 | void MouseQueryListener::zoomVizCamera(int zoom)
|
---|
| 630 | {
|
---|
| 631 | mVizCameraHeight += zoom;
|
---|
| 632 | if(mVizCameraHeight < 0) mVizCameraHeight = 0;
|
---|
| 633 | }
|
---|
| 634 | //-----------------------------------------------------------------------
|
---|
[85] | 635 | void MouseQueryListener::nextAlgorithm()
|
---|
[61] | 636 | {
|
---|
[107] | 637 | mCurrentAlgorithm = (mCurrentAlgorithm + 1) %
|
---|
[74] | 638 | GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS,
|
---|
[61] | 639 |
|
---|
[85] | 640 | setAlgorithm(mCurrentAlgorithm);
|
---|
| 641 | }
|
---|
| 642 | //-----------------------------------------------------------------------
|
---|
| 643 | void MouseQueryListener::setAlgorithm(int algorithm)
|
---|
| 644 | {
|
---|
[61] | 645 | mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
|
---|
| 646 | mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
|
---|
| 647 | }
|
---|
| 648 | //-----------------------------------------------------------------------
|
---|
[87] | 649 | void MouseQueryListener::updateStats()
|
---|
[61] | 650 | {
|
---|
| 651 | unsigned int opt = 0;
|
---|
| 652 | char str[100];
|
---|
| 653 |
|
---|
| 654 | mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt);
|
---|
| 655 | mFrustumCulledNodesInfo->setCaption(str);
|
---|
| 656 |
|
---|
[87] | 657 | mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt);
|
---|
| 658 | mQueriesIssuedInfo->setCaption(str);
|
---|
| 659 |
|
---|
[61] | 660 | mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt);
|
---|
| 661 | mQueryCulledNodesInfo->setCaption(str);
|
---|
| 662 |
|
---|
| 663 | mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt);
|
---|
| 664 | mTraversedNodesInfo->setCaption(str);
|
---|
| 665 |
|
---|
[74] | 666 | mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt);
|
---|
[61] | 667 | mHierarchyNodesInfo->setCaption(str);
|
---|
| 668 |
|
---|
| 669 | mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt);
|
---|
| 670 | mRenderedNodesInfo->setCaption(str);
|
---|
[84] | 671 |
|
---|
| 672 | sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount());
|
---|
[87] | 673 | mObjectsInfo->setCaption(str);
|
---|
[61] | 674 | }
|
---|
| 675 | //-----------------------------------------------------------------------
|
---|
[86] | 676 | void MouseQueryListener::toggleUseOptimization()
|
---|
| 677 | {
|
---|
| 678 | mUseOptimization = !mUseOptimization;
|
---|
| 679 |
|
---|
| 680 | mSceneMgr->setOption("UseOptimization", &mUseOptimization);
|
---|
| 681 |
|
---|
[100] | 682 | if (mUseOptimization)
|
---|
[86] | 683 | mUseOptimizationInfo->setCaption(": true");
|
---|
| 684 | else
|
---|
| 685 | mUseOptimizationInfo->setCaption(": false");
|
---|
| 686 | }
|
---|
| 687 | //-----------------------------------------------------------------------
|
---|
| 688 | void MouseQueryListener::toggleShowOctree()
|
---|
| 689 | {
|
---|
| 690 | mShowOctree = !mShowOctree;
|
---|
| 691 |
|
---|
| 692 | mSceneMgr->setOption("ShowOctree", &mShowOctree);
|
---|
| 693 | }
|
---|
| 694 | //-----------------------------------------------------------------------
|
---|
[99] | 695 | void MouseQueryListener::toggleUseVisibilityCulling()
|
---|
[87] | 696 | {
|
---|
[99] | 697 | mUseVisibilityCulling = !mUseVisibilityCulling;
|
---|
[87] | 698 |
|
---|
[99] | 699 | mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling);
|
---|
[87] | 700 | }
|
---|
| 701 | //-----------------------------------------------------------------------
|
---|
[99] | 702 | void MouseQueryListener::toggleShowViz()
|
---|
[93] | 703 | {
|
---|
[99] | 704 | mShowVisualization = !mShowVisualization;
|
---|
[112] | 705 | mVisualizeCulledNodes = !mVisualizeCulledNodes;
|
---|
[94] | 706 |
|
---|
[100] | 707 | // create viewport with priority VIZ_VIEWPORT_Z_ORDER:
|
---|
| 708 | // will be rendered over standard viewport
|
---|
| 709 | if (mShowVisualization)
|
---|
[94] | 710 | {
|
---|
[100] | 711 | Viewport *vizvp = mWindow->addViewport(mVizCamera,
|
---|
[103] | 712 | VIZ_VIEWPORT_Z_ORDER, 0.6, 0.6, 0.4, 0.4);
|
---|
[100] | 713 |
|
---|
| 714 | vizvp->setBackgroundColour(ColourValue(0.0, 0.3, 0.2, 1));
|
---|
| 715 |
|
---|
| 716 | vizvp->setOverlaysEnabled(false);
|
---|
| 717 | // Alter the camera aspect ratio to match the viewport
|
---|
| 718 | mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) /
|
---|
| 719 | Real(vizvp->getActualHeight()));
|
---|
[112] | 720 |
|
---|
| 721 | mSceneMgr->setOption("VisualizeCulledNodes", &mVisualizeCulledNodes);
|
---|
[100] | 722 | //vizvp->setClearEveryFrame(false);
|
---|
| 723 |
|
---|
[104] | 724 | // Create a skyplane (for visualization background)
|
---|
| 725 | /*
|
---|
| 726 | Plane plane;
|
---|
| 727 | plane.d = -1000;
|
---|
[100] | 728 | plane.normal = Vector3::UNIT_Y;
|
---|
[104] | 729 | mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false);
|
---|
[103] | 730 | */
|
---|
[104] | 731 |
|
---|
[94] | 732 | }
|
---|
| 733 | else
|
---|
[99] | 734 | {
|
---|
[100] | 735 | mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
|
---|
[112] | 736 | // if octree was enabled for visualization purpose, reset now
|
---|
[100] | 737 | mSceneMgr->setOption("ShowOctree", &mShowOctree);
|
---|
[99] | 738 | }
|
---|
[93] | 739 | }
|
---|
| 740 | //-----------------------------------------------------------------------
|
---|
[111] | 741 | void MouseQueryListener::toggleUseShadows()
|
---|
| 742 | {
|
---|
| 743 | mUseShadows = !mUseShadows;
|
---|
| 744 |
|
---|
| 745 | //mSunLight->setCastShadows(mUseShadows);
|
---|
| 746 |
|
---|
| 747 | if (mUseShadows)
|
---|
| 748 | {
|
---|
| 749 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
| 750 | }
|
---|
| 751 | else
|
---|
| 752 | {
|
---|
| 753 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
| 754 | }
|
---|
| 755 |
|
---|
| 756 | }
|
---|
| 757 | //-----------------------------------------------------------------------
|
---|
[113] | 758 | void MouseQueryListener::nextNodeVizMode()
|
---|
[103] | 759 | {
|
---|
[113] | 760 | mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM;
|
---|
[103] | 761 |
|
---|
[113] | 762 | bool renderNodesForViz =
|
---|
| 763 | (mNodeVizMode == NODEVIZ_RENDER_NODES) ||
|
---|
| 764 | (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
|
---|
| 765 | bool renderNodesContentForViz = mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT;
|
---|
| 766 |
|
---|
| 767 | mSceneMgr->setOption("RenderNodesForViz", &renderNodesForViz);
|
---|
| 768 | mSceneMgr->setOption("RenderNodesContentForViz", &renderNodesContentForViz);
|
---|
[103] | 769 | }
|
---|
| 770 | //-----------------------------------------------------------------------
|
---|
[61] | 771 | void MouseQueryListener::keyPressed(KeyEvent* e)
|
---|
| 772 | {
|
---|
| 773 | if(e->getKey() == KC_ESCAPE)
|
---|
| 774 | {
|
---|
| 775 | mShutdownRequested = true;
|
---|
| 776 | e->consume();
|
---|
| 777 | return;
|
---|
| 778 | }
|
---|
| 779 |
|
---|
| 780 | CEGUI::System::getSingleton().injectKeyDown(e->getKey());
|
---|
| 781 | CEGUI::System::getSingleton().injectChar(e->getKeyChar());
|
---|
| 782 | e->consume();
|
---|
| 783 | }
|
---|
| 784 | //-----------------------------------------------------------------------
|
---|
| 785 | void MouseQueryListener::keyReleased(KeyEvent* e)
|
---|
| 786 | {
|
---|
| 787 | CEGUI::System::getSingleton().injectKeyUp(e->getKey());
|
---|
| 788 | e->consume();
|
---|
| 789 | }
|
---|
| 790 | //-----------------------------------------------------------------------
|
---|
| 791 | void MouseQueryListener::keyClicked(KeyEvent* e)
|
---|
| 792 | {
|
---|
| 793 | // Do nothing
|
---|
| 794 | e->consume();
|
---|
| 795 | }
|
---|
[106] | 796 | //-----------------------------------------------------------------------
|
---|
[107] | 797 | void MouseQueryListener::addFrameInfo(SceneNode *camNode, Real timeElapsed)
|
---|
[106] | 798 | {
|
---|
| 799 | frame_info info;
|
---|
| 800 | info.orientation = mCamNode->getOrientation();
|
---|
| 801 | info.position = mCamNode->getPosition();
|
---|
[107] | 802 | info.timeElapsed = timeElapsed;
|
---|
| 803 |
|
---|
| 804 | mFrameInfo.push_back(info);
|
---|
[106] | 805 | }
|
---|
| 806 | //-----------------------------------------------------------------------
|
---|
[107] | 807 | void MouseQueryListener::setCurrentFrameInfo(Real timeElapsed)
|
---|
[106] | 808 | {
|
---|
[108] | 809 | //-- find current frame relative to elapsed frame time
|
---|
[107] | 810 | mTimeElapsed -= timeElapsed;
|
---|
| 811 |
|
---|
| 812 | while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1))
|
---|
| 813 | {
|
---|
| 814 | mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed;
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | frame_info new_frame = mFrameInfo[mCurrentFrame];
|
---|
| 818 | frame_info old_frame = mFrameInfo[mCurrentFrame - 1];
|
---|
| 819 |
|
---|
| 820 | //-- interpolate frames
|
---|
| 821 | Real factor = 1;
|
---|
| 822 |
|
---|
| 823 | if (old_frame.timeElapsed > 0)
|
---|
| 824 | factor = mTimeElapsed / old_frame.timeElapsed;
|
---|
| 825 |
|
---|
| 826 | Vector3 camPos = old_frame.position + factor * (new_frame.position - old_frame.position);
|
---|
| 827 | Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation,
|
---|
| 828 | new_frame.orientation, true);
|
---|
| 829 |
|
---|
| 830 | mCamNode->setPosition(camPos);
|
---|
| 831 | mCamNode->setOrientation(camOrienation);
|
---|
[108] | 832 |
|
---|
[107] | 833 | // stop replay after a full walkthrough
|
---|
| 834 | if (mCurrentFrame == (int)mFrameInfo.size() - 1)
|
---|
| 835 | {
|
---|
| 836 | nextAppState();
|
---|
| 837 | }
|
---|
[106] | 838 | }
|
---|
| 839 |
|
---|
[99] | 840 | /**************************************************************/
|
---|
| 841 | /* VisualizationRenderTargetListener implementation */
|
---|
| 842 | /**************************************************************/
|
---|
[107] | 843 | //-----------------------------------------------------------------------
|
---|
[99] | 844 | VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
|
---|
| 845 | :RenderTargetListener(), mSceneMgr(sceneMgr)
|
---|
| 846 | {
|
---|
| 847 | }
|
---|
[61] | 848 | //-----------------------------------------------------------------------
|
---|
[99] | 849 | void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
|
---|
| 850 | {
|
---|
[100] | 851 | const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; // visualization viewport
|
---|
| 852 | const bool nShowViz = !showViz;
|
---|
| 853 |
|
---|
[113] | 854 | // ambient light must be full for visualization
|
---|
| 855 | if (showViz)
|
---|
| 856 | {
|
---|
| 857 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
| 858 | }
|
---|
| 859 | else
|
---|
| 860 | {
|
---|
| 861 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
| 862 | }
|
---|
| 863 |
|
---|
[100] | 864 | mSceneMgr->setOption("ShowVisualization", &showViz);
|
---|
| 865 | mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
|
---|
| 866 | //mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
|
---|
[99] | 867 |
|
---|
| 868 | RenderTargetListener::preViewportUpdate(evt);
|
---|
| 869 | }
|
---|
| 870 | //-----------------------------------------------------------------------
|
---|
| 871 | void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
|
---|
| 872 | {
|
---|
| 873 | RenderTargetListener::postRenderTargetUpdate(evt);
|
---|
| 874 | }
|
---|
| 875 | //-----------------------------------------------------------------------
|
---|
[61] | 876 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
| 877 | {
|
---|
| 878 | // Create application object
|
---|
| 879 | TestCullingTerrainApplication app;
|
---|
| 880 |
|
---|
| 881 | try
|
---|
| 882 | {
|
---|
| 883 | app.go();
|
---|
| 884 | }
|
---|
| 885 | catch( Ogre::Exception& e )
|
---|
| 886 | {
|
---|
[75] | 887 | MessageBox( NULL, e.getFullDescription().c_str(),
|
---|
| 888 | "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
[61] | 889 | }
|
---|
| 890 |
|
---|
| 891 | return 0;
|
---|
| 892 | } |
---|