[3242] | 1 | #ifndef __VIEWCELLSTREE
|
---|
| 2 | #define __VIEWCELLSTREE
|
---|
| 3 |
|
---|
| 4 | #include <vector>
|
---|
| 5 | #include "Pvs.h"
|
---|
| 6 | #include "AxisAlignedBox3.h"
|
---|
[3243] | 7 | #include "common.h"
|
---|
[3242] | 8 |
|
---|
| 9 |
|
---|
| 10 | namespace CHCDemoEngine
|
---|
| 11 | {
|
---|
| 12 |
|
---|
| 13 | /** basic view cell structure
|
---|
| 14 | */
|
---|
| 15 | struct ViewCell
|
---|
| 16 | {
|
---|
| 17 | public:
|
---|
| 18 |
|
---|
| 19 | ViewCell(): mPvs() {}
|
---|
| 20 |
|
---|
[3243] | 21 | int GetId() const { return mId; }
|
---|
| 22 |
|
---|
| 23 | void SetId(int id) { mId = id; }
|
---|
| 24 |
|
---|
| 25 | void SetBox(const AxisAlignedBox3 &box) { mBox = box; }
|
---|
| 26 |
|
---|
[3244] | 27 | AxisAlignedBox3 GetBox() const { return mBox; }
|
---|
[3243] | 28 |
|
---|
| 29 | // the pvs associated with the viewcell
|
---|
| 30 | Pvs mPvs;
|
---|
| 31 |
|
---|
[3242] | 32 | protected:
|
---|
| 33 |
|
---|
| 34 | // id of this viewcell
|
---|
| 35 | int mId;
|
---|
| 36 | // bounding box of the viewcell
|
---|
| 37 | AxisAlignedBox3 mBox;
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | struct ViewCellsTreeNode
|
---|
| 42 | {
|
---|
| 43 | ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {}
|
---|
| 44 |
|
---|
[3244] | 45 | bool IsLeaf() { return mAxis == -1; }
|
---|
[3242] | 46 |
|
---|
| 47 |
|
---|
| 48 | ///////////////////////
|
---|
| 49 |
|
---|
[3244] | 50 | /// split mAxis
|
---|
| 51 | int mAxis;
|
---|
| 52 |
|
---|
[3243] | 53 | union
|
---|
| 54 | {
|
---|
| 55 | // split position - 4B
|
---|
| 56 | float mPosition;
|
---|
| 57 | // the viewcell associated with this node (NULL for non terminal nodes)
|
---|
| 58 | ViewCell *mViewCell;
|
---|
| 59 | };
|
---|
[3242] | 60 |
|
---|
[3243] | 61 | /// children of the node
|
---|
| 62 | ViewCellsTreeNode *mBack;
|
---|
| 63 | ViewCellsTreeNode *mFront;
|
---|
[3242] | 64 | };
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | class ViewCellsTree
|
---|
| 68 | {
|
---|
[3243] | 69 | friend class VisibilitySolutionLoader;
|
---|
| 70 |
|
---|
[3242] | 71 | public:
|
---|
| 72 |
|
---|
| 73 | ViewCellsTree(): mRoot(NULL) {}
|
---|
| 74 |
|
---|
| 75 | void SubdivideNode(ViewCellsTreeNode *node,
|
---|
| 76 | const AxisAlignedBox3 &box,
|
---|
| 77 | int depth);
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | int CastLineSegment(const Vector3 &origin,
|
---|
| 81 | const Vector3 &termination,
|
---|
| 82 | ViewCell **viewcells);
|
---|
| 83 |
|
---|
| 84 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[3257] | 85 |
|
---|
[3256] | 86 | /** Hack: Sometimes the scene has to be scaled, then also
|
---|
| 87 | the view cells must be scaled accordingly.
|
---|
| 88 | */
|
---|
[3257] | 89 | bool LoadFromFile(const std::string &filename, float scaleFactor = 1.0f);
|
---|
| 90 |
|
---|
[3242] | 91 |
|
---|
| 92 | protected:
|
---|
| 93 |
|
---|
[3257] | 94 | bool _LoadFromFile(FILE *file, float scaleFactor);
|
---|
[3242] | 95 |
|
---|
| 96 |
|
---|
| 97 | ////////////////////////
|
---|
| 98 |
|
---|
[3243] | 99 | int mMaxDepth;
|
---|
[3242] | 100 | AxisAlignedBox3 mBox;
|
---|
| 101 | ViewCellsTreeNode *mRoot;
|
---|
| 102 | };
|
---|
| 103 |
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | #endif
|
---|