#ifndef _OcclusionCullingOctreeSceneTraverser_H__ #define _OcclusionCullingOctreeSceneTraverser_H__ #include "OgreOctree.h" #include "OgreOcclusionCullingSceneTraverser.h" using namespace std; namespace Ogre { /** This class implements the compare operator for the priority queue especially for octree hierarchies using getCullBounds for bounding box computation. A lower distance has a higher value in the queue. */ template class octreeless { public: octreeless(Camera *cam) { mCamera = cam; } bool operator() (T v1, T v2) const { AxisAlignedBox box1, box2; v1->_getCullBounds(&box1); v2->_getCullBounds(&box2); return getSquaredViewDepth(mCamera, &box1) > getSquaredViewDepth(mCamera, &box2); } private: Real getSquaredViewDepth(const Ogre::Camera* cam, const Ogre::AxisAlignedBox* box) const { Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum(); return (cam->getDerivedPosition() - mid).squaredLength(); } Camera *mCamera; //AxisAlignedBox mBox1, mBox2; //Ogre::Vector3 min, max, mid, dist; }; typedef pair OctreeQueryPair; typedef priority_queue, octreeless::value_type> > OctreePriorityQueue; typedef queue OctreeQueryQueue; class OcclusionCullingOctreeSceneTraverser: public OcclusionCullingSceneTraverser { public: OcclusionCullingOctreeSceneTraverser(SceneManager *sm, RenderSystem *rsys); ~OcclusionCullingOctreeSceneTraverser(); //void renderScene( Camera *cam ); void setSceneRoot(Octree *root); /** Sets the number of nodes in this octree @remark do not confuse this with the OctreeNode class which is derived from SceneNode @param num number of nodes in the octree */ void setNumOctreeNodes( unsigned int num ); /** Gets the given option for the scene traverser. @remarks See setOption */ bool getOption( const String &, void * ); bool getOptionKeys( StringVector &refKeys ); protected: /** Renders the scene with view frustum culling only. */ void renderCullFrustum( Camera *cam ); /** Renders the scene with the hierarchical stop and wait algorithm. */ void renderStopAndWait( Camera *cam ); /** Renders the scene with the coherent hierarchical algorithm and the query queye. */ void renderCoherentWithQueue( Camera *cam ); /** Issue a occlusion query for this node. */ void initDistanceQueue(Camera *cam); void pullUpVisibility(Octree *octree); void traverseOctant(Camera *cam, Octree *octant); void renderOctant(Camera *cam, Octree *octant); bool isLeaf(Octree *octant); private: OctreePriorityQueue *mOctreeDistanceQueue; // the octree root Octree *mOctreeSceneRoot; unsigned int mNumOctreeNodes; }; } #endif // OcclusionCullingOctreeSceneTraverser_H