source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h @ 3257

Revision 3257, 1.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __VIEWCELLSTREE
2#define __VIEWCELLSTREE
3
4#include <vector>
5#include "Pvs.h"
6#include "AxisAlignedBox3.h"
7#include "common.h"
8
9       
10namespace CHCDemoEngine
11{
12
13/** basic view cell structure
14*/
15struct ViewCell
16{
17public:
18
19        ViewCell(): mPvs() {}
20
21        int GetId() const { return mId; }
22
23        void SetId(int id) { mId = id; }
24
25        void SetBox(const AxisAlignedBox3 &box) { mBox = box; }
26
27        AxisAlignedBox3 GetBox() const { return mBox; }
28
29        // the pvs associated with the viewcell
30        Pvs mPvs;
31
32protected:
33
34        // id of this viewcell
35        int mId;
36        // bounding box of the viewcell
37        AxisAlignedBox3 mBox;
38};
39
40
41struct ViewCellsTreeNode
42{
43        ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {}
44
45        bool IsLeaf() { return mAxis == -1; }
46
47
48        ///////////////////////
49
50        /// split mAxis
51        int mAxis;
52
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        };
60
61        /// children of the node
62        ViewCellsTreeNode *mBack;
63        ViewCellsTreeNode *mFront;
64};
65
66
67class ViewCellsTree
68{
69        friend class VisibilitySolutionLoader;
70
71public:
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;
85       
86        /** Hack: Sometimes the scene has to be scaled, then also
87                the view cells must be scaled accordingly.
88        */
89        bool LoadFromFile(const std::string &filename, float scaleFactor = 1.0f);
90       
91
92protected:
93
94        bool _LoadFromFile(FILE *file, float scaleFactor);
95
96
97        ////////////////////////
98
99        int mMaxDepth;
100        AxisAlignedBox3 mBox;
101        ViewCellsTreeNode *mRoot;
102};
103
104}
105
106#endif
Note: See TracBrowser for help on using the repository browser.