diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs index 2ace097..13184e2 100644 --- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs | |||
@@ -27,10 +27,9 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Globalization; | ||
31 | using System.Diagnostics; | ||
32 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
33 | 31 | using System.Diagnostics; | |
32 | using System.Globalization; | ||
34 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
35 | 34 | ||
36 | public class Vertex : IComparable<Vertex> | 35 | public class Vertex : IComparable<Vertex> |
@@ -76,8 +75,6 @@ public class Vertex : IComparable<Vertex> | |||
76 | { | 75 | { |
77 | return me.CompareTo(other) < 0; | 76 | return me.CompareTo(other) < 0; |
78 | } | 77 | } |
79 | |||
80 | |||
81 | } | 78 | } |
82 | 79 | ||
83 | public class Simplex : IComparable<Simplex> | 80 | public class Simplex : IComparable<Simplex> |
@@ -122,8 +119,7 @@ public class Simplex : IComparable<Simplex> | |||
122 | 119 | ||
123 | return 0; | 120 | return 0; |
124 | } | 121 | } |
125 | 122 | } ; | |
126 | }; | ||
127 | 123 | ||
128 | public class Triangle | 124 | public class Triangle |
129 | { | 125 | { |
@@ -131,9 +127,9 @@ public class Triangle | |||
131 | public Vertex v2; | 127 | public Vertex v2; |
132 | public Vertex v3; | 128 | public Vertex v3; |
133 | 129 | ||
134 | float radius_square; | 130 | private float radius_square; |
135 | float cx; | 131 | private float cx; |
136 | float cy; | 132 | private float cy; |
137 | 133 | ||
138 | public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) | 134 | public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) |
139 | { | 135 | { |
@@ -149,18 +145,18 @@ public class Triangle | |||
149 | float dx, dy; | 145 | float dx, dy; |
150 | float dd; | 146 | float dd; |
151 | 147 | ||
152 | dx = x - this.cx; | 148 | dx = x - cx; |
153 | dy = y - this.cy; | 149 | dy = y - cy; |
154 | 150 | ||
155 | dd = dx * dx + dy * dy; | 151 | dd = dx*dx + dy*dy; |
156 | if (dd < this.radius_square) | 152 | if (dd < radius_square) |
157 | return true; | 153 | return true; |
158 | else | 154 | else |
159 | return false; | 155 | return false; |
160 | } | 156 | } |
161 | 157 | ||
162 | 158 | ||
163 | void CalcCircle() | 159 | private void CalcCircle() |
164 | { | 160 | { |
165 | // Calculate the center and the radius of a circle given by three points p1, p2, p3 | 161 | // Calculate the center and the radius of a circle given by three points p1, p2, p3 |
166 | // It is assumed, that the triangles vertices are already set correctly | 162 | // It is assumed, that the triangles vertices are already set correctly |
@@ -198,8 +194,8 @@ public class Triangle | |||
198 | p3y = v3.point.Y; | 194 | p3y = v3.point.Y; |
199 | 195 | ||
200 | /* calc helping values first */ | 196 | /* calc helping values first */ |
201 | c1 = (p1x * p1x + p1y * p1y - p2x * p2x - p2y * p2y) / 2; | 197 | c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2; |
202 | c2 = (p1x * p1x + p1y * p1y - p3x * p3x - p3y * p3y) / 2; | 198 | c2 = (p1x*p1x + p1y*p1y - p3x*p3x - p3y*p3y)/2; |
203 | 199 | ||
204 | v1x = p1x - p2x; | 200 | v1x = p1x - p2x; |
205 | v1y = p1y - p2y; | 201 | v1y = p1y - p2y; |
@@ -207,35 +203,34 @@ public class Triangle | |||
207 | v2x = p1x - p3x; | 203 | v2x = p1x - p3x; |
208 | v2y = p1y - p3y; | 204 | v2y = p1y - p3y; |
209 | 205 | ||
210 | z = (c1 * v2x - c2 * v1x); | 206 | z = (c1*v2x - c2*v1x); |
211 | n = (v1y * v2x - v2y * v1x); | 207 | n = (v1y*v2x - v2y*v1x); |
212 | 208 | ||
213 | if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location | 209 | if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location |
214 | { | 210 | { |
215 | radius_square = 0.0f; | 211 | radius_square = 0.0f; |
216 | return; | 212 | return; |
217 | } | 213 | } |
218 | 214 | ||
219 | this.cy = (float)(z / n); | 215 | cy = (float) (z/n); |
220 | 216 | ||
221 | if (v2x != 0.0) | 217 | if (v2x != 0.0) |
222 | { | 218 | { |
223 | this.cx = (float)((c2 - v2y * this.cy) / v2x); | 219 | cx = (float) ((c2 - v2y*cy)/v2x); |
224 | } | 220 | } |
225 | else if (v1x != 0.0) | 221 | else if (v1x != 0.0) |
226 | { | 222 | { |
227 | this.cx = (float)((c1 - v1y * this.cy) / v1x); | 223 | cx = (float) ((c1 - v1y*cy)/v1x); |
228 | } | 224 | } |
229 | else | 225 | else |
230 | { | 226 | { |
231 | Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ | 227 | Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ |
232 | } | 228 | } |
233 | 229 | ||
234 | rx = (p1x - this.cx); | 230 | rx = (p1x - cx); |
235 | ry = (p1y - this.cy); | 231 | ry = (p1y - cy); |
236 | |||
237 | this.radius_square = (float)(rx * rx + ry * ry); | ||
238 | 232 | ||
233 | radius_square = (float) (rx*rx + ry*ry); | ||
239 | } | 234 | } |
240 | 235 | ||
241 | public List<Simplex> GetSimplices() | 236 | public List<Simplex> GetSimplices() |
@@ -254,17 +249,18 @@ public class Triangle | |||
254 | 249 | ||
255 | public override String ToString() | 250 | public override String ToString() |
256 | { | 251 | { |
257 | |||
258 | NumberFormatInfo nfi = new NumberFormatInfo(); | 252 | NumberFormatInfo nfi = new NumberFormatInfo(); |
259 | nfi.CurrencyDecimalDigits = 2; | 253 | nfi.CurrencyDecimalDigits = 2; |
260 | nfi.CurrencyDecimalSeparator = "."; | 254 | nfi.CurrencyDecimalSeparator = "."; |
261 | 255 | ||
262 | String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + ">"; | 256 | String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + |
263 | String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + ">"; | 257 | ">"; |
264 | String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + ">"; | 258 | String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + |
259 | ">"; | ||
260 | String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + | ||
261 | ">"; | ||
265 | 262 | ||
266 | return s1 + ";" + s2 + ";" + s3; | 263 | return s1 + ";" + s2 + ";" + s3; |
267 | |||
268 | } | 264 | } |
269 | 265 | ||
270 | public PhysicsVector getNormal() | 266 | public PhysicsVector getNormal() |
@@ -281,12 +277,12 @@ public class Triangle | |||
281 | // Cross product for normal | 277 | // Cross product for normal |
282 | PhysicsVector n = new PhysicsVector(); | 278 | PhysicsVector n = new PhysicsVector(); |
283 | float nx, ny, nz; | 279 | float nx, ny, nz; |
284 | n.X = e1.Y * e2.Z - e1.Z * e2.Y; | 280 | n.X = e1.Y*e2.Z - e1.Z*e2.Y; |
285 | n.Y = e1.Z * e2.X - e1.X * e2.Z; | 281 | n.Y = e1.Z*e2.X - e1.X*e2.Z; |
286 | n.Z = e1.X * e2.Y - e1.Y * e2.X; | 282 | n.Z = e1.X*e2.Y - e1.Y*e2.X; |
287 | 283 | ||
288 | // Length | 284 | // Length |
289 | float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); | 285 | float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z); |
290 | 286 | ||
291 | // Normalized "normal" | 287 | // Normalized "normal" |
292 | n.X /= l; | 288 | n.X /= l; |
@@ -303,6 +299,4 @@ public class Triangle | |||
303 | v1 = v2; | 299 | v1 = v2; |
304 | v2 = vt; | 300 | v2 = vt; |
305 | } | 301 | } |
306 | } | 302 | } \ No newline at end of file |
307 | |||
308 | |||