2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
(Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
7
Copyright (c) 2000-2006 The OGRE Team
8
Also see acknowledgements in Readme.html
10
This program is free software; you can redistribute it and/or modify it under
11
the terms of the GNU Lesser General Public License as published by the Free Software
12
Foundation; either version 2 of the License, or (at your option) any later
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public License along with
20
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22
http://www.gnu.org/copyleft/lesser.txt.
23
-----------------------------------------------------------------------------
25
/***************************************************************************
26
PagingLandScapeOctreescenemanager.cpp - description
28
begin : Fri Sep 27 2002
29
copyright : (C) 2002 by Jon Anderson
30
email : janders@users.sf.net
32
Enhancements 2003 - 2004 (C) The OGRE Team
34
***************************************************************************/
36
#include "OgrePagingLandScapePrecompiledHeaders.h"
38
#include "OgrePagingLandScapeOctreeSceneManager.h"
40
#include "OgrePagingLandScapeOctreeAxisAlignedBoxSceneQuery.h"
41
#include "OgrePagingLandScapeOctreeIntersectionSceneQuery.h"
42
#include "OgrePagingLandScapeOctreePlaneBoundedVolumeListSceneQuery.h"
43
#include "OgrePagingLandScapeOctreeRaySceneQuery.h"
44
#include "OgrePagingLandScapeOctreeSphereSceneQuery.h"
45
#include "OgreRenderSystem.h"
46
#include "OgreWireBoundingBox.h"
47
#include "OgreRenderOperation.h"
48
#include "OgreStringConverter.h"
50
#include "OgreOverlayManager.h"
51
#include "OgreOverlayElement.h"
53
#include "OgrePagingLandScapeOctreeCamera.h"
54
#include "OgrePagingLandScapeOctree.h"
55
#include "OgrePagingLandScapeOctreeNode.h"
57
#include "OgreOcclusionBoundingBox.h"
58
#include "OgrePagingLandScapeOcclusionSorter.h"
59
#include "OgrePagingLandScapeOcclusionVisibilityData.h"
60
#include "OgrePagingLandScapeOcclusionTraversal.h"
61
#include "OgrePagingLandScapeOcclusionCameraTraversal.h"
62
#include "OgrePagingLandScapeOcclusionVFTraversal.h"
63
#include "OgrePagingLandScapeOcclusionSWTraversal.h"
64
#include "OgrePagingLandScapeOcclusionDebugTraversal.h"
70
void findNodesInBox(Ogre::SceneManager *sm,
71
const Ogre::AxisAlignedBox &box,
72
std::list < Ogre::SceneNode * > &list,
73
const Ogre::SceneNode * const exclude)
75
static_cast<Ogre::PagingLandScapeOctreeSceneManager*>(sm)->findNodesIn(box, list, exclude);
77
void findNodesInSphere(Ogre::SceneManager *sm,
78
const Ogre::Sphere &sphere,
79
std::list < Ogre::SceneNode * > &list,
80
const Ogre::SceneNode * const exclude)
82
static_cast<Ogre::PagingLandScapeOctreeSceneManager*>(sm)->findNodesIn(sphere, list, exclude);
88
//---------------------------------------------------------------------
95
int PagingLandScapeOctreeSceneManager::intersect_call = 0;
96
//---------------------------------------------------------------------
97
Intersection intersect(const Ray &ray, const AxisAlignedBox &box)
103
if (box.isInfinite())
106
const Vector3& min = box.getMinimum();
107
const Vector3& max = box.getMaximum();
108
const Vector3& rayorig = ray.getOrigin();
110
// Check origin inside first
111
if ( rayorig > min && rayorig < max )
114
const Vector3& raydir = ray.getDirection();
121
// Check each face in turn, only check closest 3
123
if (rayorig.x < min.x && raydir.x > 0)
125
t = (min.x - rayorig.x) / raydir.x;
128
// Substitute t back into ray and check bounds and dist
129
hitpoint = rayorig + raydir * t;
130
if (hitpoint.y >= min.y && hitpoint.y <= max.y &&
131
hitpoint.z >= min.z && hitpoint.z <= max.z &&
139
if (rayorig.x > max.x && raydir.x < 0)
141
t = (max.x - rayorig.x) / raydir.x;
144
// Substitute t back into ray and check bounds and dist
145
hitpoint = rayorig + raydir * t;
146
if (hitpoint.y >= min.y && hitpoint.y <= max.y &&
147
hitpoint.z >= min.z && hitpoint.z <= max.z &&
155
if (rayorig.y < min.y && raydir.y > 0)
157
t = (min.y - rayorig.y) / raydir.y;
160
// Substitute t back into ray and check bounds and dist
161
hitpoint = rayorig + raydir * t;
162
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
163
hitpoint.z >= min.z && hitpoint.z <= max.z &&
171
if (rayorig.y > max.y && raydir.y < 0)
173
t = (max.y - rayorig.y) / raydir.y;
176
// Substitute t back into ray and check bounds and dist
177
hitpoint = rayorig + raydir * t;
178
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
179
hitpoint.z >= min.z && hitpoint.z <= max.z &&
187
if (rayorig.z < min.z && raydir.z > 0)
189
t = (min.z - rayorig.z) / raydir.z;
192
// Substitute t back into ray and check bounds and dist
193
hitpoint = rayorig + raydir * t;
194
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
195
hitpoint.y >= min.y && hitpoint.y <= max.y &&
203
if (rayorig.z > max.z && raydir.z < 0)
205
t = (max.z - rayorig.z) / raydir.z;
208
// Substitute t back into ray and check bounds and dist
209
hitpoint = rayorig + raydir * t;
210
if (hitpoint.x >= min.x && hitpoint.x <= max.x &&
211
hitpoint.y >= min.y && hitpoint.y <= max.y &&
221
//---------------------------------------------------------------------
222
Intersection intersect2(const Ray &one, const AxisAlignedBox &two)
224
PagingLandScapeOctreeSceneManager::intersect_call++;
230
if (two.isInfinite())
233
const Vector3* const pCorners = two.getAllCorners();
234
const Vector3 origin = one.getOrigin();
235
const Vector3 dir = one.getDirection();
237
Vector3 maxT (-1.0f, -1.0f, -1.0f);
241
for (i = 0; i < 3; i++)
243
if (origin[i] < pCorners[0][i])
247
maxT[i] = (pCorners[0][i] - origin[i]) / dir[i];
249
else if (origin[i] > pCorners[4][i])
253
maxT[i] = (pCorners[4][i] - origin[i]) / dir[i];
262
if(maxT[1] > maxT[whichPlane])
264
if(maxT[2] > maxT[whichPlane])
267
if(((int)maxT[whichPlane]) & 0x80000000)
271
const Real maxTThisPlane = maxT[whichPlane];
272
for(i = 0; i < 3; i++)
276
const Real f = origin[i] + maxTThisPlane * dir[i];
277
if (f < (pCorners[0][i] - 0.00001f) ||
278
f > (pCorners[4][i] + 0.00001f))
288
//---------------------------------------------------------------------
289
/** Checks how the second box intersects with the first.
291
Intersection intersect(const PlaneBoundedVolume &one, const AxisAlignedBox &two)
293
PagingLandScapeOctreeSceneManager::intersect_call++;
297
if (two.isInfinite())
300
// Get corners of the box
301
const Vector3 * const pCorners = two.getAllCorners();
303
// For each plane, see if all points are on the negative side
304
// If so, object is not visible.
305
// If one or more are, it's partial.
306
// If all aren't, full
307
static const int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
309
bool all_inside = true;
310
PlaneList::const_iterator i, iend = one.planes.end();
311
for (i = one.planes.begin(); i != iend; ++i)
313
const Plane& plane = *i;
314
bool all_outside = true;
315
for (unsigned int corner = 0; corner < 8; ++corner)
317
const Real distance = plane.getDistance(pCorners[ corners[ corner ] ]);
318
all_outside = all_outside && (distance < 0);
319
all_inside = all_inside && (distance >= 0);
321
if (!all_outside && !all_inside)
335
//---------------------------------------------------------------------
336
/** Checks how the second box intersects with the first.
338
Intersection intersect(const AxisAlignedBox &one, const AxisAlignedBox &two)
340
PagingLandScapeOctreeSceneManager::intersect_call++;
343
if (one.isNull() || two.isNull())
345
if (one.isInfinite())
347
if (two.isInfinite())
350
const Vector3 * outside = one.getAllCorners();
351
const Vector3 *inside = two.getAllCorners();
353
if (inside[ 4 ].x < outside[ 0 ].x ||
354
inside[ 4 ].y < outside[ 0 ].y ||
355
inside[ 4 ].z < outside[ 0 ].z ||
356
inside[ 0 ].x > outside[ 4 ].x ||
357
inside[ 0 ].y > outside[ 4 ].y ||
358
inside[ 0 ].z > outside[ 4 ].z)
363
const bool full = (inside[ 0 ].x > outside[ 0 ].x &&
364
inside[ 0 ].y > outside[ 0 ].y &&
365
inside[ 0 ].z > outside[ 0 ].z &&
366
inside[ 4 ].x < outside[ 4 ].x &&
367
inside[ 4 ].y < outside[ 4 ].y &&
368
inside[ 4 ].z < outside[ 4 ].z);
376
//---------------------------------------------------------------------
377
/** Checks how the box intersects with the sphere.
379
Intersection intersect(const Sphere &one, const AxisAlignedBox &two)
381
PagingLandScapeOctreeSceneManager::intersect_call++;
386
if (two.isInfinite())
390
const Real sradius = Math::Sqr (one.getRadius());
391
const Vector3 scenter = one.getCenter();
392
const Vector3 * const corners = two.getAllCorners();
394
const Vector3 mndistance = (corners[ 0 ] - scenter);
395
const Vector3 mxdistance = (corners[ 4 ] - scenter);
398
if (mndistance.squaredLength() < sradius &&
399
mxdistance.squaredLength() < sradius)
404
//find the square of the distance
405
//from the sphere to the box
407
for (unsigned int i = 0 ; i < 3 ; i++)
409
const Real sCenteri = scenter[ i ];
410
if (sCenteri < corners[ 0 ][ i ])
412
const Real s = sCenteri - corners[ 0 ][ i ];
415
else if (sCenteri > corners[ 4 ][ i ])
417
const Real s = sCenteri - corners[ 4 ][ i ];
423
const bool partial = (d <= sradius);
437
//-----------------------------------------------------------------------
438
//-----------------------------------------------------------------------
439
//-----------------------------------------------------------------------
440
const String PagingLandScapeOctreeSceneManagerFactory::FACTORY_TYPE_NAME = "PagingLandScapeOctreeSceneManager";
441
//-----------------------------------------------------------------------
442
void PagingLandScapeOctreeSceneManagerFactory::initMetaData(void) const
444
mMetaData.typeName = FACTORY_TYPE_NAME;
445
mMetaData.description = "Scene manager organising the scene on the basis of an octree, possibly using occlusion culling.";
446
mMetaData.sceneTypeMask = ST_EXTERIOR_REAL_FAR; // support all types
447
mMetaData.worldGeometrySupported = false;
449
//-----------------------------------------------------------------------
450
SceneManager* PagingLandScapeOctreeSceneManagerFactory::createInstance(
451
const String& instanceName)
453
return new PagingLandScapeOctreeSceneManager(instanceName);
455
//-----------------------------------------------------------------------
456
void PagingLandScapeOctreeSceneManagerFactory::destroyInstance(SceneManager* instance)
460
//---------------------------------------------------------------------
461
PagingLandScapeOctreeSceneManager::PagingLandScapeOctreeSceneManager(const String& name):
463
mPagingLandScapeOctree(0),
464
mCurrentOptionCamera(0)
466
mOctreeSet.setPoolSize (64);
467
AxisAlignedBox b(-10000, -10000, -10000, 10000, 10000, 10000);
471
//---------------------------------------------------------------------
472
PagingLandScapeOctreeSceneManager::PagingLandScapeOctreeSceneManager(const String& name, AxisAlignedBox &box, int max_depth) :
474
mPagingLandScapeOctree(0)
476
init(box, max_depth);
478
//---------------------------------------------------------------------
479
const String& PagingLandScapeOctreeSceneManager::getTypeName(void) const
481
return PagingLandScapeOctreeSceneManagerFactory::FACTORY_TYPE_NAME;
483
//---------------------------------------------------------------------
484
void PagingLandScapeOctreeSceneManager::init(const AxisAlignedBox &box, int depth)
486
delete mSceneRoot; //get rid of old root.
488
// -- Changes by Steve
489
// Don't do it this way, it will add it to the mSceneNodes which we don't want
490
//mSceneRoot = createSceneNode("SceneRoot");
491
mSceneRoot = new PagingLandScapeOctreeNode(this, "SceneRoot");
492
mSceneRoot->_notifyRootNode();
493
// -- End changes by Steve
496
if (mPagingLandScapeOctree)
497
deleteOctree (mPagingLandScapeOctree);
498
mPagingLandScapeOctree = mOctreeSet.getPoolable();
499
assert (mPagingLandScapeOctree);
500
mPagingLandScapeOctree->setSceneManager (this);
505
//mSceneRoot isn't put into the PagingLandScapeOctree since it has no volume.
506
mPagingLandScapeOctree->setBoundingBox (box.getMinimum(), box.getMaximum());
508
#ifdef _VISIBILITYDEBUG
511
// setDisplaySceneNodes(true);
512
#endif //_VISIBILITYDEBUG
515
mOcclusion.init (this);
519
//---------------------------------------------------------------------
520
PagingLandScapeOctreeSceneManager::~PagingLandScapeOctreeSceneManager()
522
// -- Changed by Steve
523
// Don't do this here, SceneManager will do it
528
// --End Changes by Steve
530
if (mPagingLandScapeOctree)
532
deleteOctree (mPagingLandScapeOctree);
533
mPagingLandScapeOctree = 0;
535
VisiblesPerCam::iterator i = mVisibles.begin ();
536
while (i != mVisibles.end())
542
mOctreeSet.deletePool ();
544
//---------------------------------------------------------------------
545
Camera * PagingLandScapeOctreeSceneManager::createCamera(const String &name)
547
if (mCameras.find(name) != mCameras.end())
550
Exception::ERR_DUPLICATE_ITEM,
551
"A camera with the name " + name + " already exists",
552
"PagingLandScapeSceneManager::createCamera");
554
Camera * c = new PagingLandScapeOctreeCamera(name, this);
555
mCameras.insert(CameraList::value_type(name, c));
559
//-----------------------------------------------------------------------
560
void PagingLandScapeOctreeSceneManager::addCamera(Camera *cam)
562
PagingLandScapeOctreeCamera *c = static_cast <PagingLandScapeOctreeCamera *> (cam);
563
mVisibles[c->getId ()] = new MovableObjectList();
564
if (!c->isRegisteredInOcclusionSystem()
565
&& c->needRegistrationInOcclusionSystem())
567
mPagingLandScapeOctree->traversal(RegisterCameraTraversal(c), 0);
568
c->setRegisteredInOcclusionSystem(true);
570
if (!mCurrentOptionCamera)
571
mCurrentOptionCamera = c;
573
//-----------------------------------------------------------------------
574
void PagingLandScapeOctreeSceneManager::unregisterCamera(PagingLandScapeOctreeCamera *c)
576
VisiblesPerCam::iterator i = mVisibles.find (c->getId ());
577
if (i != mVisibles.end())
582
if (c->isRegisteredInOcclusionSystem ())
584
mPagingLandScapeOctree->traversal (UnregisterCameraTraversal(c), 0);
585
c->setRegisteredInOcclusionSystem (false);
587
if (mCurrentOptionCamera == c)
590
//-----------------------------------------------------------------------
591
void PagingLandScapeOctreeSceneManager::destroyCamera(Camera *cam)
593
SceneManager::destroyCamera(cam);
595
//-----------------------------------------------------------------------
596
void PagingLandScapeOctreeSceneManager::destroyCamera(const String& name)
599
CameraList::iterator i = mCameras.find(name);
600
if (i != mCameras.end())
602
unregisterCamera (static_cast <PagingLandScapeOctreeCamera *> (i->second));
603
SceneManager::destroyCamera (name);
606
//-----------------------------------------------------------------------
607
void PagingLandScapeOctreeSceneManager::destroyAllCameras(void)
609
CameraList::iterator i = mCameras.begin();
610
for (; i != mCameras.end(); ++i)
612
unregisterCamera (static_cast <PagingLandScapeOctreeCamera *> (i->second));
613
// Notify render system
614
mDestRenderSystem->_notifyCameraRemoved(i->second);
619
//---------------------------------------------------------------------
620
void PagingLandScapeOctreeSceneManager::destroySceneNode(const String &name)
622
PagingLandScapeOctreeNode * on = static_cast < PagingLandScapeOctreeNode* > (SceneManager::getSceneNode(name));
625
_removePagingLandScapeOctreeNode(on);
627
SceneManager::destroySceneNode(name);
629
//---------------------------------------------------------------------
630
bool PagingLandScapeOctreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
632
return SceneManager::getOptionValues(key, refValueList);
634
//---------------------------------------------------------------------
635
bool PagingLandScapeOctreeSceneManager::getOptionKeys(StringVector & refKeys)
637
SceneManager::getOptionKeys(refKeys);
639
refKeys.push_back("CullCamera");
640
refKeys.push_back("Size");
641
refKeys.push_back("ShowPagingLandScapeOctree");
642
refKeys.push_back("Depth");
646
//---------------------------------------------------------------------
647
void PagingLandScapeOctreeSceneManager::_updatePagingLandScapeOctreeNode(PagingLandScapeOctreeNode * onode)
649
const AxisAlignedBox box = onode->_getWorldAABB();
654
// Skip if octree has been destroyed (shutdown conditions)
655
if (!mPagingLandScapeOctree)
658
if (onode->getOctant() == 0)
660
//if outside the PagingLandScapeOctree, force into the root node.
661
if (! onode->_isIn(mPagingLandScapeOctree->getBoundingBox()))
662
mPagingLandScapeOctree->_addNode(onode);
664
_addPagingLandScapeOctreeNode(onode, mPagingLandScapeOctree);
668
if (! onode->_isIn(onode->getOctant()->getBoundingBox()))
670
_removePagingLandScapeOctreeNode(onode);
672
//if outside the PagingLandScapeOctree, force into the root node.
673
if (! onode->_isIn(mPagingLandScapeOctree->getBoundingBox()))
674
mPagingLandScapeOctree->_addNode(onode);
676
_addPagingLandScapeOctreeNode(onode, mPagingLandScapeOctree);
679
//---------------------------------------------------------------------
680
/** Only removes the node from the PagingLandScapeOctree. It leaves the PagingLandScapeOctree, even if it's empty.
682
void PagingLandScapeOctreeSceneManager::_removePagingLandScapeOctreeNode(PagingLandScapeOctreeNode * n)
686
// Skip if octree has been destroyed (shutdown conditions)
687
if (!mPagingLandScapeOctree)
690
PagingLandScapeOctree * oct = n->getOctant();
692
oct->_removeNode (n);
694
unregisteredNodeInCamera (n);
696
//---------------------------------------------------------------------
697
void PagingLandScapeOctreeSceneManager::_addPagingLandScapeOctreeMovableNode(PagingLandScapeOctreeNode * n,
698
PagingLandScapeOctree *octant,
701
const AxisAlignedBox& bx(n->_getWorldAABB());
703
//if the PagingLandScapeOctree is twice as big as the scene node,
704
//we will add it to a child.
705
if ((depth < mMaxDepth) && octant->_isTwiceSize (bx))
707
_addPagingLandScapeOctreeMovableNode(n,
708
octant->_getChildWhereBoxFits(bx, this),
713
#ifdef _VISIBILITYDEBUG
714
n ->setDebugCorners(this);
715
#endif //_VISIBILITYDEBUG
718
std::cout << "Depth Placement "
719
<< StringConverter::toString (depth)
726
//---------------------------------------------------------------------
727
void PagingLandScapeOctreeSceneManager::_addPagingLandScapeOctreeStaticNode(PagingLandScapeOctreeNode * n,
728
PagingLandScapeOctree *octant,
731
const AxisAlignedBox bx = n->_getWorldAABB();
733
//if the PagingLandScapeOctree is twice as big as the scene node,
734
//we will add it to a child.
735
if ((depth < mMaxDepth) && octant->_isTwiceCullSize (bx))
737
if (octant->_isNotCrossingAxes(bx))
739
_addPagingLandScapeOctreeStaticNode(n,
740
octant->_getCullChildWhereBoxFits(bx, this),
745
// re-insert it as a moving node, therefore avoiding crossing problem.
746
n->setStaticCulling (false);
747
_addPagingLandScapeOctreeMovableNode(n,
748
mPagingLandScapeOctree,
754
#ifdef _VISIBILITYDEBUG
755
n ->setDebugCorners(this);
756
#endif //_VISIBILITYDEBUG
760
//---------------------------------------------------------------------
761
void PagingLandScapeOctreeSceneManager::_addPagingLandScapeOctreeNode(PagingLandScapeOctreeNode * n, PagingLandScapeOctree *octant, int depth)
763
assert (n && octant);
764
if (n->isStaticNode ())
765
_addPagingLandScapeOctreeStaticNode(n, octant, depth);
767
_addPagingLandScapeOctreeMovableNode(n, octant, depth);
768
registeredNodeInCamera (n);
770
//---------------------------------------------------------------------
771
SceneNode * PagingLandScapeOctreeSceneManager::createSceneNode(void)
773
PagingLandScapeOctreeNode * on = new PagingLandScapeOctreeNode(this);
774
mSceneNodes[ on->getName() ] = on;
777
//---------------------------------------------------------------------
778
SceneNode * PagingLandScapeOctreeSceneManager::createSceneNode(const String &name)
780
// Check name not used
781
if (mSceneNodes.find(name) != mSceneNodes.end())
784
Exception::ERR_DUPLICATE_ITEM,
785
"A scene node with the name " + name + " already exists",
786
"PagingLandScapeOctreeSceneManager::createSceneNode" );
788
PagingLandScapeOctreeNode * on = new PagingLandScapeOctreeNode(this, name);
789
mSceneNodes[ on->getName() ] = on;
792
//---------------------------------------------------------------------
793
void PagingLandScapeOctreeSceneManager::registeredNodeInCamera(OcclusionElement *on)
795
// register existing camera in nodes
796
bool isRegistered = false;
797
for (CameraList::iterator it = mCameras.begin(); it != mCameras.end(); ++it)
799
// Notify occlusion system
800
PagingLandScapeOctreeCamera *c = static_cast <PagingLandScapeOctreeCamera *> (it->second);
802
if (c->isRegisteredInOcclusionSystem ())
804
on->traversal (RegisterCameraTraversal(c), 0);
808
on->setRegisteredtoCam (isRegistered);
810
//---------------------------------------------------------------------
811
void PagingLandScapeOctreeSceneManager::unregisteredNodeInCamera(OcclusionElement *on)
813
// register existing camera in nodes
814
for (CameraList::iterator it = mCameras.begin();it != mCameras.end(); ++it)
816
// Notify occlusion system
817
PagingLandScapeOctreeCamera *c = static_cast <PagingLandScapeOctreeCamera *> (it->second);
819
if (c->isRegisteredInOcclusionSystem ())
820
on->traversal (UnregisterCameraTraversal(c), 0);
822
on->setRegisteredtoCam (false);
824
//---------------------------------------------------------------------
825
void PagingLandScapeOctreeSceneManager::_updateSceneGraph(Camera * cam)
827
SceneManager::_updateSceneGraph(cam);
829
//---------------------------------------------------------------------
830
void PagingLandScapeOctreeSceneManager::enableHardwareOcclusionTests()
832
Camera * const c_cam = mCameraInProgress;
834
// make sure we always occlude in SOLID MODE
835
mCamDetail = c_cam->getPolygonMode ();
836
if (mCamDetail != PM_SOLID)
838
mOcclusion.setIfNotSolidScene (true);
839
c_cam->setPolygonMode (PM_SOLID);
843
mOcclusion.setIfNotSolidScene (false);
846
//#define HWOCCLUSIONRTT
847
#ifdef HWOCCLUSIONRTT
849
const Viewport * const c_camViewPort = c_cam->getViewport();
850
assert (c_camViewPort);
851
if (mOcclusionDepth == 0)
853
mOcclusionDepth = mDestRenderSystem->
855
"OcclusionDepthTexture",
856
c_camViewPort->getActualWidth() / 8,
857
c_camViewPort->getActualHeight() / 8,
862
mOcclusionDepth->setAutoUpdated (false);
863
mOcclusionDepth->setActive (false);
865
mOcclusionCamera = createCamera ("OcclusionDepthTextureCamera");
866
Viewport * const v = mOcclusionDepth->addViewport(mOcclusionCamera);
868
v->setOverlaysEnabled (false);
869
v->setClearEveryFrame(false);
870
v->setBackgroundColour(ColourValue::Black);
874
MaterialPtr mat = MaterialManager::getSingleton().create (
875
"OcclusionDepthTextureMat",
876
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
877
mat->getTechnique(0)->getPass(0)->createTextureUnitState("OcclusionDepthTexture");
879
Overlay *OcclusionDepthOverlay = OverlayManager::getSingleton ().create("OcclusionDepthOverlay");
880
OverlayElement *OcclusionDepthPanel =
881
OverlayManager::getSingleton ().createOverlayElement ("Panel",
882
"OcclusionDepthPanel",
884
OcclusionDepthPanel->setMaterialName ("OcclusionDepthTextureMat");
885
OcclusionDepthOverlay->add2D ((OverlayContainer *)OcclusionDepthPanel);
886
OcclusionDepthOverlay->show ();
888
//OcclusionDepthOverlay->setScale (0.5f, 0.5f);
889
OcclusionDepthPanel->setPosition (0.8, 0.8);
892
mOcclusionCamera->setNearClipDistance(c_cam->getNearClipDistance());
893
mOcclusionCamera->setFarClipDistance(c_cam->getFarClipDistance());
894
mOcclusionCamera->setAspectRatio(
895
(Real)c_camViewPort->getActualWidth() / c_camViewPort->getActualHeight());
898
// copy camera characteristics to occlusion camera.
899
mOcclusionCamera->setPosition (c_cam->getWorldPosition ());
900
mOcclusionCamera->setOrientation (c_cam->getWorldOrientation ());
901
mOcclusionCamera->setNearClipDistance(c_cam->getNearClipDistance());
902
mOcclusionCamera->setFarClipDistance(c_cam->getFarClipDistance());
905
mDestRenderSystem->_setViewport(mOcclusionCamera->getViewport ());
906
mDestRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
907
mDestRenderSystem->_setViewMatrix(c_cam->getViewMatrix());
908
mDestRenderSystem->_setProjectionMatrix(c_cam->getProjectionMatrix());
910
mDestRenderSystem->_beginFrame();
912
mDestRenderSystem->clearFrameBuffer (FBT_DEPTH | FBT_COLOUR,
913
mOcclusionCamera->getViewport ()->getBackgroundColour ());
915
#else //HWOCCLUSIONRTT
917
assert (c_cam->getViewport());
918
mDestRenderSystem->_setViewport(c_cam->getViewport());
919
mDestRenderSystem->clearFrameBuffer (FBT_DEPTH | FBT_COLOUR,
920
c_cam->getViewport ()->getBackgroundColour (),//color
923
mDestRenderSystem->_beginFrame();
924
assert (c_cam->getViewport()->getClearEveryFrame () == false);
925
#endif //HWOCCLUSIONRTT
927
mDestRenderSystem->_beginGeometryCount();
930
//---------------------------------------------------------------------
931
void PagingLandScapeOctreeSceneManager::disableHardwareOcclusionTests()
933
PagingLandScapeOctreeCamera * const octreeCam = static_cast <PagingLandScapeOctreeCamera *> (mCameraInProgress);
935
assert (octreeCam->getViewport ());
936
#ifdef HWOCCLUSIONRTT
938
mDestRenderSystem->_endFrame();
939
mDestRenderSystem->_setViewport(octreeCam->getViewport ());
941
#else //HWOCCLUSIONRTT
942
mDestRenderSystem->_endFrame();
943
#endif //HWOCCLUSIONRTT
945
if (mCamDetail != PM_SOLID)
947
mDestRenderSystem->clearFrameBuffer (FBT_DEPTH | FBT_COLOUR,
948
octreeCam->getViewport ()->getBackgroundColour (),//color
953
// make sure we restore previous detail level.
954
octreeCam->setPolygonMode (mCamDetail);
956
// Notify camera or vis faces
957
octreeCam->_addCHCRenderedFaces(mDestRenderSystem->_getFaceCount());
959
//---------------------------------------------------------------------
961
void PagingLandScapeOctreeSceneManager::_findVisibleObjects(Camera* cam, VisibleObjectsBoundsInfo * visibleBounds, bool onlyShadowCasters)
963
void PagingLandScapeOctreeSceneManager::_findVisibleObjects(Camera * cam, bool onlyShadowCasters)
966
RenderQueue *q = SceneManager::getRenderQueue();
969
PagingLandScapeOctreeCamera * const octreeCam = static_cast <PagingLandScapeOctreeCamera *> (cam);
971
assert (mVisibles.find(octreeCam->getId()) != mVisibles.end());
972
mCamInProgressVisibles = mVisibles[octreeCam->getId()];
973
assert (mCamInProgressVisibles);
975
#ifdef _VISIBILITYDEBUG
977
if (!octreeCam->isRegisteredInOcclusionSystem())
979
mPagingLandScapeOctree->traversal(RegisterCameraTraversal(octreeCam));
980
octreeCam->setRegisteredInOcclusionSystem(true);
986
if (getCamera("CullCamera"))
987
cam = getCamera("CullCamera");
989
#endif // _VISIBILITYDEBUG
991
if (mPagingLandScapeOctree->hasChildren ())
995
// should find a way to be sure that
996
// it's a new frame, and not just a camera change or something.
997
if (mOcclusion.nextFrame (static_cast < PagingLandScapeOctreeCamera * > (cam),
998
mCamInProgressVisibles,
1002
switch (octreeCam->getOcclusionMode())
1006
enableHardwareOcclusionTests();
1007
mOcclusion.CHCtraversal (mPagingLandScapeOctree, visibleBounds);
1008
disableHardwareOcclusionTests();
1010
#ifdef _VISIBILITYDEBUG
1011
if (mCullDebug && cam->getViewport ())
1014
"CHC = " + StringConverter::toString(mOcclusion.object_cnt) + ", t=" +
1015
StringConverter::toString(mOcclusion.traversed_nodes_cnt) + ", f=" +
1016
StringConverter::toString(mOcclusion.frustum_culled_nodes_cnt) + ", q=" +
1017
StringConverter::toString(mOcclusion.query_cnt)
1020
#endif //_VISIBILITYDEBUG
1023
case CHC_CONSERVATIVE:
1025
enableHardwareOcclusionTests();
1026
mOcclusion.CHCtraversalConservative (mPagingLandScapeOctree, visibleBounds);
1027
disableHardwareOcclusionTests();
1030
#ifdef _VISIBILITYDEBUG
1031
if (mCullDebug && cam->getViewport ())
1034
"CHC Conservative = " + StringConverter::toString(mOcclusion.object_cnt) + ", t=" +
1035
StringConverter::toString(mOcclusion.traversed_nodes_cnt) + ", f=" +
1036
StringConverter::toString(mOcclusion.frustum_culled_nodes_cnt) + ", q=" +
1037
StringConverter::toString(mOcclusion.query_cnt)
1040
#endif //_VISIBILITYDEBUG
1043
// case STOP_AND_WAIT:
1045
// enableHardwareOcclusionTests();
1046
// mOcclusion.initQueryPool ();
1047
// mPagingLandScapeOctree->traversal (SWTraversal (mOcclusion), visibleBounds);
1048
// disableHardwareOcclusionTests(); q->clear();
1050
// #ifdef _VISIBILITYDEBUG
1051
// if (mCullDebug && cam->getViewport ()) {cam->getViewport ()->getTarget ()->setDebugText(
1052
// "SnW = " + StringConverter::toString(mOcclusion.object_cnt) + ", t=" +
1053
// StringConverter::toString(mOcclusion.traversed_nodes_cnt) + ", f=" +
1054
// StringConverter::toString(mOcclusion.frustum_culled_nodes_cnt) + ", q=" +
1055
// StringConverter::toString(mOcclusion.query_cnt)
1058
// #endif //_VISIBILITYDEBUG
1062
// case VIEW_FRUSTUM:
1064
// mPagingLandScapeOctree->traversal (ViewFrustumCullingTraversal (mOcclusion), visibleBounds);
1066
// #ifdef _VISIBILITYDEBUG
1067
// if (mCullDebug && cam->getViewport ())
1068
// { cam->getViewport ()->getTarget ()->setDebugText(
1069
// "VF = " + StringConverter::toString(mOcclusion.object_cnt) + ", t=" +
1070
// StringConverter::toString(mOcclusion.traversed_nodes_cnt) + ", f=" +
1071
// StringConverter::toString(mOcclusion.frustum_culled_nodes_cnt) + ", q=" +
1072
// StringConverter::toString(mOcclusion.query_cnt)
1075
// #endif //_VISIBILITYDEBUG
1078
case VIEW_FRUSTUM_DIRECT:
1080
ViewFrustumCullingTraversalDirect temp (mOcclusion);
1081
mPagingLandScapeOctree->traversal (temp, visibleBounds);
1083
#ifdef _VISIBILITYDEBUG
1084
if (mCullDebug && cam->getViewport ())
1087
"VFD = " + StringConverter::toString(mOcclusion.object_cnt) + ", t=" +
1088
StringConverter::toString(mOcclusion.traversed_nodes_cnt) + ", f=" +
1089
StringConverter::toString(mOcclusion.frustum_culled_nodes_cnt) + ", q=" +
1090
StringConverter::toString(mOcclusion.query_cnt)
1093
#endif // _VISIBILITYDEBUG
1103
if (!mCamInProgressVisibles->empty())
1105
MovableObjectList::iterator movableIt = mCamInProgressVisibles->begin();
1106
MovableObjectList::iterator mitend = mCamInProgressVisibles->end();
1107
while (movableIt != mitend)
1109
(*movableIt)->_updateRenderQueue (q);
1114
#ifdef _VISIBILITYDEBUG
1117
mPagingLandScapeOctree->traversal (TreeOverlayDebug (mOcclusion, this), visibleBounds);
1119
#endif // _VISIBILITYDEBUG
1122
//---------------------------------------------------------------------
1123
void PagingLandScapeOctreeSceneManager::addVisible(MovableObject *mo)
1125
mCamInProgressVisibles->push_back (mo);
1127
//---------------------------------------------------------------------
1128
void PagingLandScapeOctreeSceneManager::directRenderSingleQueue(RenderQueue *queue)
1130
RenderQueue *oldQueue = mRenderQueue;
1131
mRenderQueue = queue;
1133
SceneManager::_renderVisibleObjects ();
1136
mRenderQueue = oldQueue;
1138
//---------------------------------------------------------------------
1139
void PagingLandScapeOctreeSceneManager::directRenderSingleObject(Renderable *r)
1141
const Camera * const c_cam = mCameraInProgress;
1142
mDestRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
1143
// mDestRenderSystem->_setViewMatrix(c_cam->getViewMatrix());
1144
// mDestRenderSystem->_setProjectionMatrix(c_cam->getProjectionMatrix());
1146
mDestRenderSystem->setCurrentPassIterationCount(1);
1147
_setPass(r->getMaterial()->getBestTechnique()->getPass(0));
1148
useRenderableViewProjMode (r);
1151
r->getRenderOperation (ro);
1152
mDestRenderSystem->_render(ro);
1155
//---------------------------------------------------------------------
1156
void PagingLandScapeOctreeSceneManager::registerCamera (PagingLandScapeOctreeCamera *c)
1158
mPagingLandScapeOctree->traversal(RegisterCameraTraversal(c), 0);
1160
//---------------------------------------------------------------------
1161
// --- non template versions
1162
void _findNodes(const AxisAlignedBox &t, std::list < SceneNode * > &list,
1163
const Ogre::SceneNode * const exclude, const bool full, PagingLandScapeOctree *octant)
1169
AxisAlignedBox obox;
1170
octant->_getCullBounds(&obox);
1172
const Intersection isect = intersect(t, obox);
1174
if (isect == OUTSIDE)
1177
isFull = (isect == INSIDE);
1181
const bool b_full = isFull;
1182
NodeList::iterator it = octant->mNodes.begin();
1184
while (it != octant->mNodes.end())
1186
PagingLandScapeOctreeNode * const on = (*it);
1197
const Intersection nsect = intersect(t, on->_getWorldAABB());
1199
if (nsect != OUTSIDE)
1212
if (octant->mChildren[ 0 ][ 0 ][ 0 ] != 0)
1213
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 0 ]);
1215
if (octant->mChildren[ 1 ][ 0 ][ 0 ] != 0)
1216
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 0 ]);
1218
if (octant->mChildren[ 0 ][ 1 ][ 0 ] != 0)
1219
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 0 ]);
1221
if (octant->mChildren[ 1 ][ 1 ][ 0 ] != 0)
1222
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 0 ]);
1224
if (octant->mChildren[ 0 ][ 0 ][ 1 ] != 0)
1225
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 1 ]);
1227
if (octant->mChildren[ 1 ][ 0 ][ 1 ] != 0)
1228
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 1 ]);
1230
if (octant->mChildren[ 0 ][ 1 ][ 1 ] != 0)
1231
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 1 ]);
1233
if (octant->mChildren[ 1 ][ 1 ][ 1 ] != 0)
1234
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 1 ]);
1237
//---------------------------------------------------------------------
1238
void _findNodes(const Sphere &t, std::list < SceneNode * > &list,
1239
const SceneNode * const exclude,
1240
const bool full, PagingLandScapeOctree *octant)
1245
AxisAlignedBox obox;
1246
octant->_getCullBounds(&obox);
1248
const Intersection isect = intersect(t, obox);
1250
if (isect == OUTSIDE)
1253
isFull = (isect == INSIDE);
1256
const bool b_full = isFull;
1257
NodeList::iterator it = octant->mNodes.begin();
1259
while (it != octant->mNodes.end())
1261
PagingLandScapeOctreeNode * const on = (*it);
1272
const Intersection nsect = intersect(t, on->_getWorldAABB());
1274
if (nsect != OUTSIDE)
1287
if (octant->mChildren[ 0 ][ 0 ][ 0 ] != 0)
1288
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 0 ]);
1290
if (octant->mChildren[ 1 ][ 0 ][ 0 ] != 0)
1291
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 0 ]);
1293
if (octant->mChildren[ 0 ][ 1 ][ 0 ] != 0)
1294
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 0 ]);
1296
if (octant->mChildren[ 1 ][ 1 ][ 0 ] != 0)
1297
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 0 ]);
1299
if (octant->mChildren[ 0 ][ 0 ][ 1 ] != 0)
1300
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 1 ]);
1302
if (octant->mChildren[ 1 ][ 0 ][ 1 ] != 0)
1303
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 1 ]);
1305
if (octant->mChildren[ 0 ][ 1 ][ 1 ] != 0)
1306
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 1 ]);
1308
if (octant->mChildren[ 1 ][ 1 ][ 1 ] != 0)
1309
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 1 ]);
1312
//---------------------------------------------------------------------
1313
void _findNodes(const PlaneBoundedVolume &t, std::list < SceneNode * > &list,
1314
const Ogre::SceneNode * const exclude, const bool full, PagingLandScapeOctree *octant)
1320
AxisAlignedBox obox;
1321
octant->_getCullBounds(&obox);
1323
const Intersection isect = intersect(t, obox);
1325
if (isect == OUTSIDE)
1328
isFull = (isect == INSIDE);
1332
const bool b_full = isFull;
1333
NodeList::iterator it = octant->mNodes.begin();
1335
while (it != octant->mNodes.end())
1337
PagingLandScapeOctreeNode * const on = (*it);
1346
const Intersection nsect = intersect(t, on->_getWorldAABB());
1348
if (nsect != OUTSIDE)
1357
if (octant->mChildren[ 0 ][ 0 ][ 0 ] != 0)
1358
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 0 ]);
1360
if (octant->mChildren[ 1 ][ 0 ][ 0 ] != 0)
1361
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 0 ]);
1363
if (octant->mChildren[ 0 ][ 1 ][ 0 ] != 0)
1364
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 0 ]);
1366
if (octant->mChildren[ 1 ][ 1 ][ 0 ] != 0)
1367
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 0 ]);
1369
if (octant->mChildren[ 0 ][ 0 ][ 1 ] != 0)
1370
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 1 ]);
1372
if (octant->mChildren[ 1 ][ 0 ][ 1 ] != 0)
1373
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 1 ]);
1375
if (octant->mChildren[ 0 ][ 1 ][ 1 ] != 0)
1376
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 1 ]);
1378
if (octant->mChildren[ 1 ][ 1 ][ 1 ] != 0)
1379
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 1 ]);
1382
//---------------------------------------------------------------------
1383
void _findNodes(const Ray &t, std::list < SceneNode * > &list,
1384
const Ogre::SceneNode * const exclude,
1385
const bool full, PagingLandScapeOctree *octant)
1390
AxisAlignedBox obox;
1391
octant->_getCullBounds(&obox);
1393
const Intersection isect = intersect(t, obox);
1395
if (isect == OUTSIDE)
1398
isFull = (isect == INSIDE);
1402
const bool b_full = isFull;
1403
if (!octant->mNodes.empty ())
1405
NodeList::iterator it = octant->mNodes.begin();
1406
while (it != octant->mNodes.end())
1408
PagingLandScapeOctreeNode * const on = (*it);
1417
const Intersection nsect = intersect(t, on->_getWorldAABB());
1418
if (nsect != OUTSIDE)
1425
if (octant->hasChildren ())
1427
if (octant->mChildren[ 0 ][ 0 ][ 0 ] != 0)
1428
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 0 ]);
1430
if (octant->mChildren[ 1 ][ 0 ][ 0 ] != 0)
1431
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 0 ]);
1433
if (octant->mChildren[ 0 ][ 1 ][ 0 ] != 0)
1434
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 0 ]);
1436
if (octant->mChildren[ 1 ][ 1 ][ 0 ] != 0)
1437
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 0 ]);
1439
if (octant->mChildren[ 0 ][ 0 ][ 1 ] != 0)
1440
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 0 ][ 1 ]);
1442
if (octant->mChildren[ 1 ][ 0 ][ 1 ] != 0)
1443
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 0 ][ 1 ]);
1445
if (octant->mChildren[ 0 ][ 1 ][ 1 ] != 0)
1446
_findNodes(t, list, exclude, b_full, octant->mChildren[ 0 ][ 1 ][ 1 ]);
1448
if (octant->mChildren[ 1 ][ 1 ][ 1 ] != 0)
1449
_findNodes(t, list, exclude, b_full, octant->mChildren[ 1 ][ 1 ][ 1 ]);
1452
//---------------------------------------------------------------------
1453
void PagingLandScapeOctreeSceneManager::findNodesIn(const AxisAlignedBox &box, std::list < SceneNode * > &list, const SceneNode* const exclude)
1455
_findNodes(box, list, exclude, false, mPagingLandScapeOctree);
1457
//---------------------------------------------------------------------
1458
void PagingLandScapeOctreeSceneManager::findNodesIn(const Sphere &sphere, std::list < SceneNode * > &list, const SceneNode* const exclude)
1460
_findNodes(sphere, list, exclude, false, mPagingLandScapeOctree);
1462
//---------------------------------------------------------------------
1463
void PagingLandScapeOctreeSceneManager::findNodesIn(const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, const SceneNode* const exclude)
1465
_findNodes(volume, list, exclude, false, mPagingLandScapeOctree);
1467
//---------------------------------------------------------------------
1468
void PagingLandScapeOctreeSceneManager::findNodesIn(const Ray &r, std::list < SceneNode * > &list, const SceneNode* const exclude)
1470
_findNodes(r, list, exclude, false, mPagingLandScapeOctree);
1472
//---------------------------------------------------------------------
1473
void PagingLandScapeOctreeSceneManager::resize(const AxisAlignedBox &box, const int depth)
1478
//---------------------------------------------------------------------
1479
void PagingLandScapeOctreeSceneManager::resize(const AxisAlignedBox &box)
1481
std::list < SceneNode * > nodes;
1483
_findNodes(mPagingLandScapeOctree->getBoundingBox (), nodes, 0, true, mPagingLandScapeOctree);
1485
if (mPagingLandScapeOctree)
1486
deleteOctree (mPagingLandScapeOctree);
1489
mPagingLandScapeOctree = mOctreeSet.getPoolable();
1490
assert (mPagingLandScapeOctree);
1491
mPagingLandScapeOctree->setSceneManager (this);
1492
mPagingLandScapeOctree ->setBoundingBox (box.getMinimum(), box.getMaximum());
1493
registeredNodeInCamera (mPagingLandScapeOctree);
1497
std::list < SceneNode * > ::iterator it;
1500
while (it != nodes.end())
1502
PagingLandScapeOctreeNode * const on = static_cast < PagingLandScapeOctreeNode * > (*it);
1504
_updatePagingLandScapeOctreeNode(on);
1506
} // while (it != nodes.end())
1509
//---------------------------------------------------------------------
1510
bool PagingLandScapeOctreeSceneManager::setOption(const String & key, const void * val)
1514
resize(* static_cast < const AxisAlignedBox * > (val));
1518
else if (key == "Depth")
1520
assert (mPagingLandScapeOctree);
1521
mMaxDepth = * static_cast < const int * > (val);
1522
// copy the box since resize will delete mOctree and reference won't work
1523
AxisAlignedBox box = mPagingLandScapeOctree->getBoundingBox();
1527
else if (key == "NextCullMode")
1531
CameraList::iterator it = mCameras.find (static_cast < const PagingLandScapeOctreeCamera * > (val)->getName());
1532
if (it != mCameras.end())
1534
static_cast < PagingLandScapeOctreeCamera * > (it->second)->setNextOcclusionMode();
1540
else if (key == "setNumberOfConservativeFrames")
1542
mOcclusion.setNumberOfConservativeFrames(*(static_cast < const unsigned int * > (val)));
1544
else if (key == "CurrentOptionCamera")
1548
CameraList::iterator it = mCameras.find (static_cast < const PagingLandScapeOctreeCamera * > (val)->getName());
1549
if (it != mCameras.end())
1551
mCurrentOptionCamera = static_cast < PagingLandScapeOctreeCamera * > (it->second);
1556
else if (key == "setCullingMode")
1558
assert (mCurrentOptionCamera);
1559
mCurrentOptionCamera->setOcclusionModeAsString(* static_cast < const String * > (val));
1562
#ifdef _VISIBILITYDEBUG
1563
else if (key == "ShowPagingLandScapeOctree")
1565
mShowBoxes = * static_cast < const bool * > (val);
1568
else if (key == "CullDebug")
1570
mCullDebug = * static_cast < const bool * > (val);
1573
else if (key == "CullCamera")
1575
mCullCamera = * static_cast < const bool * > (val);
1578
#endif //_VISIBILITYDEBUG
1579
return SceneManager::setOption(key, val);
1583
//---------------------------------------------------------------------
1584
bool PagingLandScapeOctreeSceneManager::getOption(const String & key, void *val)
1588
AxisAlignedBox * b = static_cast < AxisAlignedBox * > (val);
1589
b->setExtents(mPagingLandScapeOctree->getBoundingBox ().getMinimum(), mPagingLandScapeOctree->getBoundingBox().getMaximum());
1593
else if (key == "Depth")
1595
* static_cast < int * > (val) = mMaxDepth;
1598
else if (key == "setNumberOfConservativeFrames")
1600
* static_cast < unsigned int * > (val) = mOcclusion.getNumberOfConservativeFrames();
1603
else if (key == "CurrentOptionCamera")
1605
*static_cast < String * > (val) = mCurrentOptionCamera->getName();
1608
else if (key == "getCullingMode")
1610
assert (mCurrentOptionCamera);
1611
*static_cast < String * > (val) = mCurrentOptionCamera->getOcclusionModeAsString();
1615
#ifdef _VISIBILITYDEBUG
1616
else if (key == "ShowPagingLandScapeOctree")
1619
* static_cast < bool * > (val) = mShowBoxes;
1622
else if (key == "CullCamera")
1624
* static_cast < bool * > (val) = mCullCamera;
1627
else if (key == "CullDebug")
1629
* static_cast < bool * > (val) = mCullDebug;
1632
else if (key == "DebugText")
1634
* static_cast < String * > (val) = mDebugText;
1637
#endif //_VISIBILITYDEBUG
1639
return SceneManager::getOption(key, val);
1641
//---------------------------------------------------------------------
1642
void PagingLandScapeOctreeSceneManager::clearScene(void)
1644
SceneManager::clearScene();
1647
//CameraList::iterator iCam = mCameras.begin();
1648
//for (; iCam != mCameras.end(); ++iCam)
1650
// PagingLandScapeOctreeCamera *cam = static_cast <PagingLandScapeOctreeCamera *> (iCam->second);
1651
// if (cam->isRegisteredInOcclusionSystem ())
1653
// mPagingLandScapeOctree->traversal (UnregisterCameraTraversal(cam));
1654
// cam->setRegisteredInOcclusionSystem (false);
1658
init(mBox, mMaxDepth);
1661
//---------------------------------------------------------------------
1662
AxisAlignedBoxSceneQuery*
1663
PagingLandScapeOctreeSceneManager::createAABBQuery(const AxisAlignedBox& box, unsigned long mask)
1665
PagingLandScapeOctreeAxisAlignedBoxSceneQuery* q = new PagingLandScapeOctreeAxisAlignedBoxSceneQuery(this);
1667
q->setQueryMask(mask);
1670
//---------------------------------------------------------------------
1672
PagingLandScapeOctreeSceneManager::createSphereQuery(const Sphere& sphere, unsigned long mask)
1674
PagingLandScapeOctreeSphereSceneQuery* q = new PagingLandScapeOctreeSphereSceneQuery(this);
1675
q->setSphere(sphere);
1676
q->setQueryMask(mask);
1679
//---------------------------------------------------------------------
1680
PlaneBoundedVolumeListSceneQuery*
1681
PagingLandScapeOctreeSceneManager::createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes,
1684
PagingLandScapeOctreePlaneBoundedVolumeListSceneQuery* q = new PagingLandScapeOctreePlaneBoundedVolumeListSceneQuery(this);
1685
q->setVolumes(volumes);
1686
q->setQueryMask(mask);
1690
//---------------------------------------------------------------------
1692
PagingLandScapeOctreeSceneManager::createRayQuery(const Ray& ray, unsigned long mask)
1694
PagingLandScapeOctreeRaySceneQuery* q = new PagingLandScapeOctreeRaySceneQuery(this);
1696
q->setQueryMask(mask);
1699
//---------------------------------------------------------------------
1700
IntersectionSceneQuery*
1701
PagingLandScapeOctreeSceneManager::createIntersectionQuery(unsigned long mask)
1704
// PagingLandScapeOctree implementation performs WORSE for < 500 objects
1705
// TODO: optimize it so it's better in all cases
1706
//PagingLandScapeOctreeIntersectionSceneQuery* q = new PagingLandScapeOctreeIntersectionSceneQuery(this);
1707
DefaultIntersectionSceneQuery* q;
1708
if (mPagingLandScapeOctree->numNodes () > 500)
1709
q = new PagingLandScapeOctreeIntersectionSceneQuery(this);
1711
q = new DefaultIntersectionSceneQuery(this);
1712
q->setQueryMask(mask);