source: trunk/VUT/OcclusionCullingSceneManager/TestCullingDotScene/TestCullingDotSceneApplication.cpp @ 36

Revision 36, 21.3 KB checked in by mattausch, 20 years ago (diff)
RevLine 
[36]1/**
2    \file
3        TestCullingApplication.cpp
4    \brief
5        Tests the occlusion culling algorithm
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
15#include "Ogre.h"
16#include "TestCullingApplication.h"
17#include "OgreOcclusionCullingSceneTraverser.h"
18
19#define WIN32_LEAN_AND_MEAN
20#include "windows.h"
21
22RaySceneQuery* raySceneQuery = 0;
23
24/***********************************************/
25/* TestCullingApplication implementation       */
26/***********************************************/
27TestCullingApplication::~TestCullingApplication()
28{
29        delete raySceneQuery;
30}
31
32void TestCullingApplication::parseDotScene( const String &SceneName, const String& groupName )
33{
34        TiXmlDocument   *XMLDoc;
35        TiXmlElement    *XMLRoot, *XMLNodes, *XMLPathFind;
36        try
37        {
38                DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource( SceneName, groupName );
39
40                String data = pStream->getAsString();
41
42                // Open the .scene File
43                XMLDoc = new TiXmlDocument();
44                XMLDoc->Parse( data.c_str() );
45                pStream->close();
46                pStream.setNull();
47
48                if( XMLDoc->Error() )
49                {
50                        //We'll just log, and continue on gracefully
51                        LogManager::getSingleton().logMessage("Error in dotscene demo app!!!!!");
52                        delete XMLDoc;
53                        return;
54                }
55        }
56        catch(...)
57        {
58                //We'll just log, and continue on gracefully
59                LogManager::getSingleton().logMessage("Error in dotscene demo app!!!!!");
60                delete XMLDoc;
61                return;
62        }
63
64        // Validate the File
65        XMLRoot = XMLDoc->RootElement();
66        if( String( XMLRoot->Value()) != "scene"  ) {
67                LogManager::getSingleton().logMessage( "Error: Invalid .scene File. Missing <scene>" );
68                delete XMLDoc;         
69                return;
70        }
71               
72        XMLNodes = XMLRoot->FirstChildElement( "nodes" );
73       
74        // Read in the scene nodes
75        if( XMLNodes )
76        {
77                TiXmlElement *XMLNode, *XMLPosition, *XMLRotation, *XMLScale,  *XMLEntity, *XMLBillboardSet,  *XMLLight;
78
79                XMLNode = XMLNodes->FirstChildElement( "node" );
80               
81                while( XMLNode )
82                {
83                        // Process the current node
84                        // Grab the name of the node
85                        String NodeName = XMLNode->Attribute("name");
86                        // First create the new scene node
87                        SceneNode* NewNode = static_cast<SceneNode*>( mSceneMgr->getRootSceneNode()->createChild( NodeName ) );
88
89                        Vector3 TempVec;
90                        String TempValue;
91                               
92                        // Now position it...
93                        XMLPosition = XMLNode->FirstChildElement("position");
94                       
95                        if( XMLPosition )
96                        {
97                                TempValue = XMLPosition->Attribute("x");
98                                TempVec.x = StringConverter::parseReal(TempValue);
99                                TempValue = XMLPosition->Attribute("y");
100                                TempVec.y = StringConverter::parseReal(TempValue);
101                                TempValue = XMLPosition->Attribute("z");
102                                TempVec.z = StringConverter::parseReal(TempValue);
103                                NewNode->setPosition( TempVec );
104                        }
105
106                        // Rotate it...
107                        XMLRotation = XMLNode->FirstChildElement("rotation");
108                        if( XMLRotation )
109                        {
110                                Quaternion TempQuat;
111                                TempValue = XMLRotation->Attribute("qx");
112                                TempQuat.x = StringConverter::parseReal(TempValue);
113                                TempValue = XMLRotation->Attribute("qy");
114                                TempQuat.y = StringConverter::parseReal(TempValue);
115                                TempValue = XMLRotation->Attribute("qz");
116                                TempQuat.z = StringConverter::parseReal(TempValue);
117                                TempValue = XMLRotation->Attribute("qw");
118                                TempQuat.w = StringConverter::parseReal(TempValue);
119                                NewNode->setOrientation( TempQuat );
120                        }
121
122                        // Scale it.
123                        XMLScale = XMLNode->FirstChildElement("scale");
124                       
125                        if( XMLScale )
126                        {
127                                TempValue = XMLScale->Attribute("x");
128                                TempVec.x = StringConverter::parseReal(TempValue);
129                                TempValue = XMLScale->Attribute("y");
130                                TempVec.y = StringConverter::parseReal(TempValue);
131                                TempValue = XMLScale->Attribute("z");
132                                TempVec.z = StringConverter::parseReal(TempValue);
133                                NewNode->setScale( TempVec );
134                        }
135
136                        XMLLight = XMLNode->FirstChildElement( "light" );
137                       
138                        if( XMLLight )
139                                NewNode->attachObject( LoadLight( XMLLight ) );
140
141                        // Check for an Entity
142                        XMLEntity = XMLNode->FirstChildElement("entity");
143                       
144                        if( XMLEntity )
145                        {
146                                if( XMLEntity->Attribute("static") )
147                                {
148                                        if( strcmp( XMLEntity->Attribute("static"), "false" )==0 ){
149                                                String EntityName, EntityMeshFilename;
150                                                EntityName = XMLEntity->Attribute( "name" );
151                                                EntityMeshFilename = XMLEntity->Attribute( "meshFile" );
152
153                                                // Create entity
154                                                Entity* NewEntity = mSceneMgr->createEntity(EntityName, EntityMeshFilename);
155                                                NewNode->attachObject( NewEntity );
156                                        }
157                                }
158                        }
159
160                        XMLBillboardSet = XMLNode->FirstChildElement( "billboardSet" );
161                        if( XMLBillboardSet )
162                        {
163                                String TempValue;
164
165                                BillboardSet* bSet = mSceneMgr->createBillboardSet( NewNode->getName() );
166
167                                BillboardType Type;
168                                TempValue = XMLBillboardSet->Attribute( "type" );
169                                if( TempValue == "orientedCommon" )
170                                        Type = BBT_ORIENTED_COMMON;
171                                else if( TempValue == "orientedSelf" )
172                                        Type = BBT_ORIENTED_SELF;
173                                else Type = BBT_POINT;
174
175                                BillboardOrigin Origin;
176                                TempValue = XMLBillboardSet->Attribute( "type" );
177                                if( TempValue == "bottom_left" )
178                                        Origin = BBO_BOTTOM_LEFT;
179                                else if( TempValue == "bottom_center" )
180                                        Origin = BBO_BOTTOM_CENTER;
181                                else if( TempValue == "bottomRight"  )
182                                        Origin = BBO_BOTTOM_RIGHT;
183                                else if( TempValue == "left" )
184                                        Origin = BBO_CENTER_LEFT;
185                                else if( TempValue == "right" )
186                                        Origin = BBO_CENTER_RIGHT;
187                                else if( TempValue == "topLeft" )
188                                        Origin = BBO_TOP_LEFT;
189                                else if( TempValue == "topCenter" )
190                                        Origin = BBO_TOP_CENTER;
191                                else if( TempValue == "topRight" )
192                                        Origin = BBO_TOP_RIGHT;
193                                else
194                                        Origin = BBO_CENTER;
195
196                                bSet->setBillboardType( Type );
197                                bSet->setBillboardOrigin( Origin );
198
199                                TempValue = XMLBillboardSet->Attribute( "name" );
200                                bSet->setMaterialName( TempValue );
201
202                                int width, height;
203                                width = StringConverter::parseReal( XMLBillboardSet->Attribute( "width" ) );
204                                height = StringConverter::parseReal( XMLBillboardSet->Attribute( "height" ) );
205                                bSet->setDefaultDimensions( width, height );
206                                bSet->setVisible( true );
207                                NewNode->attachObject( bSet );
208
209                                TiXmlElement *XMLBillboard;
210
211                                XMLBillboard = XMLBillboardSet->FirstChildElement( "billboard" );
212
213                                while( XMLBillboard )
214                                {
215                                        Billboard *b;
216                                        TempValue;
217                                        TempVec = Vector3( 0, 0, 0 );
218                                        ColourValue TempColour(1,1,1,1);
219
220                                        XMLPosition = XMLBillboard->FirstChildElement( "position" );
221                                        if( XMLPosition ){
222                                                TempValue = XMLPosition->Attribute("x");
223                                                TempVec.x = StringConverter::parseReal(TempValue);
224                                                TempValue = XMLPosition->Attribute("y");
225                                                TempVec.y = StringConverter::parseReal(TempValue);
226                                                TempValue = XMLPosition->Attribute("z");
227                                                TempVec.z = StringConverter::parseReal(TempValue);
228                                        }
229
230                                        TiXmlElement* XMLColour = XMLBillboard->FirstChildElement( "colourDiffuse" );
231                                        if( XMLColour )
232                                        {
233                                                TempValue = XMLColour->Attribute("r");
234                                                TempColour.r = StringConverter::parseReal(TempValue);
235                                                TempValue = XMLColour->Attribute("g");
236                                                TempColour.g = StringConverter::parseReal(TempValue);
237                                                TempValue = XMLColour->Attribute("b");
238                                                TempColour.b = StringConverter::parseReal(TempValue);
239                                        }
240
241                                        b = bSet->createBillboard( TempVec, TempColour);
242
243                                        XMLBillboard = XMLBillboard->NextSiblingElement( "billboard" );
244                                }
245                        }
246
247                        // Move to the next node
248                        XMLNode = XMLNode->NextSiblingElement( "node" );
249                }
250        }
251
252        // Close the XML File
253        delete XMLDoc;
254}
255
256Light* LoadLight( TiXmlElement *XMLLight )
257{
258        TiXmlElement *XMLDiffuse, *XMLSpecular, *XMLAttentuation, *XMLPosition;
259
260        // Create a light (point | directional | spot | radPoint)
261        Light* l = mSceneMgr->createLight( XMLLight->Attribute("name") );
262        if( !XMLLight->Attribute("type") || String(XMLLight->Attribute("type")) == "point" )
263                l->setType( Light::LT_POINT );
264        else if( String(XMLLight->Attribute("type")) == "directional")
265                l->setType( Light::LT_DIRECTIONAL );
266        else if( String(XMLLight->Attribute("type")) == "spot")
267                l->setType( Light::LT_SPOTLIGHT );
268        else if( String(XMLLight->Attribute("type")) == "radPoint")
269                l->setType( Light::LT_POINT );
270
271        XMLDiffuse = XMLLight->FirstChildElement("colourDiffuse");
272        if( XMLDiffuse )
273        {
274                ColourValue Diffuse;
275                Diffuse.r = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("r") );
276                Diffuse.g = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("g") );
277                Diffuse.b = Ogre::StringConverter::parseReal( XMLDiffuse->Attribute("b") );
278                Diffuse.a = 1;
279                l->setDiffuseColour(Diffuse);
280        }
281       
282        XMLSpecular = XMLLight->FirstChildElement("colourSpecular");
283       
284        if( XMLSpecular )
285        {
286                ColourValue Specular;
287                Specular.r = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("r") );
288                Specular.g = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("g") );
289                Specular.b = Ogre::StringConverter::parseReal( XMLSpecular->Attribute("b") );
290                Specular.a = 1;
291                l->setSpecularColour(Specular);
292        }
293
294        XMLAttentuation = XMLLight->FirstChildElement("lightAttenuation");
295        if( XMLAttentuation )
296        {
297                //get defaults incase not all values specified
298                Real range, constant, linear, quadratic;
299                range = l->getAttenuationRange();
300                constant = l->getAttenuationConstant();
301                linear = l->getAttenuationLinear();
302                quadratic = l->getAttenuationQuadric();
303                       
304                if( XMLAttentuation->Attribute("range") )
305                        range = StringConverter::parseReal( XMLAttentuation->Attribute("range") );
306                if( XMLAttentuation->Attribute("constant") )
307                        constant = StringConverter::parseReal( XMLAttentuation->Attribute("constant") );
308                if( XMLAttentuation->Attribute("linear") )
309                        linear = StringConverter::parseReal( XMLAttentuation->Attribute("linear") );
310                if( XMLAttentuation->Attribute("quadratic") )
311                        quadratic = StringConverter::parseReal( XMLAttentuation->Attribute("quadratic") );
312                        l->setAttenuation( range, constant, linear, quadratic );
313        }
314
315        XMLPosition = XMLLight->FirstChildElement("position");
316        if( XMLPosition )
317        {
318                Vector3 p = Vector3(0,0,0);
319                if( XMLPosition->Attribute("x") )
320                        p.x = StringConverter::parseReal( XMLPosition->Attribute("x") );
321                if( XMLPosition->Attribute("y") )
322                        p.y = StringConverter::parseReal( XMLPosition->Attribute("y") );
323                if( XMLPosition->Attribute("z") )
324                        p.z = StringConverter::parseReal( XMLPosition->Attribute("z") );
325           
326                l->setPosition( p );
327        }
328
329        //castShadows           (true | false) "true"
330        l->setCastShadows( true );
331        if( XMLLight->Attribute("visible") )
332                if( String(XMLLight->Attribute("visible")) == "false" )
333                                l->setCastShadows( false );
334                       
335        //visible                       (true | false) "true"           
336        l->setVisible( true );
337        if( XMLLight->Attribute("visible") )
338                if( String(XMLLight->Attribute("visible")) == "false" )
339                        l->setVisible( false );
340
341        return l;
342}
343//-----------------------------------------------------------------------
344void TestCullingApplication::createCamera( void )
345{
346        // Create the camera
347        mCamera = mSceneMgr->createCamera("PlayerCam");
348
349        // Position it at 500 in Z direction
350        mCamera->setPosition(Vector3(128,25,128));
351
352        // Look back along -Z
353    mCamera->lookAt(Vector3(0,0,-300));
354    mCamera->setNearClipDistance( 1 );
355    mCamera->setFarClipDistance( 1000 );
356}
357//-----------------------------------------------------------------------
358void TestCullingApplication::createScene(void)
359{
360        Plane waterPlane;
361        // Set ambient light
362        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
363       
364        // Create a light
365        Light* l = mSceneMgr->createLight("MainLight");
366        // Accept default settings: point light, white diffuse, just set position
367        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
368        //  other objects, but I don't
369        l->setPosition(20,80,50);
370
371        // Fog
372        // NB it's VERY important to set this before calling setWorldGeometry
373        // because the vertex program picked will be different
374        ColourValue fadeColour(0.93, 0.86, 0.76);
375        mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
376        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
377
378        std::string terrain_cfg("terrain.cfg");
379#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
380        terrain_cfg = mResourcePath + terrain_cfg;
381#endif
382        mSceneMgr -> setWorldGeometry( terrain_cfg );
383        // Infinite far plane?
384        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
385        {
386                mCamera->setFarClipDistance(0);
387        }
388
389        // Define the required skyplane
390        Plane plane;
391        // 5000 world units from the camera
392        plane.d = 5000;
393        // Above the camera, facing down
394        plane.normal = -Vector3::UNIT_Y;
395
396        // Set a nice viewpoint
397        mCamera->setPosition(707,2500,528);
398        mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
399
400        raySceneQuery = mSceneMgr->createRayQuery(
401        Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
402
403     // Create a skybox
404  //   mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
405
406         // CEGUI setup
407         setupGui();
408}
409//-----------------------------------------------------------------------
410void TestCullingApplication::setupGui( void )
411{
412         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, ST_EXTERIOR_CLOSE);
413     mGUISystem = new CEGUI::System(mGUIRenderer);
414
415         // Mouse
416     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
417     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
418         mGUISystem->setDefaultMouseCursor(
419                (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
420
421         CEGUI::MouseCursor::getSingleton().show( );
422     
423        /* CEGUI::Window* sheet =
424            CEGUI::WindowManager::getSingleton().loadWindowLayout(
425                (CEGUI::utf8*)"ogregui.layout");
426
427     mGUISystem->setGUISheet(sheet);*/
428}
429//-----------------------------------------------------------------------
430void TestCullingApplication::createFrameListener(void)
431{
432        mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer);
433        mFrameListener->showDebugOverlay(true);
434        mRoot->addFrameListener(mFrameListener);
435}
436//-----------------------------------------------------------------------
437void TestCullingApplication::chooseSceneManager(void)
438{
439    //mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
440        mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
441}
442
443/***********************************************/
444/* MouseQueryListener implementation           */
445/***********************************************/
446
447//-----------------------------------------------------------------------
448MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
449        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer),
450                mShutdownRequested(false)
451{
452
453        // Setup default variables
454//      mCurrentObject = NULL;
455        mLMouseDown = false;
456        mRMouseDown = false;
457        mSceneMgr = sceneManager;
458
459    // Reduce move speed
460        mMoveSpeed = 50;
461        mRotateSpeed *= 2;
462
463        mCurrentAlgorithm = OcclusionCullingSceneTraverser::RENDER_COHERENT;
464        mThreshold = 0;
465   
466        // Register this so that we get mouse events.
467        mEventProcessor->addMouseListener(this);
468        mEventProcessor->addMouseMotionListener(this);
469        mEventProcessor->addKeyListener(this);
470
471        // show overlay
472        Overlay* pOver = OverlayManager::getSingleton().getByName("Example/OcclusionDemoOverlay");
473
474        mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/AlgorithmInfo");
475        mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/ThresholdInfo");
476        mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/FrustumCulledNodesInfo");
477        mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/QueryCulledNodesInfo");
478    mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/TraversedNodesInfo");
479
480        mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
481        mThresholdInfo->setCaption(": 0");
482        mFrustumCulledNodesInfo->setCaption(": 0");
483        mQueryCulledNodesInfo->setCaption(": 0");
484        mTraversedNodesInfo->setCaption(": 0");
485
486    pOver->show();
487} // MouseQueryListener
488//-----------------------------------------------------------------------
489void MouseQueryListener::mouseMoved (MouseEvent *e)
490{
491        // Update CEGUI with the mouse motion
492    CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight());
493}
494//-----------------------------------------------------------------------
495void MouseQueryListener::mousePressed(MouseEvent* e)
496{
497     // Left mouse button down
498     if (e->getButtonID() & InputEvent::BUTTON0_MASK)
499     {
500                 CEGUI::MouseCursor::getSingleton().hide( );
501                 mLMouseDown = true;
502     } // if
503     // Right mouse button down
504     else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
505     {
506         CEGUI::MouseCursor::getSingleton().hide( );
507         mRMouseDown = true;
508     } // else if
509} // mousePressed
510
511 //-----------------------------------------------------------------------
512void MouseQueryListener::mouseReleased(MouseEvent* e)
513{
514    // Left mouse button up
515    if (e->getButtonID() & InputEvent::BUTTON0_MASK)
516    {
517                CEGUI::MouseCursor::getSingleton().show( );
518        mLMouseDown = false;
519    }
520    // Right mouse button up
521    else if (e->getButtonID() & InputEvent::BUTTON1_MASK)
522    {
523        CEGUI::MouseCursor::getSingleton().show( );
524        mRMouseDown = false;
525    }
526}
527//-----------------------------------------------------------------------
528void MouseQueryListener::mouseDragged (MouseEvent *e)
529 {
530         /*
531         // If we are dragging the left mouse button.   
532         if ( mLMouseDown )
533         {
534                mShipNode->translate(-e->getRelX() * 200, -e->getRelY() * 200, 0.0);
535     }
536         */
537         
538         // If we are dragging the right mouse button.
539         if ( mRMouseDown )
540         {
541                 mCamera->yaw( -e->getRelX() * mRotateSpeed );
542                 mCamera->pitch( -e->getRelY() * mRotateSpeed );
543         }
544}
545//-----------------------------------------------------------------------
546bool MouseQueryListener::frameStarted(const FrameEvent &evt)
547{
548        // clamp to terrain
549        static Ray updateRay;
550        updateRay.setOrigin(mCamera->getPosition());
551        updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
552        raySceneQuery->setRay(updateRay);
553        RaySceneQueryResult& qryResult = raySceneQuery->execute();
554        RaySceneQueryResult::iterator i = qryResult.begin();
555         
556        if (i != qryResult.end() && i->worldFragment)
557        {
558                SceneQuery::WorldFragment* wf = i->worldFragment;
559                mCamera->setPosition(mCamera->getPosition().x,
560                        i->worldFragment->singleIntersection.y + 10,
561                        mCamera->getPosition().z);
562        }
563         
564        return ExampleFrameListener::frameStarted(evt);
565}
566//-----------------------------------------------------------------------
567bool MouseQueryListener::frameEnded(const FrameEvent& evt)
568{
569        if (mShutdownRequested)
570                return false;
571
572    if (timeDelay >= 0)
573        timeDelay -= evt.timeSinceLastFrame;
574
575    KEY_PRESSED(KC_SPACE, 0.3, changeAlgorithm());
576
577        KEY_PRESSED(KC_SUBTRACT, 0.3, changeThreshold(-10));
578        KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
579        //KEY_PRESSED(KC_T, 1, change);
580     
581        changeStats();
582
583    return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);       
584}
585//-----------------------------------------------------------------------
586void MouseQueryListener::changeThreshold(int incr)
587{
588        mThreshold += incr; if(mThreshold < 0) mThreshold = 0;
589       
590        char str[100]; sprintf(str,": %d", mThreshold);
591
592        mSceneMgr->setOption("Threshold", &mThreshold);
593        mThresholdInfo->setCaption(str);
594}
595//-----------------------------------------------------------------------
596void MouseQueryListener::changeAlgorithm()
597{
598    mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingSceneTraverser::NUM_RENDERMODES;
599
600        mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
601        mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
602}
603//-----------------------------------------------------------------------
604void MouseQueryListener::changeStats()
605{
606        unsigned int opt = 0;
607        char str[100];
608       
609        mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt);
610        mFrustumCulledNodesInfo->setCaption(str);
611       
612        mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt);
613        mQueryCulledNodesInfo->setCaption(str);
614       
615        mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt);
616        mTraversedNodesInfo->setCaption(str);
617}
618//-----------------------------------------------------------------------
619void MouseQueryListener::keyPressed(KeyEvent* e)
620{
621        if(e->getKey() == KC_ESCAPE)
622    {
623                mShutdownRequested = true;
624                e->consume();
625                return;
626        }
627
628        CEGUI::System::getSingleton().injectKeyDown(e->getKey());
629        CEGUI::System::getSingleton().injectChar(e->getKeyChar());
630        e->consume();
631}
632//-----------------------------------------------------------------------
633void MouseQueryListener::keyReleased(KeyEvent* e)
634{
635        CEGUI::System::getSingleton().injectKeyUp(e->getKey());
636        e->consume();
637}
638//-----------------------------------------------------------------------
639void MouseQueryListener::keyClicked(KeyEvent* e)
640{
641        // Do nothing
642        e->consume();
643}
644//-----------------------------------------------------------------------
645INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
646{
647    // Create application object
648    TestCullingApplication app;
649
650        try
651        {
652        app.go();
653    }
654        catch( Ogre::Exception& e )
655        {
656        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
657    }   
658
659    return 0;
660}
Note: See TracBrowser for help on using the repository browser.