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