diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/Octree.h | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/Octree.h | 776 |
1 files changed, 388 insertions, 388 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/Octree.h b/libraries/irrlicht-1.8/source/Irrlicht/Octree.h index 2bb879d..dcccb84 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/Octree.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/Octree.h | |||
@@ -1,388 +1,388 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #ifndef __C_OCTREE_H_INCLUDED__ | 5 | #ifndef __C_OCTREE_H_INCLUDED__ |
6 | #define __C_OCTREE_H_INCLUDED__ | 6 | #define __C_OCTREE_H_INCLUDED__ |
7 | 7 | ||
8 | #include "SViewFrustum.h" | 8 | #include "SViewFrustum.h" |
9 | #include "S3DVertex.h" | 9 | #include "S3DVertex.h" |
10 | #include "aabbox3d.h" | 10 | #include "aabbox3d.h" |
11 | #include "irrArray.h" | 11 | #include "irrArray.h" |
12 | #include "CMeshBuffer.h" | 12 | #include "CMeshBuffer.h" |
13 | 13 | ||
14 | /** | 14 | /** |
15 | Flags for Octree | 15 | Flags for Octree |
16 | */ | 16 | */ |
17 | //! use meshbuffer for drawing, enables VBO usage | 17 | //! use meshbuffer for drawing, enables VBO usage |
18 | #define OCTREE_USE_HARDWARE false | 18 | #define OCTREE_USE_HARDWARE false |
19 | //! use visibility information together with VBOs | 19 | //! use visibility information together with VBOs |
20 | #define OCTREE_USE_VISIBILITY true | 20 | #define OCTREE_USE_VISIBILITY true |
21 | //! use bounding box or frustum for calculate polys | 21 | //! use bounding box or frustum for calculate polys |
22 | #define OCTREE_BOX_BASED true | 22 | #define OCTREE_BOX_BASED true |
23 | //! bypass full invisible/visible test | 23 | //! bypass full invisible/visible test |
24 | #define OCTREE_PARENTTEST | 24 | #define OCTREE_PARENTTEST |
25 | 25 | ||
26 | namespace irr | 26 | namespace irr |
27 | { | 27 | { |
28 | 28 | ||
29 | //! template octree. | 29 | //! template octree. |
30 | /** T must be a vertex type which has a member | 30 | /** T must be a vertex type which has a member |
31 | called .Pos, which is a core::vertex3df position. */ | 31 | called .Pos, which is a core::vertex3df position. */ |
32 | template <class T> | 32 | template <class T> |
33 | class Octree | 33 | class Octree |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | 36 | ||
37 | struct SMeshChunk : public scene::CMeshBuffer<T> | 37 | struct SMeshChunk : public scene::CMeshBuffer<T> |
38 | { | 38 | { |
39 | SMeshChunk () | 39 | SMeshChunk () |
40 | : scene::CMeshBuffer<T>(), MaterialId(0) | 40 | : scene::CMeshBuffer<T>(), MaterialId(0) |
41 | { | 41 | { |
42 | scene::CMeshBuffer<T>::grab(); | 42 | scene::CMeshBuffer<T>::grab(); |
43 | } | 43 | } |
44 | 44 | ||
45 | virtual ~SMeshChunk () | 45 | virtual ~SMeshChunk () |
46 | { | 46 | { |
47 | //removeAllHardwareBuffers | 47 | //removeAllHardwareBuffers |
48 | } | 48 | } |
49 | 49 | ||
50 | s32 MaterialId; | 50 | s32 MaterialId; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | struct SIndexChunk | 53 | struct SIndexChunk |
54 | { | 54 | { |
55 | core::array<u16> Indices; | 55 | core::array<u16> Indices; |
56 | s32 MaterialId; | 56 | s32 MaterialId; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | struct SIndexData | 59 | struct SIndexData |
60 | { | 60 | { |
61 | u16* Indices; | 61 | u16* Indices; |
62 | s32 CurrentSize; | 62 | s32 CurrentSize; |
63 | s32 MaxSize; | 63 | s32 MaxSize; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | 66 | ||
67 | //! Constructor | 67 | //! Constructor |
68 | Octree(const core::array<SMeshChunk>& meshes, s32 minimalPolysPerNode=128) : | 68 | Octree(const core::array<SMeshChunk>& meshes, s32 minimalPolysPerNode=128) : |
69 | IndexData(0), IndexDataCount(meshes.size()), NodeCount(0) | 69 | IndexData(0), IndexDataCount(meshes.size()), NodeCount(0) |
70 | { | 70 | { |
71 | IndexData = new SIndexData[IndexDataCount]; | 71 | IndexData = new SIndexData[IndexDataCount]; |
72 | 72 | ||
73 | // construct array of all indices | 73 | // construct array of all indices |
74 | 74 | ||
75 | core::array<SIndexChunk>* indexChunks = new core::array<SIndexChunk>; | 75 | core::array<SIndexChunk>* indexChunks = new core::array<SIndexChunk>; |
76 | indexChunks->reallocate(meshes.size()); | 76 | indexChunks->reallocate(meshes.size()); |
77 | for (u32 i=0; i!=meshes.size(); ++i) | 77 | for (u32 i=0; i!=meshes.size(); ++i) |
78 | { | 78 | { |
79 | IndexData[i].CurrentSize = 0; | 79 | IndexData[i].CurrentSize = 0; |
80 | IndexData[i].MaxSize = meshes[i].Indices.size(); | 80 | IndexData[i].MaxSize = meshes[i].Indices.size(); |
81 | IndexData[i].Indices = new u16[IndexData[i].MaxSize]; | 81 | IndexData[i].Indices = new u16[IndexData[i].MaxSize]; |
82 | 82 | ||
83 | indexChunks->push_back(SIndexChunk()); | 83 | indexChunks->push_back(SIndexChunk()); |
84 | SIndexChunk& tic = indexChunks->getLast(); | 84 | SIndexChunk& tic = indexChunks->getLast(); |
85 | 85 | ||
86 | tic.MaterialId = meshes[i].MaterialId; | 86 | tic.MaterialId = meshes[i].MaterialId; |
87 | tic.Indices = meshes[i].Indices; | 87 | tic.Indices = meshes[i].Indices; |
88 | } | 88 | } |
89 | 89 | ||
90 | // create tree | 90 | // create tree |
91 | Root = new OctreeNode(NodeCount, 0, meshes, indexChunks, minimalPolysPerNode); | 91 | Root = new OctreeNode(NodeCount, 0, meshes, indexChunks, minimalPolysPerNode); |
92 | } | 92 | } |
93 | 93 | ||
94 | //! returns all ids of polygons partially or fully enclosed | 94 | //! returns all ids of polygons partially or fully enclosed |
95 | //! by this bounding box. | 95 | //! by this bounding box. |
96 | void calculatePolys(const core::aabbox3d<f32>& box) | 96 | void calculatePolys(const core::aabbox3d<f32>& box) |
97 | { | 97 | { |
98 | for (u32 i=0; i!=IndexDataCount; ++i) | 98 | for (u32 i=0; i!=IndexDataCount; ++i) |
99 | IndexData[i].CurrentSize = 0; | 99 | IndexData[i].CurrentSize = 0; |
100 | 100 | ||
101 | Root->getPolys(box, IndexData, 0); | 101 | Root->getPolys(box, IndexData, 0); |
102 | } | 102 | } |
103 | 103 | ||
104 | //! returns all ids of polygons partially or fully enclosed | 104 | //! returns all ids of polygons partially or fully enclosed |
105 | //! by a view frustum. | 105 | //! by a view frustum. |
106 | void calculatePolys(const scene::SViewFrustum& frustum) | 106 | void calculatePolys(const scene::SViewFrustum& frustum) |
107 | { | 107 | { |
108 | for (u32 i=0; i!=IndexDataCount; ++i) | 108 | for (u32 i=0; i!=IndexDataCount; ++i) |
109 | IndexData[i].CurrentSize = 0; | 109 | IndexData[i].CurrentSize = 0; |
110 | 110 | ||
111 | Root->getPolys(frustum, IndexData, 0); | 111 | Root->getPolys(frustum, IndexData, 0); |
112 | } | 112 | } |
113 | 113 | ||
114 | const SIndexData* getIndexData() const | 114 | const SIndexData* getIndexData() const |
115 | { | 115 | { |
116 | return IndexData; | 116 | return IndexData; |
117 | } | 117 | } |
118 | 118 | ||
119 | u32 getIndexDataCount() const | 119 | u32 getIndexDataCount() const |
120 | { | 120 | { |
121 | return IndexDataCount; | 121 | return IndexDataCount; |
122 | } | 122 | } |
123 | 123 | ||
124 | u32 getNodeCount() const | 124 | u32 getNodeCount() const |
125 | { | 125 | { |
126 | return NodeCount; | 126 | return NodeCount; |
127 | } | 127 | } |
128 | 128 | ||
129 | //! for debug purposes only, collects the bounding boxes of the tree | 129 | //! for debug purposes only, collects the bounding boxes of the tree |
130 | void getBoundingBoxes(const core::aabbox3d<f32>& box, | 130 | void getBoundingBoxes(const core::aabbox3d<f32>& box, |
131 | core::array< const core::aabbox3d<f32>* >&outBoxes) const | 131 | core::array< const core::aabbox3d<f32>* >&outBoxes) const |
132 | { | 132 | { |
133 | Root->getBoundingBoxes(box, outBoxes); | 133 | Root->getBoundingBoxes(box, outBoxes); |
134 | } | 134 | } |
135 | 135 | ||
136 | //! destructor | 136 | //! destructor |
137 | ~Octree() | 137 | ~Octree() |
138 | { | 138 | { |
139 | for (u32 i=0; i<IndexDataCount; ++i) | 139 | for (u32 i=0; i<IndexDataCount; ++i) |
140 | delete [] IndexData[i].Indices; | 140 | delete [] IndexData[i].Indices; |
141 | 141 | ||
142 | delete [] IndexData; | 142 | delete [] IndexData; |
143 | delete Root; | 143 | delete Root; |
144 | } | 144 | } |
145 | 145 | ||
146 | private: | 146 | private: |
147 | // private inner class | 147 | // private inner class |
148 | class OctreeNode | 148 | class OctreeNode |
149 | { | 149 | { |
150 | public: | 150 | public: |
151 | 151 | ||
152 | // constructor | 152 | // constructor |
153 | OctreeNode(u32& nodeCount, u32 currentdepth, | 153 | OctreeNode(u32& nodeCount, u32 currentdepth, |
154 | const core::array<SMeshChunk>& allmeshdata, | 154 | const core::array<SMeshChunk>& allmeshdata, |
155 | core::array<SIndexChunk>* indices, | 155 | core::array<SIndexChunk>* indices, |
156 | s32 minimalPolysPerNode) : IndexData(0), | 156 | s32 minimalPolysPerNode) : IndexData(0), |
157 | Depth(currentdepth+1) | 157 | Depth(currentdepth+1) |
158 | { | 158 | { |
159 | ++nodeCount; | 159 | ++nodeCount; |
160 | 160 | ||
161 | u32 i; // new ISO for scoping problem with different compilers | 161 | u32 i; // new ISO for scoping problem with different compilers |
162 | 162 | ||
163 | for (i=0; i!=8; ++i) | 163 | for (i=0; i!=8; ++i) |
164 | Children[i] = 0; | 164 | Children[i] = 0; |
165 | 165 | ||
166 | if (indices->empty()) | 166 | if (indices->empty()) |
167 | { | 167 | { |
168 | delete indices; | 168 | delete indices; |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool found = false; | 172 | bool found = false; |
173 | 173 | ||
174 | // find first point for bounding box | 174 | // find first point for bounding box |
175 | 175 | ||
176 | for (i=0; i<indices->size(); ++i) | 176 | for (i=0; i<indices->size(); ++i) |
177 | { | 177 | { |
178 | if (!(*indices)[i].Indices.empty()) | 178 | if (!(*indices)[i].Indices.empty()) |
179 | { | 179 | { |
180 | Box.reset(allmeshdata[i].Vertices[(*indices)[i].Indices[0]].Pos); | 180 | Box.reset(allmeshdata[i].Vertices[(*indices)[i].Indices[0]].Pos); |
181 | found = true; | 181 | found = true; |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | if (!found) | 186 | if (!found) |
187 | { | 187 | { |
188 | delete indices; | 188 | delete indices; |
189 | return; | 189 | return; |
190 | } | 190 | } |
191 | 191 | ||
192 | s32 totalPrimitives = 0; | 192 | s32 totalPrimitives = 0; |
193 | 193 | ||
194 | // now lets calculate our bounding box | 194 | // now lets calculate our bounding box |
195 | for (i=0; i<indices->size(); ++i) | 195 | for (i=0; i<indices->size(); ++i) |
196 | { | 196 | { |
197 | totalPrimitives += (*indices)[i].Indices.size(); | 197 | totalPrimitives += (*indices)[i].Indices.size(); |
198 | for (u32 j=0; j<(*indices)[i].Indices.size(); ++j) | 198 | for (u32 j=0; j<(*indices)[i].Indices.size(); ++j) |
199 | Box.addInternalPoint(allmeshdata[i].Vertices[(*indices)[i].Indices[j]].Pos); | 199 | Box.addInternalPoint(allmeshdata[i].Vertices[(*indices)[i].Indices[j]].Pos); |
200 | } | 200 | } |
201 | 201 | ||
202 | core::vector3df middle = Box.getCenter(); | 202 | core::vector3df middle = Box.getCenter(); |
203 | core::vector3df edges[8]; | 203 | core::vector3df edges[8]; |
204 | Box.getEdges(edges); | 204 | Box.getEdges(edges); |
205 | 205 | ||
206 | // calculate all children | 206 | // calculate all children |
207 | core::aabbox3d<f32> box; | 207 | core::aabbox3d<f32> box; |
208 | core::array<u16> keepIndices; | 208 | core::array<u16> keepIndices; |
209 | 209 | ||
210 | if (totalPrimitives > minimalPolysPerNode && !Box.isEmpty()) | 210 | if (totalPrimitives > minimalPolysPerNode && !Box.isEmpty()) |
211 | for (u32 ch=0; ch!=8; ++ch) | 211 | for (u32 ch=0; ch!=8; ++ch) |
212 | { | 212 | { |
213 | box.reset(middle); | 213 | box.reset(middle); |
214 | box.addInternalPoint(edges[ch]); | 214 | box.addInternalPoint(edges[ch]); |
215 | 215 | ||
216 | // create indices for child | 216 | // create indices for child |
217 | bool added = false; | 217 | bool added = false; |
218 | core::array<SIndexChunk>* cindexChunks = new core::array<SIndexChunk>; | 218 | core::array<SIndexChunk>* cindexChunks = new core::array<SIndexChunk>; |
219 | cindexChunks->reallocate(allmeshdata.size()); | 219 | cindexChunks->reallocate(allmeshdata.size()); |
220 | for (i=0; i<allmeshdata.size(); ++i) | 220 | for (i=0; i<allmeshdata.size(); ++i) |
221 | { | 221 | { |
222 | cindexChunks->push_back(SIndexChunk()); | 222 | cindexChunks->push_back(SIndexChunk()); |
223 | SIndexChunk& tic = cindexChunks->getLast(); | 223 | SIndexChunk& tic = cindexChunks->getLast(); |
224 | tic.MaterialId = allmeshdata[i].MaterialId; | 224 | tic.MaterialId = allmeshdata[i].MaterialId; |
225 | 225 | ||
226 | for (u32 t=0; t<(*indices)[i].Indices.size(); t+=3) | 226 | for (u32 t=0; t<(*indices)[i].Indices.size(); t+=3) |
227 | { | 227 | { |
228 | if (box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t]].Pos) && | 228 | if (box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t]].Pos) && |
229 | box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t+1]].Pos) && | 229 | box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t+1]].Pos) && |
230 | box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t+2]].Pos)) | 230 | box.isPointInside(allmeshdata[i].Vertices[(*indices)[i].Indices[t+2]].Pos)) |
231 | { | 231 | { |
232 | tic.Indices.push_back((*indices)[i].Indices[t]); | 232 | tic.Indices.push_back((*indices)[i].Indices[t]); |
233 | tic.Indices.push_back((*indices)[i].Indices[t+1]); | 233 | tic.Indices.push_back((*indices)[i].Indices[t+1]); |
234 | tic.Indices.push_back((*indices)[i].Indices[t+2]); | 234 | tic.Indices.push_back((*indices)[i].Indices[t+2]); |
235 | 235 | ||
236 | added = true; | 236 | added = true; |
237 | } | 237 | } |
238 | else | 238 | else |
239 | { | 239 | { |
240 | keepIndices.push_back((*indices)[i].Indices[t]); | 240 | keepIndices.push_back((*indices)[i].Indices[t]); |
241 | keepIndices.push_back((*indices)[i].Indices[t+1]); | 241 | keepIndices.push_back((*indices)[i].Indices[t+1]); |
242 | keepIndices.push_back((*indices)[i].Indices[t+2]); | 242 | keepIndices.push_back((*indices)[i].Indices[t+2]); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | (*indices)[i].Indices.set_used(keepIndices.size()); | 246 | (*indices)[i].Indices.set_used(keepIndices.size()); |
247 | memcpy( (*indices)[i].Indices.pointer(), keepIndices.pointer(), keepIndices.size()*sizeof(u16)); | 247 | memcpy( (*indices)[i].Indices.pointer(), keepIndices.pointer(), keepIndices.size()*sizeof(u16)); |
248 | keepIndices.set_used(0); | 248 | keepIndices.set_used(0); |
249 | } | 249 | } |
250 | 250 | ||
251 | if (added) | 251 | if (added) |
252 | Children[ch] = new OctreeNode(nodeCount, Depth, | 252 | Children[ch] = new OctreeNode(nodeCount, Depth, |
253 | allmeshdata, cindexChunks, minimalPolysPerNode); | 253 | allmeshdata, cindexChunks, minimalPolysPerNode); |
254 | else | 254 | else |
255 | delete cindexChunks; | 255 | delete cindexChunks; |
256 | 256 | ||
257 | } // end for all possible children | 257 | } // end for all possible children |
258 | 258 | ||
259 | IndexData = indices; | 259 | IndexData = indices; |
260 | } | 260 | } |
261 | 261 | ||
262 | // destructor | 262 | // destructor |
263 | ~OctreeNode() | 263 | ~OctreeNode() |
264 | { | 264 | { |
265 | delete IndexData; | 265 | delete IndexData; |
266 | 266 | ||
267 | for (u32 i=0; i<8; ++i) | 267 | for (u32 i=0; i<8; ++i) |
268 | delete Children[i]; | 268 | delete Children[i]; |
269 | } | 269 | } |
270 | 270 | ||
271 | // returns all ids of polygons partially or full enclosed | 271 | // returns all ids of polygons partially or full enclosed |
272 | // by this bounding box. | 272 | // by this bounding box. |
273 | void getPolys(const core::aabbox3d<f32>& box, SIndexData* idxdata, u32 parentTest ) const | 273 | void getPolys(const core::aabbox3d<f32>& box, SIndexData* idxdata, u32 parentTest ) const |
274 | { | 274 | { |
275 | #if defined (OCTREE_PARENTTEST ) | 275 | #if defined (OCTREE_PARENTTEST ) |
276 | // if not full inside | 276 | // if not full inside |
277 | if ( parentTest != 2 ) | 277 | if ( parentTest != 2 ) |
278 | { | 278 | { |
279 | // partially inside ? | 279 | // partially inside ? |
280 | if (!Box.intersectsWithBox(box)) | 280 | if (!Box.intersectsWithBox(box)) |
281 | return; | 281 | return; |
282 | 282 | ||
283 | // fully inside ? | 283 | // fully inside ? |
284 | parentTest = Box.isFullInside(box)?2:1; | 284 | parentTest = Box.isFullInside(box)?2:1; |
285 | } | 285 | } |
286 | #else | 286 | #else |
287 | if (Box.intersectsWithBox(box)) | 287 | if (Box.intersectsWithBox(box)) |
288 | #endif | 288 | #endif |
289 | { | 289 | { |
290 | const u32 cnt = IndexData->size(); | 290 | const u32 cnt = IndexData->size(); |
291 | u32 i; // new ISO for scoping problem in some compilers | 291 | u32 i; // new ISO for scoping problem in some compilers |
292 | 292 | ||
293 | for (i=0; i<cnt; ++i) | 293 | for (i=0; i<cnt; ++i) |
294 | { | 294 | { |
295 | const s32 idxcnt = (*IndexData)[i].Indices.size(); | 295 | const s32 idxcnt = (*IndexData)[i].Indices.size(); |
296 | 296 | ||
297 | if (idxcnt) | 297 | if (idxcnt) |
298 | { | 298 | { |
299 | memcpy(&idxdata[i].Indices[idxdata[i].CurrentSize], | 299 | memcpy(&idxdata[i].Indices[idxdata[i].CurrentSize], |
300 | &(*IndexData)[i].Indices[0], idxcnt * sizeof(s16)); | 300 | &(*IndexData)[i].Indices[0], idxcnt * sizeof(s16)); |
301 | idxdata[i].CurrentSize += idxcnt; | 301 | idxdata[i].CurrentSize += idxcnt; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | for (i=0; i!=8; ++i) | 305 | for (i=0; i!=8; ++i) |
306 | if (Children[i]) | 306 | if (Children[i]) |
307 | Children[i]->getPolys(box, idxdata,parentTest); | 307 | Children[i]->getPolys(box, idxdata,parentTest); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | // returns all ids of polygons partially or full enclosed | 311 | // returns all ids of polygons partially or full enclosed |
312 | // by the view frustum. | 312 | // by the view frustum. |
313 | void getPolys(const scene::SViewFrustum& frustum, SIndexData* idxdata,u32 parentTest) const | 313 | void getPolys(const scene::SViewFrustum& frustum, SIndexData* idxdata,u32 parentTest) const |
314 | { | 314 | { |
315 | u32 i; // new ISO for scoping problem in some compilers | 315 | u32 i; // new ISO for scoping problem in some compilers |
316 | 316 | ||
317 | // if parent is fully inside, no further check for the children is needed | 317 | // if parent is fully inside, no further check for the children is needed |
318 | #if defined (OCTREE_PARENTTEST ) | 318 | #if defined (OCTREE_PARENTTEST ) |
319 | if ( parentTest != 2 ) | 319 | if ( parentTest != 2 ) |
320 | #endif | 320 | #endif |
321 | { | 321 | { |
322 | #if defined (OCTREE_PARENTTEST ) | 322 | #if defined (OCTREE_PARENTTEST ) |
323 | parentTest = 2; | 323 | parentTest = 2; |
324 | #endif | 324 | #endif |
325 | for (i=0; i!=scene::SViewFrustum::VF_PLANE_COUNT; ++i) | 325 | for (i=0; i!=scene::SViewFrustum::VF_PLANE_COUNT; ++i) |
326 | { | 326 | { |
327 | core::EIntersectionRelation3D r = Box.classifyPlaneRelation(frustum.planes[i]); | 327 | core::EIntersectionRelation3D r = Box.classifyPlaneRelation(frustum.planes[i]); |
328 | if ( r == core::ISREL3D_FRONT ) | 328 | if ( r == core::ISREL3D_FRONT ) |
329 | return; | 329 | return; |
330 | #if defined (OCTREE_PARENTTEST ) | 330 | #if defined (OCTREE_PARENTTEST ) |
331 | if ( r == core::ISREL3D_CLIPPED ) | 331 | if ( r == core::ISREL3D_CLIPPED ) |
332 | parentTest = 1; // must still check children | 332 | parentTest = 1; // must still check children |
333 | #endif | 333 | #endif |
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | const u32 cnt = IndexData->size(); | 338 | const u32 cnt = IndexData->size(); |
339 | 339 | ||
340 | for (i=0; i!=cnt; ++i) | 340 | for (i=0; i!=cnt; ++i) |
341 | { | 341 | { |
342 | s32 idxcnt = (*IndexData)[i].Indices.size(); | 342 | s32 idxcnt = (*IndexData)[i].Indices.size(); |
343 | 343 | ||
344 | if (idxcnt) | 344 | if (idxcnt) |
345 | { | 345 | { |
346 | memcpy(&idxdata[i].Indices[idxdata[i].CurrentSize], | 346 | memcpy(&idxdata[i].Indices[idxdata[i].CurrentSize], |
347 | &(*IndexData)[i].Indices[0], idxcnt * sizeof(s16)); | 347 | &(*IndexData)[i].Indices[0], idxcnt * sizeof(s16)); |
348 | idxdata[i].CurrentSize += idxcnt; | 348 | idxdata[i].CurrentSize += idxcnt; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | for (i=0; i!=8; ++i) | 352 | for (i=0; i!=8; ++i) |
353 | if (Children[i]) | 353 | if (Children[i]) |
354 | Children[i]->getPolys(frustum, idxdata,parentTest); | 354 | Children[i]->getPolys(frustum, idxdata,parentTest); |
355 | } | 355 | } |
356 | 356 | ||
357 | //! for debug purposes only, collects the bounding boxes of the node | 357 | //! for debug purposes only, collects the bounding boxes of the node |
358 | void getBoundingBoxes(const core::aabbox3d<f32>& box, | 358 | void getBoundingBoxes(const core::aabbox3d<f32>& box, |
359 | core::array< const core::aabbox3d<f32>* >&outBoxes) const | 359 | core::array< const core::aabbox3d<f32>* >&outBoxes) const |
360 | { | 360 | { |
361 | if (Box.intersectsWithBox(box)) | 361 | if (Box.intersectsWithBox(box)) |
362 | { | 362 | { |
363 | outBoxes.push_back(&Box); | 363 | outBoxes.push_back(&Box); |
364 | 364 | ||
365 | for (u32 i=0; i!=8; ++i) | 365 | for (u32 i=0; i!=8; ++i) |
366 | if (Children[i]) | 366 | if (Children[i]) |
367 | Children[i]->getBoundingBoxes(box, outBoxes); | 367 | Children[i]->getBoundingBoxes(box, outBoxes); |
368 | } | 368 | } |
369 | } | 369 | } |
370 | 370 | ||
371 | private: | 371 | private: |
372 | 372 | ||
373 | core::aabbox3df Box; | 373 | core::aabbox3df Box; |
374 | core::array<SIndexChunk>* IndexData; | 374 | core::array<SIndexChunk>* IndexData; |
375 | OctreeNode* Children[8]; | 375 | OctreeNode* Children[8]; |
376 | u32 Depth; | 376 | u32 Depth; |
377 | }; | 377 | }; |
378 | 378 | ||
379 | OctreeNode* Root; | 379 | OctreeNode* Root; |
380 | SIndexData* IndexData; | 380 | SIndexData* IndexData; |
381 | u32 IndexDataCount; | 381 | u32 IndexDataCount; |
382 | u32 NodeCount; | 382 | u32 NodeCount; |
383 | }; | 383 | }; |
384 | 384 | ||
385 | } // end namespace | 385 | } // end namespace |
386 | 386 | ||
387 | #endif | 387 | #endif |
388 | 388 | ||