1 | #ifndef __PVS_H
|
---|
2 | #define __PVS_H
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "Bvh.h"
|
---|
6 |
|
---|
7 | namespace CHCDemoEngine
|
---|
8 | {
|
---|
9 |
|
---|
10 | class BvhNode;
|
---|
11 | class Bvh;
|
---|
12 |
|
---|
13 | struct PvsEntry
|
---|
14 | {
|
---|
15 | PvsEntry(SceneEntity *ent, float t):
|
---|
16 | mEntity(ent)
|
---|
17 | //, mTimeStamp(t)
|
---|
18 | {}
|
---|
19 |
|
---|
20 | friend bool operator<(const PvsEntry &a, const PvsEntry &b);
|
---|
21 |
|
---|
22 |
|
---|
23 | ///////////////
|
---|
24 |
|
---|
25 | SceneEntity *mEntity;
|
---|
26 | //float mTimeStamp;
|
---|
27 | };
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | typedef std::vector<PvsEntry> PvsEntryContainer;
|
---|
33 |
|
---|
34 |
|
---|
35 | /** Class representing the Potentially Visible Set (PVS) from a view cell.
|
---|
36 | */
|
---|
37 | class Pvs
|
---|
38 | {
|
---|
39 | public:
|
---|
40 |
|
---|
41 | void Clear();
|
---|
42 |
|
---|
43 | bool Empty() const;
|
---|
44 | /** Convencience method adding all scene entities associated with a bvh node.
|
---|
45 | */
|
---|
46 | void AddEntry(Bvh *bvh, BvhNode *node, float timeStamp = -1);
|
---|
47 |
|
---|
48 | int GetSize() const;
|
---|
49 |
|
---|
50 | inline SceneEntity *GetEntity(int i) const;
|
---|
51 |
|
---|
52 | inline PvsEntry GetEntry(int i) const;
|
---|
53 |
|
---|
54 | inline void AddEntry(const PvsEntry &entry);
|
---|
55 | /* Sort entries by timestamp
|
---|
56 | */
|
---|
57 | void Sort();
|
---|
58 |
|
---|
59 |
|
---|
60 | protected:
|
---|
61 |
|
---|
62 | /// vector of PVS entries
|
---|
63 | PvsEntryContainer mEntries;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | inline SceneEntity *Pvs::GetEntity(int i) const
|
---|
68 | {
|
---|
69 | return mEntries[i].mEntity;
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | inline PvsEntry Pvs::GetEntry(int i) const
|
---|
74 | {
|
---|
75 | return mEntries[i];
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | inline void Pvs::AddEntry(const PvsEntry &entry)
|
---|
80 | {
|
---|
81 | mEntries.push_back(entry);
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | inline int Pvs::GetSize() const
|
---|
86 | {
|
---|
87 | return (int)mEntries.size();
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | inline void Pvs::AddEntry(Bvh *bvh, BvhNode *node, float timeStamp)
|
---|
92 | {
|
---|
93 | int geometrySize;
|
---|
94 | SceneEntity **entities;
|
---|
95 | entities = bvh->GetGeometry(node, geometrySize);
|
---|
96 |
|
---|
97 | for (int i = 0; i < geometrySize; ++ i)
|
---|
98 | {
|
---|
99 | AddEntry(PvsEntry(entities[i], timeStamp));
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | #endif |
---|