1 | 1) include following libs into your application: |
---|
2 | |
---|
3 | Preprocessor.lib zdll.lib zziplib.lib xerces-c_2.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib glew32.lib glew32s.lib |
---|
4 | |
---|
5 | |
---|
6 | 2) view cells are loaded using a similar piece of code like this: |
---|
7 | |
---|
8 | OctreeBoundingBoxConverter bconverter(this); |
---|
9 | ObjectContainer objects; |
---|
10 | |
---|
11 | // load the view cells assigning the found objects to the pvss |
---|
12 | |
---|
13 | GtpVisibilityPreprocessor::ViewCellsManager *viewCellsManager = |
---|
14 | GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &objects, &bconverter); |
---|
15 | |
---|
16 | The bouning box converter is used to associate entities in the |
---|
17 | engine and connect them to entities of the visibility |
---|
18 | preprocessing file. |
---|
19 | |
---|
20 | 3) The parameter objects: |
---|
21 | |
---|
22 | The parameter objects of the type ObjectContainer contains the primitives which |
---|
23 | will be set visible / invisible accoring to the pvs. |
---|
24 | |
---|
25 | They are given as pointers to an Intersectable. |
---|
26 | It is therefore necessary to write wrapper for the primitives in |
---|
27 | your engine. Something like: |
---|
28 | |
---|
29 | |
---|
30 | /** |
---|
31 | Wrapper for Ogre object intances for use with the preprocessed view cells. |
---|
32 | */ |
---|
33 | class __declspec(dllexport) OgreMeshInstance: public GtpVisibilityPreprocessor::Intersectable |
---|
34 | { |
---|
35 | public: |
---|
36 | /** The default constructor taking an entity into account. |
---|
37 | */ |
---|
38 | OgreMeshInstance(Entity *ent); |
---|
39 | |
---|
40 | /** Returns 'mesh' associated with this instance. |
---|
41 | */ |
---|
42 | Entity *GetEntity() const; |
---|
43 | |
---|
44 | /** See get. |
---|
45 | */ |
---|
46 | void SetEntity(Entity *entity); |
---|
47 | |
---|
48 | |
---|
49 | ///////////////////////////// |
---|
50 | //-- inherited functions from Intersectable |
---|
51 | |
---|
52 | GtpVisibilityPreprocessor::AxisAlignedBox3 GetBox() const; |
---|
53 | |
---|
54 | int CastRay(GtpVisibilityPreprocessor::Ray &ray); |
---|
55 | |
---|
56 | bool IsConvex() const; |
---|
57 | bool IsWatertight() const; |
---|
58 | float IntersectionComplexity(); |
---|
59 | |
---|
60 | int NumberOfFaces() const; |
---|
61 | int Type() const; |
---|
62 | |
---|
63 | int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, |
---|
64 | GtpVisibilityPreprocessor::Vector3 &normal); |
---|
65 | |
---|
66 | int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, |
---|
67 | GtpVisibilityPreprocessor::Vector3 &normal, |
---|
68 | const GtpVisibilityPreprocessor::Vector3 &viewpoint, |
---|
69 | const int maxTries); |
---|
70 | |
---|
71 | ostream &Describe(ostream &s); |
---|
72 | |
---|
73 | |
---|
74 | protected: |
---|
75 | |
---|
76 | Entity *mEntity; |
---|
77 | }; |
---|
78 | |
---|
79 | |
---|
80 | 4) The bounding box converter has to implement the following interface: |
---|
81 | |
---|
82 | |
---|
83 | /** Class used to assign unique indices to objects using a comparison of bounding boxes. |
---|
84 | */ |
---|
85 | class BoundingBoxConverter |
---|
86 | { |
---|
87 | public: |
---|
88 | /** Takes a vector of indexed bounding boxes and uses it to identify objects with a similar bounding box |
---|
89 | and to assign them their index (id). |
---|
90 | The objects are returned in the object container. |
---|
91 | |
---|
92 | @returns true if conversion was successful |
---|
93 | */ |
---|
94 | virtual bool IdentifyObjects(const IndexedBoundingBoxContainer &iboxes, |
---|
95 | ObjectContainer &objects) const |
---|
96 | { |
---|
97 | // default: do nothing as we assume that a unique id is already assigned to the objects. |
---|
98 | return true; |
---|
99 | } |
---|
100 | }; |
---|
101 | |
---|
102 | |
---|
103 | The interface only contains the method IdentifyObjects, which will be |
---|
104 | responsible for the conversion. |
---|
105 | |
---|
106 | 5) The ViewCellsManager: |
---|
107 | |
---|
108 | This class is there to control the view cells. You can get a view |
---|
109 | point by using something like the following: |
---|
110 | |
---|
111 | GtpVisibilityPreprocessor::Vector3 viewPoint; |
---|
112 | |
---|
113 | ViewCell *currentViewCell = viewCellsManager->GetViewCell(const Vector3 &viewPoint); |
---|
114 | |
---|
115 | |
---|
116 | 6) The view cell: the Pvs of the current view cell can be received by using |
---|
117 | |
---|
118 | ObjectPvs pvs = viewCell->GetPvs(); |
---|
119 | |
---|
120 | Then objects of the pvs can be iterated over and set visibible like in |
---|
121 | this example for Ogre: |
---|
122 | |
---|
123 | |
---|
124 | GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator oit, oit_end = viewCell->GetPvs().mEntries.end(); |
---|
125 | |
---|
126 | //////////// |
---|
127 | //-- set PVS of view cell to visible |
---|
128 | |
---|
129 | for (oit = viewCell->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) |
---|
130 | { |
---|
131 | GtpVisibilityPreprocessor::Intersectable *entry = (*oit).first; |
---|
132 | // no associated geometry found |
---|
133 | if (!entry) continue; |
---|
134 | |
---|
135 | OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(entry); |
---|
136 | omi->GetEntity()->setVisible(load); |
---|
137 | } |
---|