source: branches/VUT/0.3/obsolete/OcclusionCullingSceneManager/include/OgreOcclusionCullingOctreeSceneTraverser.h @ 52

Revision 52, 2.9 KB checked in by mattausch, 20 years ago (diff)
Line 
1#ifndef _OcclusionCullingOctreeSceneTraverser_H__
2#define _OcclusionCullingOctreeSceneTraverser_H__
3
4#include "OgreOctree.h"
5#include "OgreOcclusionCullingSceneTraverser.h"
6
7using namespace std;
8
9namespace Ogre {
10        /**
11                This class implements the compare operator for the priority queue
12                especially for octree hierarchies using getCullBounds for bounding
13                box computation. A lower distance has a higher value in the queue.
14        */
15        template <typename T> class octreeless
16        {
17        public:
18                octreeless(Camera *cam) { mCamera = cam; }
19               
20                bool operator() (T v1, T v2) const
21                {
22                        AxisAlignedBox box1, box2;
23                        v1->_getCullBounds(&box1);
24                        v2->_getCullBounds(&box2);
25
26                        return getSquaredViewDepth(mCamera, &box1) > getSquaredViewDepth(mCamera, &box2);
27                }
28
29        private:
30                Real getSquaredViewDepth(const Ogre::Camera* cam, const Ogre::AxisAlignedBox* box) const
31                {
32                        Vector3 mid  = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
33                        return (cam->getDerivedPosition() - mid).squaredLength();                                                                   
34                }
35
36                Camera *mCamera;
37                //AxisAlignedBox mBox1, mBox2;
38                //Ogre::Vector3 min, max, mid, dist;
39        };
40
41        typedef pair<Octree *, HardwareOcclusionQuery *> OctreeQueryPair;
42        typedef priority_queue<Octree *, vector<Octree *>, octreeless<vector<Octree *>::value_type> > OctreePriorityQueue;
43        typedef queue<OctreeQueryPair> OctreeQueryQueue;
44
45        class OcclusionCullingOctreeSceneTraverser: public OcclusionCullingSceneTraverser
46        {
47        public:
48                OcclusionCullingOctreeSceneTraverser(SceneManager *sm, RenderSystem *rsys);
49                ~OcclusionCullingOctreeSceneTraverser();
50                //void renderScene( Camera *cam );
51                void setSceneRoot(Octree *root);
52                /** Sets the number of nodes in this octree
53                @remark do not confuse this with the OctreeNode class
54                which is derived from SceneNode
55                @param num number of nodes in the octree
56                */
57                void setNumOctreeNodes( unsigned int num );
58       
59                /** Gets the given option for the scene traverser.
60                @remarks
61                    See setOption
62                */
63                bool getOption( const String &, void * );
64                bool getOptionKeys( StringVector &refKeys );
65               
66        protected:
67                /** Renders the scene with view frustum culling only. */
68                void renderCullFrustum( Camera *cam );
69                /** Renders the scene with the hierarchical stop and wait algorithm. */
70                void renderStopAndWait( Camera *cam );
71                /** Renders the scene with the coherent hierarchical algorithm and the query queye. */
72                void renderCoherentWithQueue( Camera *cam );
73                /** Issue a occlusion query for this node. */
74               
75                void initDistanceQueue(Camera *cam);
76                void pullUpVisibility(Octree *octree);
77                void traverseOctant(Camera *cam, Octree *octant);
78                void renderOctant(Camera *cam, Octree *octant);
79                bool isLeaf(Octree *octant);
80
81        private:
82                OctreePriorityQueue *mOctreeDistanceQueue;
83                // the octree root
84                Octree *mOctreeSceneRoot;
85
86                unsigned int mNumOctreeNodes;
87        };
88
89}
90#endif // OcclusionCullingOctreeSceneTraverser_H
Note: See TracBrowser for help on using the repository browser.