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

Revision 3242, 1.5 KB checked in by mattausch, 15 years ago (diff)
Line 
1#ifndef __VIEWCELLSTREE
2#define __VIEWCELLSTREE
3
4#include <vector>
5#include "Pvs.h"
6#include "AxisAlignedBox3.h"
7
8
9       
10namespace CHCDemoEngine
11{
12
13/** basic view cell structure
14*/
15struct ViewCell
16{
17public:
18
19        ViewCell(): mPvs() {}
20
21protected:
22
23        // id of this viewcell
24        int mId;
25        // bounding box of the viewcell
26        AxisAlignedBox3 mBox;
27        // the pvs associated with the viewcell
28        Pvs mPvs;
29
30};
31
32
33struct ViewCellsTreeNode
34{
35        union
36        {
37                // split position - 4B
38                float position;
39                // the viewcell associated with this node (NULL for non terminal nodes) - 4B
40                ViewCell *viewCell;
41        };
42
43
44        ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {}
45
46        bool IsLeaf() { return mAxis == -1; }
47
48        bool IsVirtualLeaf() { return mViewCell != NULL; }
49
50
51        ///////////////////////
52
53        // children of the node - 8B
54        ViewCellsTreeNode *mBack, *mFront;
55
56        // kd tree split params
57        // split axis - 4B
58        int mAxis;
59};
60
61
62class ViewCellsTree
63{
64public:
65       
66        ViewCellsTree(): mRoot(NULL) {}
67
68        void SubdivideNode(ViewCellsTreeNode *node,
69                       const AxisAlignedBox3 &box,
70                                           int depth);
71
72
73        int     CastLineSegment(const Vector3 &origin,
74                        const Vector3 &termination,
75                                                ViewCell **viewcells);
76
77        ViewCell *GetViewCell(const Vector3 &point) const;
78
79        bool LoadFromFile(const string &filename);
80
81
82protected:
83
84        bool _LoadFromFile(FILE *file);
85
86
87        ////////////////////////
88
89        float mMaxDepth;
90        AxisAlignedBox3 mBox;
91        ViewCellsTreeNode *mRoot;
92};
93
94}
95
96#endif
Note: See TracBrowser for help on using the repository browser.