source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBihRenderable.h @ 2385

Revision 2385, 3.6 KB checked in by vizrt_christian_seidl, 17 years ago (diff)

Added some members for BIH

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the GameTools Project
4http://www.gametools.org
5
6Author: Martin Szydlowski
7-----------------------------------------------------------------------------
8*/
9
10#ifndef _OgreBihRenderable_H__
11#define _OgreBihRenderable_H__
12
13#include "OgreBiHierarchy.h"
14
15namespace Ogre
16{
17
18        // interface which must be implemented by all objects which desire to be
19        // placed in the kd-tree
20        class BihRenderable
21        {
22        public:
23                BihRenderable():mSide(BihPlaneEvent::PES_BOTH), mClassified(false), mLastQueued(0), mBiHierarchy(0)
24                {
25                        setDecided(0,false); setDecided(1,false); setDecided(2,false);
26            };
27                virtual ~BihRenderable()
28                {
29                        if (mBiHierarchy)
30                                mBiHierarchy->remove(this);
31                }
32
33                // gather the information required for the creation of the kd-tree
34                virtual void computeScene(BihPlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren = true) = 0;
35
36                // put all objects this element holds in the renedering queue
37                virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters) = 0;
38
39                // place all entities in geometry queue (for CHC)
40                virtual void getGeometryList(GeometryVector *geometryList) = 0;
41
42                // return a bounding box enclosing all objects
43                virtual AxisAlignedBox getBoundingBox() const = 0;
44
45                // TODO: reconsider getters/setters !!!
46                inline bool isClassified()
47                {
48                        return mClassified;
49                };
50                inline void setClassified(bool q)
51                {
52                        mClassified = q;
53                };
54
55                inline  isDecided(int w)
56                {
57                        return mDecided[w];
58                };
59                inline void setDecided(int w,bool b)
60                {
61                        mDecided[w] = b;
62                };
63
64                inline BihPlaneEvent::Side getSide()
65                {
66                        return mSide;
67                };
68                inline void setSide(BihPlaneEvent::Side s)
69                {
70                        mSide = s;
71                };
72
73                // funcions for attachment/detachment of renderables to/from the kd-tree
74                inline bool isAttached()
75                {
76                        return mLeaves.size() != 0;
77                };
78                // the following functions should work in O(log N)
79                inline bool isAttached(BiHierarchy::LeafPtr leaf)
80                {
81                        return mLeaves.find(leaf) != mLeaves.end();
82                };
83                inline bool attachTo(BiHierarchy::LeafPtr leaf, BiHierarchy * BiHierarchy)
84                {
85                        if (mBiHierarchy == 0 || mBiHierarchy == BiHierarchy)
86                                mBiHierarchy = BiHierarchy;
87                        else
88                                return false;
89
90                        BiHierarchy::LeafSet::_Pairib p = mLeaves.insert(leaf);
91                        return p.second;
92                };
93                inline bool detachFrom(BiHierarchy::LeafPtr leaf)
94                {
95                        bool success = (mLeaves.erase(leaf) == 1);
96                        if (mLeaves.size() == 0)
97                                mBiHierarchy = 0;
98
99                        return success;
100                };
101
102                inline bool isQueued(unsigned long currentFrame, Camera * currentCam)
103                {
104                        if (mLastQueued == currentFrame && mLastCam == currentCam)
105                        {
106                                return true;
107                        }
108                        else
109                        {
110                                mLastQueued = currentFrame;
111                                mLastCam = currentCam;
112                                return false;
113                        }
114                };
115
116                BiHierarchy::LeafSet& getLeaves()
117                {
118                        return mLeaves;
119                };
120
121        protected:
122                // number of the frame in which this renderable was last queued for rendering
123                unsigned long mLastQueued;
124                // the camera for which this renderable was last queued for rendering
125                Camera * mLastCam;
126               
127                // BiHierarchy to which this renderable is attached
128                BiHierarchy * mBiHierarchy;
129                // BiHierarchy leaves which overlap this renderable
130                BiHierarchy::LeafSet mLeaves;
131
132                // Flag for the SAH determining the "cheaper" side of the split plane
133                BihPlaneEvent::Side mSide;
134                // Flag for the SAH which marks if this renderable was already placed in the list after a split
135                bool mClassified;
136
137                bool mDecided[3];
138        }; // class BihRenderable
139
140} // namespace Ogre
141
142#endif // _OgreBihRenderable_H__
Note: See TracBrowser for help on using the repository browser.