source: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp @ 106

Revision 106, 21.9 KB checked in by mattausch, 19 years ago (diff)
RevLine 
[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
[80]25/*******************************************************/
26/*     TestCullingTerrainApplication implementation    */
27/*******************************************************/
[100]28
29//-----------------------------------------------------------------------
[61]30TestCullingTerrainApplication::~TestCullingTerrainApplication()
31{
[93]32        if(mTerrainContentGenerator)
33                delete mTerrainContentGenerator;
[99]34        //if(mRenderTargetListener)     delete mRenderTargetListener;
[61]35}
36//-----------------------------------------------------------------------
[93]37void TestCullingTerrainApplication::createCamera()
[61]38{
[99]39        // create the camera
[103]40        mCamera = mSceneMgr->createCamera("PlayerCam");
[93]41       
[100]42        /** set a nice viewpoint
43        *       we use a camera node here and apply all transformations on it instead
44        *       of applying all transformations directly to the camera
45        *       because then the camera is displayed correctly in the visualization
46        */
[93]47       
[100]48        mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
49                "CamNode1", Vector3(707, 5000, 528));
50        //mCamera->setPosition(707, 5000, 528);
51        mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
52       
53        mCamNode->attachObject(mCamera);
[61]54
[100]55        //-- create visualization camera
56        mVizCamera = mSceneMgr->createCamera("VizCam");
57        mVizCamera->setPosition(mCamNode->getPosition());
58
59        mVizCamera->setNearClipDistance(1);
[93]60        mCamera->setNearClipDistance(1);
[61]61
[99]62        // infinite far plane?
[93]63        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
64        {
[100]65                mVizCamera->setFarClipDistance(0);
[93]66                mCamera->setFarClipDistance(0);
67        }
68        else
69        {
[104]70                 mVizCamera->setFarClipDistance(20000);
71                 mCamera->setFarClipDistance(20000);
[99]72        }       
[61]73}
[99]74
[61]75//-----------------------------------------------------------------------
[99]76bool TestCullingTerrainApplication::setup()
77{
78        bool result = ExampleApplication::setup();
79
80        createRenderTargetListener();
81
82        return result;
83}
84//-----------------------------------------------------------------------
85void TestCullingTerrainApplication::createRenderTargetListener()
86{
87        mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr));
88}
89//-----------------------------------------------------------------------
[75]90void TestCullingTerrainApplication::createScene()
[61]91{
92        // Set ambient light
93        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
94       
95        // Create a light
96        Light* l = mSceneMgr->createLight("MainLight");
97        // Accept default settings: point light, white diffuse, just set position
98        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
[100]99        // other objects, but I don't
[61]100        l->setPosition(20,80,50);
101
102        // --Fog
103        // NB it's VERY important to set this before calling setWorldGeometry
104        // because the vertex program picked will be different
105        ColourValue fadeColour(0.93, 0.86, 0.76);
106        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
107        //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
[94]108       
[61]109        // Create a skybox
[103]110        mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false);
111       
[61]112        std::string terrain_cfg("terrain.cfg");
113#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
114        terrain_cfg = mResourcePath + terrain_cfg;
115#endif
[74]116        mSceneMgr->setWorldGeometry(terrain_cfg);
[75]117       
[100]118        //-- CEGUI setup
[61]119        setupGui();
[100]120
121        //-- terrain content setup
122
[80]123        // HACK: necessary to call once before the content creation for
124        // terrain initialisation
125        mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true);
[74]126
[82]127        mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
[98]128        mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 5000.0f, 3000.0f));
[103]129
[98]130        mTerrainContentGenerator->GenerateScene(1500, "robot.mesh");
[103]131//      mTerrainContentGenerator->GenerateScene(500, "ninja.mesh");
[86]132
[84]133        // no limitations needed anymore: the user can set
134        // objects also on peaks of terrain
[82]135        mTerrainContentGenerator->SetMaxHeight(5000);
[61]136}
137//-----------------------------------------------------------------------
[80]138void TestCullingTerrainApplication::setupGui()
[61]139{
[75]140         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
141                 false, 3000, ST_EXTERIOR_CLOSE);
[61]142     mGUISystem = new CEGUI::System(mGUIRenderer);
143
144         // Mouse
145     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
146     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
147         mGUISystem->setDefaultMouseCursor(
148                (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
149
[75]150         CEGUI::MouseCursor::getSingleton().show();
[61]151}
152//-----------------------------------------------------------------------
[80]153void TestCullingTerrainApplication::createFrameListener()
[61]154{
[80]155        mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr,
[100]156                mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode);
[61]157        mFrameListener->showDebugOverlay(true);
158        mRoot->addFrameListener(mFrameListener);
159}
160//-----------------------------------------------------------------------
[80]161void TestCullingTerrainApplication::chooseSceneManager()
[61]162{
163        mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
164}
165/***********************************************/
[80]166/*      MouseQueryListener implementation      */
[61]167/***********************************************/
168//-----------------------------------------------------------------------
[75]169MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam,
170                                                                           SceneManager *sceneManager,
[80]171                                                                           CEGUI::Renderer *renderer,
[93]172                                                                           TerrainContentGenerator *sceneGenerator,
[100]173                                                                           Camera *vizCamera,
174                                                                           SceneNode *camNode):
[86]175ExampleFrameListener(win, cam, false, true),
176mGUIRenderer(renderer),
177mShutdownRequested(false),
178mLMouseDown(false),
179mRMouseDown(false),
180mSceneMgr(sceneManager),
181mCurrentObject(NULL),
182mTerrainContentGenerator(sceneGenerator),
183mVisibilityThreshold(0),
[87]184mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
[93]185mShowOctree(false),
[99]186mUseVisibilityCulling(true),
[94]187mUseOptimization(true),
[100]188mVizCamera(vizCamera),
189mShowVisualization(false),
[103]190mRenderNodesForViz(false),
[100]191mVizCameraHeight(Real(2500.0)),
192mCamNode(camNode),
[104]193mCullCamera(false),
[106]194mState(WALKTHROUGH),
195mCurrentFrame(1)
[61]196{
[86]197        // Reduce move speed
[61]198        mMoveSpeed = 50;
199        mRotateSpeed *= 2;
200   
201        // Register this so that we get mouse events.
202        mEventProcessor->addMouseListener(this);
203        mEventProcessor->addMouseMotionListener(this);
204        mEventProcessor->addKeyListener(this);
205
[74]206        mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
[75]207       
[61]208        // show overlay
209        Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay");
210
[74]211        mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo");
212        mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo");
[84]213       
[74]214        mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/FrustumCulledNodesInfo");
215        mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueryCulledNodesInfo");
216    mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TraversedNodesInfo");
217        mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo");
218        mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
[87]219        mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
[86]220        mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
[87]221        mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
222       
[61]223        mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
224        mThresholdInfo->setCaption(": 0");
225        mFrustumCulledNodesInfo->setCaption(": 0");
226        mQueryCulledNodesInfo->setCaption(": 0");
227        mTraversedNodesInfo->setCaption(": 0");
228        mHierarchyNodesInfo->setCaption(": 0");
229        mRenderedNodesInfo->setCaption(": 0");
[87]230        mObjectsInfo->setCaption(": 0");
[86]231        mUseOptimizationInfo->setCaption(": true");
[87]232        mQueriesIssuedInfo->setCaption(": 0");
[84]233
[85]234        setAlgorithm(mCurrentAlgorithm);
235
[93]236        mSceneMgr->setOption("UseOptimization", &mUseOptimization);
[99]237        mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling);
[93]238        mSceneMgr->setOption("ShowOctree", &mShowOctree);
[100]239        mSceneMgr->setOption("CullCamera", &mCullCamera);
[103]240        mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
241        mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz);
242
243        pOver->show();
[61]244}
245//-----------------------------------------------------------------------
[100]246MouseQueryListener::~MouseQueryListener()
[61]247{
[74]248        delete mRayQueryExecutor;
[61]249}
250//-----------------------------------------------------------------------
[100]251void MouseQueryListener::mouseMoved(MouseEvent *e)
[61]252{
253        // Update CEGUI with the mouse motion
[100]254    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() *
255                mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
[61]256}
257//-----------------------------------------------------------------------
258void MouseQueryListener::mousePressed(MouseEvent* e)
259{
260     // Left mouse button down
261     if (e->getButtonID() & InputEvent::BUTTON0_MASK)
262     {
[76]263                 CEGUI::MouseCursor::getSingleton().hide();
[61]264
265                 // Setup the ray scene query
[80]266         Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
[74]267   
268                 Vector3 queryResult;
[80]269                 
270                 // Get results, create a node/entity on the position
[82]271                 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
[80]272                         mouseRay.getOrigin(), mouseRay.getDirection(), "robot.mesh");
273               
[61]274         mLMouseDown = true;
275     }
276     // Right mouse button down
277     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
278     {
[75]279         CEGUI::MouseCursor::getSingleton().hide();
[61]280         mRMouseDown = true;
[100]281     }
[61]282} // mousePressed
[99]283//-----------------------------------------------------------------------
[61]284void MouseQueryListener::mouseReleased(MouseEvent* e)
285{
286    // Left mouse button up
287    if (e->getButtonID() & InputEvent::BUTTON0_MASK)
288    {
[75]289                CEGUI::MouseCursor::getSingleton().show();
[61]290        mLMouseDown = false;
291    }
292    // Right mouse button up
293    else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
294    {
[75]295        CEGUI::MouseCursor::getSingleton().show();
[61]296        mRMouseDown = false;
297    }
298}
299//-----------------------------------------------------------------------
[75]300void MouseQueryListener::mouseDragged(MouseEvent *e)
[61]301 {
302         // If we are dragging the left mouse button.           
[75]303         if (mLMouseDown)
[61]304     {
[74]305                 Vector3 queryResult;
306                 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
[61]307
[100]308                 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay))
[61]309                 {
[100]310                         if (mCurrentObject)
311                         {
[80]312                                 mCurrentObject->setPosition(queryResult);
[100]313                         }
[74]314                 }
[61]315     }
316         // If we are dragging the right mouse button.
[75]317         if (mRMouseDown)
[61]318         {
[100]319                 //mCamera->yaw(-e->getRelX() * mRotateSpeed);
320                 //mCamera->pitch(-e->getRelY() * mRotateSpeed);
321                 mCamNode->yaw(-e->getRelX() * mRotateSpeed);
322                 mCamNode->pitch(-e->getRelY() * mRotateSpeed);
[61]323         }
324}
325//-----------------------------------------------------------------------
[105]326bool MouseQueryListener::frameStarted(const FrameEvent &evt)
[104]327{
[105]328        switch (mState)
[104]329        {
[106]330        case REPLAY:
331                SetCurrentCameraPath(mCamNode);
332                mCamNode->setPosition(mCameraPath[mCurrentFrame].position);
333                mCamNode->setOrientation(mCameraPath[mCurrentFrame].orientation);
334                (mCurrentFrame++) % mCameraPath.size();
335                break;
336        case WALKTHROUGH:
[105]337                Clamp2Terrain();
[104]338
[106]339        case RECORD:
340                AddCameraPath(mCamNode);
341                break;
342        default:
343                break;
344        };
[105]345       
[100]346        if (mShowVisualization)
347        {
348                // important for visualization => draw octree bounding boxes
349                mSceneMgr->setOption("ShowOctree", &mShowVisualization);
[103]350                // also render geometry?
351                mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz);
[100]352
353                // -- setup visualization camera
354                mVizCamera->setPosition(0, 0, 0);
355                mVizCamera->setOrientation(Quaternion::IDENTITY);
356
357                Vector3 camPos = mCamNode->getPosition();
358                mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z);
359
360                // Point down -Z axis
361                mVizCamera->pitch(Radian(Degree(270.0)));
362       
363                // Rotation arounnd X axis
364                mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x,
365                        -mCamera->getDerivedDirection().z));
[104]366               
367                mVizCamera->moveRelative(Vector3(0, 800, 0));
[100]368        }
369
[94]370        return ExampleFrameListener::frameStarted(evt);
371}
[100]372//-----------------------------------------------------------------------
[104]373void MouseQueryListener::Clamp2Terrain()
[94]374{
[61]375        // clamp to terrain
[100]376        Vector3 camPos = mCamNode->getPosition();
[74]377        Vector3 queryResult;
[61]378
[100]379        if (mRayQueryExecutor->executeRayQuery(&queryResult,
[94]380                        Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y))
[93]381        {
[100]382                mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z);
[93]383        }
[61]384}
385//-----------------------------------------------------------------------
386bool MouseQueryListener::frameEnded(const FrameEvent& evt)
387{
388        if (mShutdownRequested)
389                return false;
390
391    if (timeDelay >= 0)
392        timeDelay -= evt.timeSinceLastFrame;
393
[85]394    KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
[61]395
[86]396        KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
[103]397        KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
[99]398        KEY_PRESSED(KC_C, 0.3, toggleUseVisibilityCulling());
[103]399        KEY_PRESSED(KC_1, 0.3, toggleShowViz());
400        KEY_PRESSED(KC_2, 0.3, toggleRenderNodesForViz());
[104]401        KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
402        KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
403        KEY_PRESSED(KC_3, 0, zoomVizCamera(50));
404        KEY_PRESSED(KC_4, 0, zoomVizCamera(-50));
[106]405        KEY_PRESSED(KC_F1, 0, setState(RECORD));
406        KEY_PRESSED(KC_F2, 0, setState(REPLAY));
407        KEY_PRESSED(KC_F3, 0, setState(WALKTHROUGH));
[87]408        updateStats();
[61]409
[100]410        return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
[61]411}
[100]412void MouseQueryListener::moveCamera()
413{
414        mCamNode->yaw(mRotX);
415        mCamNode->pitch(mRotY);
416        mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector);
417}
[61]418//-----------------------------------------------------------------------
419void MouseQueryListener::changeThreshold(int incr)
420{
[85]421        mVisibilityThreshold += incr;
422        if(mVisibilityThreshold < 0) mVisibilityThreshold = 0;
[61]423       
[85]424        char str[100]; sprintf(str,": %d", mVisibilityThreshold);
[61]425
[85]426        mSceneMgr->setOption("Threshold", &mVisibilityThreshold);
[61]427        mThresholdInfo->setCaption(str);
428}
429//-----------------------------------------------------------------------
[100]430bool MouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
431{   
432        if (mInputDevice->isKeyDown(KC_RIGHT))
433        {
434                mCamNode->yaw(-mRotScale);
435                return true;
436        }
437        if (mInputDevice->isKeyDown(KC_LEFT))
438        {
439                mCamNode->yaw(mRotScale);
440                return true;
441        }
442
443        return ExampleFrameListener::processUnbufferedKeyInput(evt);
444}
445//-----------------------------------------------------------------------
446void MouseQueryListener::zoomVizCamera(int zoom)
447{
448        mVizCameraHeight += zoom;
449        if(mVizCameraHeight < 0) mVizCameraHeight = 0;
450}
451//-----------------------------------------------------------------------
[85]452void MouseQueryListener::nextAlgorithm()
[61]453{
[74]454        mCurrentAlgorithm = ++mCurrentAlgorithm %
455                GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS,
[61]456
[85]457        setAlgorithm(mCurrentAlgorithm);
458}
459//-----------------------------------------------------------------------
460void MouseQueryListener::setAlgorithm(int algorithm)
461{
[61]462        mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
463        mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
464}
465//-----------------------------------------------------------------------
[87]466void MouseQueryListener::updateStats()
[61]467{
468        unsigned int opt = 0;
469        char str[100];
470       
471        mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt);
472        mFrustumCulledNodesInfo->setCaption(str);
473       
[87]474        mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt);
475        mQueriesIssuedInfo->setCaption(str);
476       
[61]477        mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt);
478        mQueryCulledNodesInfo->setCaption(str);
479       
480        mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt);
481        mTraversedNodesInfo->setCaption(str);
482
[74]483        mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt);
[61]484        mHierarchyNodesInfo->setCaption(str);
485
486        mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt);
487        mRenderedNodesInfo->setCaption(str);
[84]488
489        sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount());
[87]490        mObjectsInfo->setCaption(str);
[61]491}
492//-----------------------------------------------------------------------
[86]493void MouseQueryListener::toggleUseOptimization()
494{
495        mUseOptimization = !mUseOptimization;
496
497        mSceneMgr->setOption("UseOptimization", &mUseOptimization);
498
[100]499        if (mUseOptimization)
[86]500                mUseOptimizationInfo->setCaption(": true");
501        else
502                mUseOptimizationInfo->setCaption(": false");
503}
504//-----------------------------------------------------------------------
505void MouseQueryListener::toggleShowOctree()
506{
507        mShowOctree = !mShowOctree;
508
509        mSceneMgr->setOption("ShowOctree", &mShowOctree);
510}
511//-----------------------------------------------------------------------
[99]512void MouseQueryListener::toggleUseVisibilityCulling()
[87]513{
[99]514        mUseVisibilityCulling = !mUseVisibilityCulling;
[87]515
[99]516        mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling);
[87]517}
518//-----------------------------------------------------------------------
[99]519void MouseQueryListener::toggleShowViz()
[93]520{
[99]521        mShowVisualization = !mShowVisualization;
[94]522
[100]523        // create viewport with priority VIZ_VIEWPORT_Z_ORDER:
524        // will be rendered over standard viewport
525        if (mShowVisualization)
[94]526        {       
[100]527                Viewport *vizvp = mWindow->addViewport(mVizCamera,
[103]528                        VIZ_VIEWPORT_Z_ORDER, 0.6, 0.6, 0.4, 0.4);
[100]529                               
530                vizvp->setBackgroundColour(ColourValue(0.0, 0.3, 0.2, 1));
531
532                vizvp->setOverlaysEnabled(false);
533                // Alter the camera aspect ratio to match the viewport
534        mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) /
535                        Real(vizvp->getActualHeight()));
536                //vizvp->setClearEveryFrame(false);
537
[104]538                // Create a skyplane (for visualization background)
539                /*
540                Plane plane;
541                plane.d = -1000;
[100]542                plane.normal = Vector3::UNIT_Y;
[104]543                mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false);
[103]544                */
[104]545               
[94]546        }
547        else
[99]548        {
[100]549                mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
550                // if octree was enabled for visualization purpose
551                mSceneMgr->setOption("ShowOctree", &mShowOctree);
[99]552        }
[93]553}
554//-----------------------------------------------------------------------
[103]555void MouseQueryListener::toggleRenderNodesForViz()
556{
557        mRenderNodesForViz = !mRenderNodesForViz;
558
559        mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz);
560}
561//-----------------------------------------------------------------------
[61]562void MouseQueryListener::keyPressed(KeyEvent* e)
563{
564        if(e->getKey() == KC_ESCAPE)
565    {
566                mShutdownRequested = true;
567                e->consume();
568                return;
569        }
570
571        CEGUI::System::getSingleton().injectKeyDown(e->getKey());
572        CEGUI::System::getSingleton().injectChar(e->getKeyChar());
573        e->consume();
574}
575//-----------------------------------------------------------------------
576void MouseQueryListener::keyReleased(KeyEvent* e)
577{
578        CEGUI::System::getSingleton().injectKeyUp(e->getKey());
579        e->consume();
580}
581//-----------------------------------------------------------------------
582void MouseQueryListener::keyClicked(KeyEvent* e)
583{
584        // Do nothing
585        e->consume();
586}
[106]587//-----------------------------------------------------------------------
588void MouseQueryListener::AddCameraPath(SceneNode *camNode)
589{
590        frame_info info;
591        info.orientation = mCamNode->getOrientation();
592        info.position = mCamNode->getPosition();
593        mCameraPath.push_back(info);
594}
595//-----------------------------------------------------------------------
596void MouseQueryListener::SetCurrentCameraPath(SceneNode *camNode)
597{
598        mCamNode->setPosition(mCameraPath[mCurrentFrame].position);
599        mCamNode->setOrientation(mCameraPath[mCurrentFrame].orientation);
600        (mCurrentFrame++) % mCameraPath.size();
601}
602
[99]603/**************************************************************/
604/*      VisualizationRenderTargetListener implementation      */
605/**************************************************************/
[106]606
[99]607VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
608:RenderTargetListener(), mSceneMgr(sceneMgr)
609{
610}
[61]611//-----------------------------------------------------------------------
[99]612void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
613{
[100]614        const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; // visualization viewport
615        const bool nShowViz = !showViz;
616
617    mSceneMgr->setOption("ShowVisualization", &showViz);
618        mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
619        //mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
[99]620       
621        RenderTargetListener::preViewportUpdate(evt);
622}
623//-----------------------------------------------------------------------
624void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
625{
626        RenderTargetListener::postRenderTargetUpdate(evt);
627}
628//-----------------------------------------------------------------------
[61]629INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
630{
631    // Create application object
632    TestCullingTerrainApplication app;
633
634        try
635        {
636        app.go();
637    }
638        catch( Ogre::Exception& e )
639        {
[75]640        MessageBox( NULL, e.getFullDescription().c_str(),
641                        "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
[61]642    }   
643
644    return 0;
645}
Note: See TracBrowser for help on using the repository browser.