source: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp @ 2359

Revision 2359, 23.4 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include <OgreNoMemoryMacros.h>
2#include <CEGUI/CEGUI.h>
3#include <../CEGUIRenderer/include/OgreCEGUIRenderer.h>
4#include <../CEGUIRenderer/include/OgreCEGUIResourceProvider.h>
5#include <../CEGUIRenderer/include/OgreCEGUITexture.h>
6#include <OgreMemoryMacros.h>
7#include <OgreIteratorWrappers.h>
8#include <Ogre.h>
9#include "TestCullingTerrainApplication.h"
10#include "TerrainFrameListener.h"
11
12#if COLLADA
13#include "OgreColladaPrerequisites.h"
14#include "OgreColladaDocument.h"
15#include "OgreColladaScene.h"
16#endif
17
18#include "IVReader.h"
19
20#define WIN32_LEAN_AND_MEAN
21#include <windows.h>
22
23const static bool USE_STATIC_GEOMETRY = false;
24bool TestCullingTerrainApplication::msShowHillyTerrain = false;
25
26
27//using namespace GtpVisibility;
28
29/*************************************************************/
30/*                EntityState implementation                 */
31/*************************************************************/
32
33
34Vector3 EntityState::msMinPos = Vector3::ZERO;
35Vector3 EntityState::msMaxPos = Vector3::ZERO;
36
37EntityState::EntityState(Entity *ent, State entityState, Real speed):
38mEntity(ent), mState(entityState), mAnimationSpeed(speed)
39{
40        switch(entityState)
41        {
42        case MOVING:
43                mAnimationState = mEntity->getAnimationState("Walk");
44                break;
45        case WAITING:
46                mAnimationState = mEntity->getAnimationState("Idle");
47                break;
48        case STOP:
49                mAnimationState = NULL;
50                break;
51        default:
52                break;
53        }
54        // enable animation state
55        if (mAnimationState)
56        {
57                mAnimationState->setLoop(true);
58                mAnimationState->setEnabled(true);
59        }
60
61        mTimeElapsed = Math::RangeRandom(1, 5);
62}
63//-----------------------------------------------------------------------
64EntityState::~EntityState()
65{
66        mAnimationState = NULL;
67        mEntity = NULL;
68}
69//-----------------------------------------------------------------------
70Entity *EntityState::GetEntity()
71{
72        return mEntity;
73}
74//-----------------------------------------------------------------------
75EntityState::State EntityState::GetState()
76{
77        return mState;
78}
79//-----------------------------------------------------------------------
80void EntityState::update(Real timeSinceLastFrame)
81{
82        mTimeElapsed -= timeSinceLastFrame * mAnimationSpeed;
83
84        if (!mEntity || !mAnimationState)
85                return;
86       
87        if (mState == MOVING) // toggle between moving (longer) and waiting (short)
88        {
89                SceneNode *parent = mEntity->getParentSceneNode();
90               
91                if (!parent)
92                        return;
93
94                if (mTimeElapsed <= 0) // toggle animation state
95                {
96                        if (mAnimationState->getAnimationName() == "Idle")
97                        {
98                                SetAnimationState("Walk", true);
99                               
100                                mTimeElapsed = walk_duration; // walk for mTimeElapsed units
101
102                                // choose random rotation
103                                Radian rnd = Radian(Math::UnitRandom() * Math::PI * rotate_factor);
104
105                                //mEntity->getParentSceneNode()->rotate();
106                                parent->yaw(rnd);                                               
107                        }
108                        else
109                        {
110                                SetAnimationState("Idle", true);
111                                mTimeElapsed = wait_duration; // wait for mTimeElapsed seconds
112                        }
113                }
114
115                if (mAnimationState->getAnimationName() == "Walk") // move forward
116                {
117                        // store old position, just in case we get out of bounds
118                        Vector3 oldPos = parent->getPosition();
119                        parent->translate(parent->getLocalAxes(), Vector3(move_factor * mAnimationSpeed, 0, 0));
120
121                        // HACK: if out of bounds => reset to old position and set animationstate to idle
122                        if (OutOfBounds(parent))
123                        {
124                                parent->setPosition(oldPos);
125                                SetAnimationState("Idle", true);
126                               
127                                mTimeElapsed = wait_duration;
128                        }
129                }
130        }
131               
132        // add time to drive animation
133        mAnimationState->addTime(timeSinceLastFrame * mAnimationSpeed);
134}
135//-----------------------------------------------------------------------
136void EntityState::SetAnimationState(String stateStr, bool loop)
137{
138        if (!mEntity)
139                return;
140
141        mAnimationState = mEntity->getAnimationState(stateStr);
142        mAnimationState->setLoop(loop);
143        mAnimationState->setEnabled(true);
144}
145//-----------------------------------------------------------------------
146bool EntityState::OutOfBounds(SceneNode *node)
147{
148        Vector3 pos = node->getPosition();
149
150        if ((pos > msMinPos) && (pos < msMaxPos))
151                return false;
152
153        return true;
154}
155
156
157
158/********************************************************************/
159/*            TestCullingTerrainApplication implementation          */
160/********************************************************************/
161
162
163TestCullingTerrainApplication::TestCullingTerrainApplication():
164mTerrainContentGenerator(NULL),
165mRayQueryExecutor(NULL),
166mIVReader(NULL),
167mFilename("terrain"),
168mViewCellsFilename(""),
169mAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
170{
171}
172//-------------------------------------------------------------------------
173void TestCullingTerrainApplication::loadConfig(const String& filename)
174{
175        // Set up the options
176        ConfigFile config;
177        String val;
178
179        config.load(filename);
180
181        std::stringstream d; d << "reading the config file from: " << filename;
182        LogManager::getSingleton().logMessage(d.str());
183
184        val = config.getSetting("Scene");
185
186    if (!val.empty())
187        {
188                 mFilename = val.c_str();
189                 d << "\nloading scene from file: " << mFilename;
190                 LogManager::getSingleton().logMessage(d.str());
191        }
192}
193//-----------------------------------------------------------------------
194TestCullingTerrainApplication::~TestCullingTerrainApplication()
195{
196        OGRE_DELETE(mTerrainContentGenerator);
197        OGRE_DELETE(mRayQueryExecutor);
198        OGRE_DELETE(mIVReader);
199
200        deleteEntityStates();   
201}
202//-----------------------------------------------------------------------
203void TestCullingTerrainApplication::deleteEntityStates()
204{
205        for (int i = 0; i < (int)mEntityStates.size(); ++i)
206        {
207                OGRE_DELETE(mEntityStates[i]);
208        }
209
210        mEntityStates.clear();
211}
212//-----------------------------------------------------------------------
213void TestCullingTerrainApplication::createCamera()
214{
215        // create the camera
216        mCamera = mSceneMgr->createCamera("PlayerCam");
217       
218        /** set a nice viewpoint
219        *       we use a camera node here and apply all transformations on it instead
220        *       of applying all transformations directly to the camera
221        *       because then the camera is displayed correctly in the visualization
222        */
223        // hack: vienna view point
224        Vector3 viewPoint(830, 300, -540);
225       
226        mCamNode = mSceneMgr->getRootSceneNode()->
227                createChildSceneNode("CamNode1", viewPoint);
228       
229        mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
230        mCamNode->attachObject(mCamera);
231       
232        ///////////////////
233        //-- create visualization camera
234
235        mVizCamera = mSceneMgr->createCamera("VizCam");
236        mVizCamera->setPosition(mCamNode->getPosition());
237
238        mVizCamera->setNearClipDistance(1);
239        mCamera->setNearClipDistance(1);
240
241        // infinite far plane?
242        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
243        {
244                mVizCamera->setFarClipDistance(0);
245                mCamera->setFarClipDistance(0);
246        }
247        else
248        {
249                 mVizCamera->setFarClipDistance(20000);
250                 mCamera->setFarClipDistance(20000);
251        }       
252}
253
254//-----------------------------------------------------------------------
255bool TestCullingTerrainApplication::setup()
256{
257        bool carryOn = ExampleApplication::setup();
258
259        if (carryOn)
260                createRenderTargetListener();
261
262        return carryOn;
263}
264//-----------------------------------------------------------------------
265void TestCullingTerrainApplication::createRenderTargetListener()
266{
267        mWindow->addListener(new VisualizationRenderTargetListener(mSceneMgr));
268}
269//-----------------------------------------------------------------------
270bool TestCullingTerrainApplication::LoadSceneCollada(const String &filename,
271                                                                                                         SceneNode *root,
272                                                                                                         const int index)
273{
274#if COLLADA
275        // Collada
276        ColladaDocument *daeDoc = new ColladaDocument(mSceneMgr);
277
278        String daeName = filename;
279        //if (daeName.empty())
280        //      daeName = "City_1500.dae";
281
282        // default directory
283        //daeName.insert(0, "../../media/models/collada/City");
284        LogManager::getSingleton().logMessage("ColladaDocument - import started");
285
286        // full import
287        if (daeDoc->doImport(daeName))
288        {
289                LogManager::getSingleton().logMessage("loading collada");
290                /**
291                 * build up scene
292                 * if you only want a specific part of the scene graph, you must fetch a scene node
293                 * by its unique node name and give it as parameter
294                 * e.g.
295                 * ColladaSceneNode *box = mScene->getNode("Box2");
296                 * if (box != NULL) box->createOgreInstance(NULL);
297                 */
298                daeDoc->getScene()->createOgreInstance(NULL);
299
300                // everything is loaded, we do not need the collada document anymore
301                delete daeDoc;
302
303                return true;
304        }
305        else
306        {
307                LogManager::getSingleton().logMessage("ColladaDocument - import failed");
308                return false;
309        }
310#endif
311        return true;
312}
313//-----------------------------------------------------------------------
314bool TestCullingTerrainApplication::LoadSceneIV(const String &filename,
315                                                                                                SceneNode *root,
316                                                                                                const int index)
317{
318        mIVReader = new IVReader();
319
320        Timer *timer = PlatformManager::getSingleton().createTimer();
321        timer->reset();
322
323        if (1)
324        {
325                std::string logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log";
326               
327                Log *log = LogManager::getSingleton().createLog(logFilename);
328                mIVReader->setLog(log);
329        }
330       
331        //viennaNode->translate(Vector3(-300, -300, 0));
332
333        if (mIVReader->loadFile(filename.c_str()))
334        {
335                SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
336
337                mIVReader->buildTree(mSceneMgr, node);
338               
339                mIVReader->collapse();
340                OGRE_DELETE(mIVReader);
341
342                std::stringstream d;
343                d << "loaded " << filename << " in " << timer->getMilliseconds() * 1e-3 << " secs";
344                LogManager::getSingleton().logMessage(d.str());
345               
346                PlatformManager::getSingleton().destroyTimer(timer);
347
348                //-- bake into static geometry
349                if (USE_STATIC_GEOMETRY)
350                {
351                        BakeSceneIntoStaticGeometry("staticVienna", "Vienna");
352                }
353       
354                return true;
355        }
356
357        return false;
358}
359//--------------------------------------------------------
360void TestCullingTerrainApplication::BakeSceneIntoStaticGeometry(const String &staticGeomName,
361                                                                                                                                const String &nodeName)
362{
363#if OGRE_103
364        // note: different static geom for roofs, roads, ..., becazse they have same material
365        StaticGeometry *staticGeom = mSceneMgr->createStaticGeometry(staticGeomName);
366
367        // note: looping over entities here. why does scene node not work?
368        SceneManager::EntityIterator it = mSceneMgr->getEntityIterator();
369        while (it.hasMoreElements())
370        {
371                Entity *ent = it.getNext();
372                ent->setVisible(false);
373                staticGeom->addEntity(ent, ent->getParentSceneNode()->getPosition());
374        }
375
376        staticGeom->setRegionDimensions(Vector3(100,100,100));
377        staticGeom->build();
378
379        // cleanup node
380        //wallsNode->detachAllObjects();
381       
382        //roofsNode->detachAllObjects();
383        //roadsNode->detachAllObjects();
384        //planeNode->detachAllObjects();
385       
386        //viennaNode->removeChild("Walls");
387        mSceneMgr->destroySceneNode(nodeName);
388#endif
389}
390//--------------------------------------------------------
391void TestCullingTerrainApplication::createScene()
392{
393        /////////
394        //-- load parameters & scene
395        //loadConfig("terrainCulling.cfg");
396       
397        /////////////////////////////////////
398
399        // Set ambient light
400        mAmbientLight = ColourValue(0.5, 0.5, 0.5);
401        mSceneMgr->setAmbientLight(mAmbientLight);
402       
403        //-- create light
404        mSunLight = mSceneMgr->createLight("SunLight");
405        mSunLight->setType(Light::LT_DIRECTIONAL);
406        //mSunLight->setType(Light::LT_SPOTLIGHT);
407        //mSunLight->setSpotlightRange(Degree(30), Degree(50));
408
409    mSunLight->setPosition(707, 2000, 500);
410        mSunLight->setCastShadows(true);
411
412        // set light angle not too small over the surface,
413        // otherwise shadows textures will be broken
414        Vector3 dir(0.5, 1, 0.5);
415        dir.normalise();
416        mSunLight->setDirection(dir);
417        //mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
418        mSunLight->setDiffuseColour(1, 1, 1);
419        mSunLight->setSpecularColour(1, 1, 1);
420
421        // it's VERY important to set fog before calling setWorldGeometry
422        // because the vertex program picked will be different
423        ColourValue fadeColour(0.93, 0.86, 0.76);
424        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
425        //mSceneMgr->setFog(FOG_LINEAR, fadeColour, .001, 500, 1000);
426       
427        // Create a skybox
428        mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 50000, true);
429       
430        // terrain creation
431        std::string terrain_cfg("terrainCulling.cfg");
432       
433        mSceneMgr->setWorldGeometry(terrain_cfg);
434
435        // was terrain loaded?
436        mSceneMgr->getOption("ShowTerrain", &msShowHillyTerrain);
437        msShowHillyTerrain=true;
438
439               
440        // hack view point for terrain
441        if (msShowHillyTerrain)
442        {
443                Vector3 viewPoint(707, 5000, 528);
444                mCamNode->setPosition(viewPoint);
445        }
446
447       
448        //-- CEGUI setup
449        setupGui();
450
451        // Warning: In GL since we can't go higher than the window res
452        mSceneMgr->setShadowTextureSettings(1024, 2);
453        mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
454
455
456        //////////////
457        //-- terrain content setup
458
459        // HACK: necessary to call once here for terrain initialisation
460        mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true);
461
462        // ray query executor: needed to clamp to terrain
463        mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
464
465        mTerrainMinPos = EntityState::msMinPos = Vector3(0, 0, 0);
466        mTerrainMaxPos = EntityState::msMaxPos = Vector3(5000, 5000, 5000);
467
468        mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr);
469               
470        // if no objects in file, we generate new objects
471        if (msShowHillyTerrain && !mTerrainContentGenerator->LoadObjects("objects.out"))
472        {
473                // the objects are generated randomly distributed over the terrain
474                if (1) generateScene(1000, 0); // create robots
475                if (0) generateScene(100, 1); // create ninjas
476                if (1) generateScene(500, 2); // create trees
477        }
478        int MaxDepth=30;
479        mSceneMgr->setOption("BiHierarchyMaxDepth", &MaxDepth);
480        int Mode=1;
481        mSceneMgr->setOption("EnhancedVisibility", &Mode);
482        mSceneMgr->setOption("RebuildBiHierarchy", NULL);
483        mSceneMgr->setOption("RebuildKdTree", NULL);
484}
485//-----------------------------------------------------------------------
486void  TestCullingTerrainApplication::generateScene(int num, int objectType)
487{
488        const float val = TerrainFrameListener::msObjectScales[objectType];
489        Vector3 scale(val, val, val);
490        const float maxHeight = 75;
491       
492        // In order to provide much occlusion,
493        // height is restricted to maxHeight => no objects are created on peaks
494        mTerrainContentGenerator->SetMinPos(Vector3(mTerrainMinPos));
495        mTerrainContentGenerator->SetMaxPos(Vector3(mTerrainMaxPos.x, maxHeight, mTerrainMaxPos.z));
496       
497        mTerrainContentGenerator->SetScale(scale);
498        mTerrainContentGenerator->SetOffset(TerrainFrameListener::msObjectTerrainOffsets[objectType]);
499        mTerrainContentGenerator->GenerateScene(num, TerrainFrameListener::msObjectCaptions[objectType]);
500
501        if (objectType != 0) // from our objects, only robot has animation phases
502                return;
503
504        EntityList *entList = mTerrainContentGenerator->GetGeneratedEntities();
505
506        /////////////
507        //-- add animation state for new robots (located at the end of the list)
508       
509        for (int i = (int)entList->size() - num; i < (int)entList->size(); ++i)
510        {
511                mEntityStates.push_back(new EntityState((*entList)[i],
512                        EntityState::WAITING, Math::RangeRandom(0.5, 1.5)));
513        }
514
515        // release limitations on height => it is possible for the user to put single
516        // objects on peaks of the terrain (will be only few, not relevant for occlusion)
517        mTerrainContentGenerator->SetMaxPos(mTerrainMaxPos);
518}
519//-----------------------------------------------------------------------
520void TestCullingTerrainApplication::updateAnimations(Real timeSinceLastFrame)
521{
522        for (int i = 0; i < (int)mEntityStates.size(); ++i)
523        {
524                SceneNode *sn = mEntityStates[i]->GetEntity()->getParentSceneNode();
525
526                mEntityStates[i]->update(timeSinceLastFrame);
527
528                if (mEntityStates[i]->GetState() == EntityState::MOVING)
529                {
530                        Clamp2Terrain(sn, 0); //sn->setNodeVisible(false);
531                }
532        }
533}
534//-----------------------------------------------------------------------
535EntityStates  &TestCullingTerrainApplication::getEntityStates()
536{
537        return mEntityStates;
538}
539//-----------------------------------------------------------------------
540void TestCullingTerrainApplication::setupGui()
541{
542#if OGRE103
543         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
544                 false, 3000, ST_EXTERIOR_CLOSE);
545#else
546          mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY,
547                 false, 3000, mSceneMgr);
548#endif
549     mGUISystem = new CEGUI::System(mGUIRenderer);
550
551         // Mouse
552     CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
553     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
554         mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook",
555                                                                           (CEGUI::utf8*)"MouseArrow");
556
557         CEGUI::MouseCursor::getSingleton().hide();
558}
559//-----------------------------------------------------------------------
560void TestCullingTerrainApplication::createFrameListener()
561{
562        mTerrainFrameListener =
563                new TerrainFrameListener(mWindow,
564                                                                 mCamera,
565                                                                 mSceneMgr,
566                                                                 mGUIRenderer,
567                                                                 mTerrainContentGenerator,
568                                                                 mVizCamera,
569                                                                 mCamNode,
570                                                                 mSunLight,
571                                                                 this);
572
573        mTerrainFrameListener->setPriority(10);
574       
575        mRoot->addFrameListener(mTerrainFrameListener);
576}
577//-----------------------------------------------------------------------
578void TestCullingTerrainApplication::chooseSceneManager()
579{
580#ifdef OGRE_103
581        if (msShowHillyTerrain)
582        {
583                // Terrain scene manager
584                mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
585        }
586        else
587        {       // octree scene manager
588                mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
589        }
590#else
591
592        //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
593        mSceneMgr = mRoot->createSceneManager("BiHierarchySceneManager");
594        //mSceneMgr = mRoot->createSceneManager("BiTreeTerrainSceneManager");
595       
596#endif
597}
598//-----------------------------------------------------------------------
599bool TestCullingTerrainApplication::Clamp2Terrain(SceneNode *node, int terrainOffs)
600{
601        // clamp scene node to terrain
602        Vector3 pos = node->getPosition();
603        Vector3 queryResult;
604
605        if (mRayQueryExecutor->executeRayQuery(&queryResult,
606                        Vector3(pos.x, MAX_HEIGHT, pos.z), Vector3::NEGATIVE_UNIT_Y))
607        {
608        node->setPosition(pos.x, queryResult.y + terrainOffs, pos.z);
609                return true;
610        }
611
612        return false;
613}
614
615//-----------------------------------------------------------------------
616bool TestCullingTerrainApplication::Clamp2FloorPlane(const float dist)
617{
618    // clamp to floor plane
619        RaySceneQuery *raySceneQuery = mSceneMgr->createRayQuery(
620                Ray(mCamNode->getPosition(), Vector3::NEGATIVE_UNIT_Y));
621
622        RaySceneQueryResult& qryResult = raySceneQuery->execute();
623   
624        RaySceneQueryResult::iterator rit = qryResult.begin();
625        bool success = false;
626       
627        float yVal = 0;
628        float minVal = 999999999999;
629
630        while (rit != qryResult.end() && rit->movable)
631        {
632                if (rit->movable->getName() != "PlayerCam")
633                {
634                        // place on the ground object
635                        yVal = rit->movable->getWorldBoundingBox().getCenter().y;
636                                if (yVal < minVal)
637                                        minVal = yVal;
638
639                        //std::stringstream d; d << "dist: " << dist << endl;
640                        //Ogre::LogManager()
641                        success = true;
642                }
643
644                ++ rit;
645        }
646   
647        // place on the ground object
648        if (success)
649        {
650                mCamNode->setPosition(mCamNode->getPosition().x,
651                                                          minVal + dist,
652                                                          mCamNode->getPosition().z);
653        }
654
655        OGRE_DELETE(raySceneQuery);
656
657        return success;
658}
659
660//-----------------------------------------------------------------------
661// splits strings containing multiple file names
662static int SplitFilenames(const std::string str, std::vector<std::string> &filenames)
663{
664        int pos = 0;
665
666        while(1)
667        {
668                int npos = (int)str.find(';', pos);
669               
670                if (npos < 0 || npos - pos < 1)
671                        break;
672                filenames.push_back(std::string(str, pos, npos - pos));
673                pos = npos + 1;
674        }
675       
676        filenames.push_back(std::string(str, pos, str.size() - pos));
677        return (int)filenames.size();
678}
679//-----------------------------------------------------------------------
680bool TestCullingTerrainApplication::LoadScene(const String &filename)
681{
682        using namespace std;
683        // use leaf nodes of the original spatial hierarchy as occludees
684        vector<string> filenames;
685        int files = SplitFilenames(filename, filenames);
686       
687        std::stringstream d;
688        d << "number of input files: " << files << "\n";
689        LogManager::getSingleton().logMessage(d.str());
690
691        bool result = false;
692        vector<string>::const_iterator fit, fit_end = filenames.end();
693        int i = 0;
694
695        for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
696        {
697                const string fn = *fit;
698
699                if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
700                {
701                        // load iv files
702                        if (!LoadSceneIV(fn, mSceneMgr->getRootSceneNode(), i))
703                        {
704                                // terrain hack
705                                //msShowHillyTerrain = true;
706                                LogManager::getSingleton().logMessage("error loading scene => load terrain");
707                        }
708                }
709                else if (strstr(filename.c_str(), ".dae"))
710                {
711                        // load collada files
712                        LoadSceneCollada(fn, mSceneMgr->getRootSceneNode(), i);         
713                }
714                else //if (filename == "terrain")
715                {
716                        // terrain hack
717                        msShowHillyTerrain = true;
718                        LogManager::getSingleton().logMessage("loading terrain");
719                }
720       
721                result = true;
722        }
723       
724        return result;
725}
726//-----------------------------------------------------------------------
727bool TestCullingTerrainApplication::LoadViewCells(const String &filename)
728{
729        // if not already loaded,
730        // the scene manager will load the view cells
731        return mSceneMgr->setOption("UseViewCells", filename.c_str());
732}
733
734
735/**********************************************************************/
736/*           VisualizationRenderTargetListener implementation         */
737/**********************************************************************/
738
739
740//-----------------------------------------------------------------------
741VisualizationRenderTargetListener::VisualizationRenderTargetListener(SceneManager *sceneMgr)
742:RenderTargetListener(), mSceneMgr(sceneMgr)
743{
744}
745//-----------------------------------------------------------------------
746void VisualizationRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt)
747{
748        // visualization viewport
749        const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER;
750        const bool nShowViz = !showViz;
751
752        mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
753        mSavedAmbientLight = mSceneMgr->getAmbientLight();
754
755        // -- ambient light must be full for visualization, shadows disabled
756    if (showViz)
757        {
758                mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
759                mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
760        }
761       
762    mSceneMgr->setOption("PrepareVisualization", &showViz);
763        mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
764       
765        RenderTargetListener::preViewportUpdate(evt);
766}
767//-----------------------------------------------------------------------
768void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
769{
770        // reset values
771        mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
772        mSceneMgr->setAmbientLight(mSavedAmbientLight);
773       
774        RenderTargetListener::postRenderTargetUpdate(evt);
775}
776//-----------------------------------------------------------------------
777INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
778{
779    // Create application object
780    TestCullingTerrainApplication app;
781
782        try
783        {
784        app.go();
785    }
786        catch( Ogre::Exception& e )
787        {
788        MessageBox( NULL, e.getFullDescription().c_str(),
789                        "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
790    }   
791
792    return 0;
793}
Note: See TracBrowser for help on using the repository browser.