aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-01-13 19:47:58 +1000
committerDavid Walter Seikel2014-01-13 19:47:58 +1000
commitf9158592e1478b2013afc7041d9ed041cf2d2f4a (patch)
treeb16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp
parentLibraries readme updated with change markers and more of the Irrlicht changes. (diff)
downloadSledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp234
1 files changed, 0 insertions, 234 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp
deleted file mode 100644
index 7f90f60..0000000
--- a/libraries/irrlicht-1.8/source/Irrlicht/CTerrainTriangleSelector.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "CTerrainTriangleSelector.h"
6#include "CTerrainSceneNode.h"
7#include "os.h"
8
9namespace irr
10{
11namespace scene
12{
13
14
15//! constructor
16CTerrainTriangleSelector::CTerrainTriangleSelector ( ITerrainSceneNode* node, s32 LOD )
17 : SceneNode(node)
18{
19 #ifdef _DEBUG
20 setDebugName ("CTerrainTriangleSelector");
21 #endif
22
23 setTriangleData(node, LOD);
24}
25
26
27//! destructor
28CTerrainTriangleSelector::~CTerrainTriangleSelector()
29{
30 TrianglePatches.TrianglePatchArray.clear();
31}
32
33
34//! Clears and sets triangle data
35void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
36{
37 // Get pointer to the GeoMipMaps vertices
38 const video::S3DVertex2TCoords* vertices = static_cast<const video::S3DVertex2TCoords*>(node->getRenderBuffer()->getVertices());
39
40 // Clear current data
41 const s32 count = (static_cast<CTerrainSceneNode*>(node))->TerrainData.PatchCount;
42 TrianglePatches.TotalTriangles = 0;
43 TrianglePatches.NumPatches = count*count;
44
45 TrianglePatches.TrianglePatchArray.reallocate(TrianglePatches.NumPatches);
46 for (s32 o=0; o<TrianglePatches.NumPatches; ++o)
47 TrianglePatches.TrianglePatchArray.push_back(SGeoMipMapTrianglePatch());
48
49 core::triangle3df tri;
50 core::array<u32> indices;
51 s32 tIndex = 0;
52 for(s32 x = 0; x < count; ++x )
53 {
54 for(s32 z = 0; z < count; ++z )
55 {
56 TrianglePatches.TrianglePatchArray[tIndex].NumTriangles = 0;
57 TrianglePatches.TrianglePatchArray[tIndex].Box = node->getBoundingBox( x, z );
58 u32 indexCount = node->getIndicesForPatch( indices, x, z, LOD );
59
60 TrianglePatches.TrianglePatchArray[tIndex].Triangles.reallocate(indexCount/3);
61 for(u32 i = 0; i < indexCount; i += 3 )
62 {
63 tri.pointA = vertices[indices[i+0]].Pos;
64 tri.pointB = vertices[indices[i+1]].Pos;
65 tri.pointC = vertices[indices[i+2]].Pos;
66 TrianglePatches.TrianglePatchArray[tIndex].Triangles.push_back(tri);
67 ++TrianglePatches.TrianglePatchArray[tIndex].NumTriangles;
68 }
69
70 TrianglePatches.TotalTriangles += TrianglePatches.TrianglePatchArray[tIndex].NumTriangles;
71 ++tIndex;
72 }
73 }
74}
75
76
77//! Gets all triangles.
78void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
79 s32 arraySize, s32& outTriangleCount,
80 const core::matrix4* transform) const
81{
82 s32 count = TrianglePatches.TotalTriangles;
83
84 if (count > arraySize)
85 count = arraySize;
86
87 core::matrix4 mat;
88
89 if (transform)
90 mat = (*transform);
91
92 s32 tIndex = 0;
93
94 for (s32 i=0; i<TrianglePatches.NumPatches; ++i)
95 {
96 if (tIndex + TrianglePatches.TrianglePatchArray[i].NumTriangles <= count)
97 for (s32 j=0; j<TrianglePatches.TrianglePatchArray[i].NumTriangles; ++j)
98 {
99 triangles[tIndex] = TrianglePatches.TrianglePatchArray[i].Triangles[j];
100
101 mat.transformVect(triangles[tIndex].pointA);
102 mat.transformVect(triangles[tIndex].pointB);
103 mat.transformVect(triangles[tIndex].pointC);
104
105 ++tIndex;
106 }
107 }
108
109 outTriangleCount = tIndex;
110}
111
112
113//! Gets all triangles which lie within a specific bounding box.
114void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
115 s32 arraySize, s32& outTriangleCount,
116 const core::aabbox3d<f32>& box, const core::matrix4* transform) const
117{
118 s32 count = TrianglePatches.TotalTriangles;
119
120 if (count > arraySize)
121 count = arraySize;
122
123 core::matrix4 mat;
124
125 if (transform)
126 mat = (*transform);
127
128 s32 tIndex = 0;
129
130 for (s32 i=0; i<TrianglePatches.NumPatches; ++i)
131 {
132 if (tIndex + TrianglePatches.TrianglePatchArray[i].NumTriangles <= count &&
133 TrianglePatches.TrianglePatchArray[i].Box.intersectsWithBox(box))
134 for (s32 j=0; j<TrianglePatches.TrianglePatchArray[i].NumTriangles; ++j)
135 {
136 triangles[tIndex] = TrianglePatches.TrianglePatchArray[i].Triangles[j];
137
138 mat.transformVect(triangles[tIndex].pointA);
139 mat.transformVect(triangles[tIndex].pointB);
140 mat.transformVect(triangles[tIndex].pointC);
141
142 ++tIndex;
143 }
144 }
145
146 outTriangleCount = tIndex;
147}
148
149
150//! Gets all triangles which have or may have contact with a 3d line.
151void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
152 s32 arraySize, s32& outTriangleCount, const core::line3d<f32>& line,
153 const core::matrix4* transform) const
154{
155 const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize);
156
157 core::matrix4 mat;
158
159 if (transform)
160 mat = (*transform);
161
162 s32 tIndex = 0;
163
164 for (s32 i=0; i<TrianglePatches.NumPatches; ++i)
165 {
166 if (tIndex + TrianglePatches.TrianglePatchArray[i].NumTriangles <= count
167 && TrianglePatches.TrianglePatchArray[i].Box.intersectsWithLine(line))
168 {
169 for (s32 j=0; j<TrianglePatches.TrianglePatchArray[i].NumTriangles; ++j)
170 {
171 triangles[tIndex] = TrianglePatches.TrianglePatchArray[i].Triangles[j];
172
173 mat.transformVect(triangles[tIndex].pointA);
174 mat.transformVect(triangles[tIndex].pointB);
175 mat.transformVect(triangles[tIndex].pointC);
176
177 ++tIndex;
178 }
179 }
180 }
181
182 outTriangleCount = tIndex;
183}
184
185
186//! Returns amount of all available triangles in this selector
187s32 CTerrainTriangleSelector::getTriangleCount() const
188{
189 return TrianglePatches.TotalTriangles;
190}
191
192
193ISceneNode* CTerrainTriangleSelector::getSceneNodeForTriangle(
194 u32 triangleIndex) const
195{
196 return SceneNode;
197}
198
199
200/* Get the number of TriangleSelectors that are part of this one.
201Only useful for MetaTriangleSelector others return 1
202*/
203u32 CTerrainTriangleSelector::getSelectorCount() const
204{
205 return 1;
206}
207
208
209/* Get the TriangleSelector based on index based on getSelectorCount.
210Only useful for MetaTriangleSelector others return 'this' or 0
211*/
212ITriangleSelector* CTerrainTriangleSelector::getSelector(u32 index)
213{
214 if (index)
215 return 0;
216 else
217 return this;
218}
219
220
221/* Get the TriangleSelector based on index based on getSelectorCount.
222Only useful for MetaTriangleSelector others return 'this' or 0
223*/
224const ITriangleSelector* CTerrainTriangleSelector::getSelector(u32 index) const
225{
226 if (index)
227 return 0;
228 else
229 return this;
230}
231
232
233} // end namespace scene
234} // end namespace irr