aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs158
1 files changed, 81 insertions, 77 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 13184e2..3b20af7 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -30,37 +30,63 @@ using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; 31using System.Diagnostics;
32using System.Globalization; 32using System.Globalization;
33using OpenSim.Framework.Console;
33using OpenSim.Region.Physics.Manager; 34using OpenSim.Region.Physics.Manager;
34 35
35public class Vertex : IComparable<Vertex> 36using OpenSim.Region.Physics.OdePlugin.Meshing;
37
38public class Vertex : PhysicsVector, IComparable<Vertex>
36{ 39{
37 public String name; 40 public Vertex(float x, float y, float z)
38 public PhysicsVector point; 41 : base(x, y, z)
42 {
43 }
44
45 public Vertex(PhysicsVector v)
46 : base(v.X, v.Y, v.Z)
47 {
48 }
49
50 public Vertex Clone()
51 {
52 return new Vertex(X, Y, Z);
53 }
54
55 public static Vertex FromAngle(double angle)
56 {
57 return new Vertex((float)Math.Cos(angle), (float)Math.Sin(angle), 0.0f);
58 }
59
39 60
40 public Vertex(String name, float x, float y, float z) 61 public virtual bool Equals(Vertex v, float tolerance)
41 { 62 {
42 this.name = name; 63 PhysicsVector diff = this - v;
43 point = new PhysicsVector(x, y, z); 64 float d = diff.length();
65 if (d < tolerance)
66 return true;
67
68 return false;
44 } 69 }
45 70
71
46 public int CompareTo(Vertex other) 72 public int CompareTo(Vertex other)
47 { 73 {
48 if (point.X < other.point.X) 74 if (X < other.X)
49 return -1; 75 return -1;
50 76
51 if (point.X > other.point.X) 77 if (X > other.X)
52 return 1; 78 return 1;
53 79
54 if (point.Y < other.point.Y) 80 if (Y < other.Y)
55 return -1; 81 return -1;
56 82
57 if (point.Y > other.point.Y) 83 if (Y > other.Y)
58 return 1; 84 return 1;
59 85
60 if (point.Z < other.point.Z) 86 if (Z < other.Z)
61 return -1; 87 return -1;
62 88
63 if (point.Z > other.point.Z) 89 if (Z > other.Z)
64 return 1; 90 return 1;
65 91
66 return 0; 92 return 0;
@@ -75,51 +101,24 @@ public class Vertex : IComparable<Vertex>
75 { 101 {
76 return me.CompareTo(other) < 0; 102 return me.CompareTo(other) < 0;
77 } 103 }
78} 104 public String ToRaw()
79
80public class Simplex : IComparable<Simplex>
81{
82 public Vertex v1;
83 public Vertex v2;
84
85 public Simplex(Vertex _v1, Vertex _v2)
86 {
87 // Presort indices to make sorting (comparing) easier
88 if (_v1 > _v2)
89 {
90 v1 = _v1;
91 v2 = _v2;
92 }
93 else
94 {
95 v1 = _v2;
96 v2 = _v1;
97 }
98 }
99
100 public int CompareTo(Simplex other)
101 { 105 {
102 if (v1 > other.v1) 106 // Why this stuff with the number formatter?
103 { 107 // Well, the raw format uses the english/US notation of numbers
104 return 1; 108 // where the "," separates groups of 1000 while the "." marks the border between 1 and 10E-1.
105 } 109 // The german notation uses these characters exactly vice versa!
106 if (v1 < other.v1) 110 // The Float.ToString() routine is a localized one, giving different results depending on the country
107 { 111 // settings your machine works with. Unusable for a machine readable file format :-(
108 return -1; 112 NumberFormatInfo nfi = new NumberFormatInfo();
109 } 113 nfi.NumberDecimalSeparator = ".";
114 nfi.NumberDecimalDigits = 3;
110 115
111 if (v2 > other.v2) 116 String s1 = X.ToString("N2", nfi) + " " + Y.ToString("N2", nfi) + " " + Z.ToString("N2", nfi);
112 {
113 return 1;
114 }
115 if (v2 < other.v2)
116 {
117 return -1;
118 }
119 117
120 return 0; 118 return s1;
121 } 119 }
122} ; 120
121}
123 122
124public class Triangle 123public class Triangle
125{ 124{
@@ -155,6 +154,12 @@ public class Triangle
155 return false; 154 return false;
156 } 155 }
157 156
157 public bool isDegraded()
158 {
159 // This means, the vertices of this triangle are somewhat strange.
160 // They either line up or at least two of them are identical
161 return (radius_square == 0.0);
162 }
158 163
159 private void CalcCircle() 164 private void CalcCircle()
160 { 165 {
@@ -184,14 +189,14 @@ public class Triangle
184 double rx, ry; 189 double rx, ry;
185 190
186 // Readout the three points, the triangle consists of 191 // Readout the three points, the triangle consists of
187 p1x = v1.point.X; 192 p1x = v1.X;
188 p1y = v1.point.Y; 193 p1y = v1.Y;
189 194
190 p2x = v2.point.X; 195 p2x = v2.X;
191 p2y = v2.point.Y; 196 p2y = v2.Y;
192 197
193 p3x = v3.point.X; 198 p3x = v3.X;
194 p3y = v3.point.Y; 199 p3y = v3.Y;
195 200
196 /* calc helping values first */ 201 /* calc helping values first */
197 c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2; 202 c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2;
@@ -253,12 +258,9 @@ public class Triangle
253 nfi.CurrencyDecimalDigits = 2; 258 nfi.CurrencyDecimalDigits = 2;
254 nfi.CurrencyDecimalSeparator = "."; 259 nfi.CurrencyDecimalSeparator = ".";
255 260
256 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + 261 String s1 = "<" + v1.X.ToString(nfi) + "," + v1.Y.ToString(nfi) + "," + v1.Z.ToString(nfi) + ">";
257 ">"; 262 String s2 = "<" + v2.X.ToString(nfi) + "," + v2.Y.ToString(nfi) + "," + v2.Z.ToString(nfi) + ">";
258 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + 263 String s3 = "<" + v3.X.ToString(nfi) + "," + v3.Y.ToString(nfi) + "," + v3.Z.ToString(nfi) + ">";
259 ">";
260 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) +
261 ">";
262 264
263 return s1 + ";" + s2 + ";" + s3; 265 return s1 + ";" + s2 + ";" + s3;
264 } 266 }
@@ -271,23 +273,17 @@ public class Triangle
271 PhysicsVector e1; 273 PhysicsVector e1;
272 PhysicsVector e2; 274 PhysicsVector e2;
273 275
274 e1 = new PhysicsVector(v1.point.X - v2.point.X, v1.point.Y - v2.point.Y, v1.point.Z - v2.point.Z); 276 e1 = new PhysicsVector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
275 e2 = new PhysicsVector(v1.point.X - v3.point.X, v1.point.Y - v3.point.Y, v1.point.Z - v3.point.Z); 277 e2 = new PhysicsVector(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z);
276 278
277 // Cross product for normal 279 // Cross product for normal
278 PhysicsVector n = new PhysicsVector(); 280 PhysicsVector n = PhysicsVector.cross(e1, e2);
279 float nx, ny, nz;
280 n.X = e1.Y*e2.Z - e1.Z*e2.Y;
281 n.Y = e1.Z*e2.X - e1.X*e2.Z;
282 n.Z = e1.X*e2.Y - e1.Y*e2.X;
283 281
284 // Length 282 // Length
285 float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z); 283 float l = n.length();
286 284
287 // Normalized "normal" 285 // Normalized "normal"
288 n.X /= l; 286 n = n / l;
289 n.Y /= l;
290 n.Z /= l;
291 287
292 return n; 288 return n;
293 } 289 }
@@ -299,4 +295,12 @@ public class Triangle
299 v1 = v2; 295 v1 = v2;
300 v2 = vt; 296 v2 = vt;
301 } 297 }
302} \ No newline at end of file 298
299 // Dumps a triangle in the "raw faces" format, blender can import. This is for visualisation and
300 // debugging purposes
301 public String ToStringRaw()
302 {
303 String output = v1.ToRaw() + " " + v2.ToRaw() + " " +v3.ToRaw();
304 return output;
305 }
306}