diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/HelperTypes.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/HelperTypes.cs | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index 232245f..8cd8dcf 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs | |||
@@ -33,30 +33,52 @@ using OpenMetaverse; | |||
33 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
34 | using OpenSim.Region.Physics.Meshing; | 34 | using OpenSim.Region.Physics.Meshing; |
35 | 35 | ||
36 | public class Vertex : PhysicsVector, IComparable<Vertex> | 36 | public class Vertex : IComparable<Vertex> |
37 | { | 37 | { |
38 | Vector3 vector; | ||
39 | |||
40 | public float X | ||
41 | { | ||
42 | get { return vector.X; } | ||
43 | set { vector.X = value; } | ||
44 | } | ||
45 | |||
46 | public float Y | ||
47 | { | ||
48 | get { return vector.Y; } | ||
49 | set { vector.Y = value; } | ||
50 | } | ||
51 | |||
52 | public float Z | ||
53 | { | ||
54 | get { return vector.Z; } | ||
55 | set { vector.Z = value; } | ||
56 | } | ||
57 | |||
38 | public Vertex(float x, float y, float z) | 58 | public Vertex(float x, float y, float z) |
39 | : base(x, y, z) | ||
40 | { | 59 | { |
60 | vector.X = x; | ||
61 | vector.Y = y; | ||
62 | vector.Z = z; | ||
41 | } | 63 | } |
42 | 64 | ||
43 | public Vertex normalize() | 65 | public Vertex normalize() |
44 | { | 66 | { |
45 | float tlength = length(); | 67 | float tlength = vector.Length(); |
46 | if (tlength != 0) | 68 | if (tlength != 0f) |
47 | { | 69 | { |
48 | float mul = 1.0f / tlength; | 70 | float mul = 1.0f / tlength; |
49 | return new Vertex(X * mul, Y * mul, Z * mul); | 71 | return new Vertex(vector.X * mul, vector.Y * mul, vector.Z * mul); |
50 | } | 72 | } |
51 | else | 73 | else |
52 | { | 74 | { |
53 | return new Vertex(0, 0, 0); | 75 | return new Vertex(0f, 0f, 0f); |
54 | } | 76 | } |
55 | } | 77 | } |
56 | 78 | ||
57 | public Vertex cross(Vertex v) | 79 | public Vertex cross(Vertex v) |
58 | { | 80 | { |
59 | return new Vertex(Y * v.Z - Z * v.Y, Z * v.X - X * v.Z, X * v.Y - Y * v.X); | 81 | return new Vertex(vector.Y * v.Z - vector.Z * v.Y, vector.Z * v.X - vector.X * v.Z, vector.X * v.Y - vector.Y * v.X); |
60 | } | 82 | } |
61 | 83 | ||
62 | // disable warning: mono compiler moans about overloading | 84 | // disable warning: mono compiler moans about overloading |
@@ -160,9 +182,9 @@ public class Vertex : PhysicsVector, IComparable<Vertex> | |||
160 | return X * v.X + Y * v.Y + Z * v.Z; | 182 | return X * v.X + Y * v.Y + Z * v.Z; |
161 | } | 183 | } |
162 | 184 | ||
163 | public Vertex(PhysicsVector v) | 185 | public Vertex(Vector3 v) |
164 | : base(v.X, v.Y, v.Z) | ||
165 | { | 186 | { |
187 | vector = v; | ||
166 | } | 188 | } |
167 | 189 | ||
168 | public Vertex Clone() | 190 | public Vertex Clone() |
@@ -175,11 +197,15 @@ public class Vertex : PhysicsVector, IComparable<Vertex> | |||
175 | return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); | 197 | return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); |
176 | } | 198 | } |
177 | 199 | ||
200 | public float Length() | ||
201 | { | ||
202 | return vector.Length(); | ||
203 | } | ||
178 | 204 | ||
179 | public virtual bool Equals(Vertex v, float tolerance) | 205 | public virtual bool Equals(Vertex v, float tolerance) |
180 | { | 206 | { |
181 | PhysicsVector diff = this - v; | 207 | Vertex diff = this - v; |
182 | float d = diff.length(); | 208 | float d = diff.Length(); |
183 | if (d < tolerance) | 209 | if (d < tolerance) |
184 | return true; | 210 | return true; |
185 | 211 | ||
@@ -369,22 +395,22 @@ public class Triangle | |||
369 | return s1 + ";" + s2 + ";" + s3; | 395 | return s1 + ";" + s2 + ";" + s3; |
370 | } | 396 | } |
371 | 397 | ||
372 | public PhysicsVector getNormal() | 398 | public Vector3 getNormal() |
373 | { | 399 | { |
374 | // Vertices | 400 | // Vertices |
375 | 401 | ||
376 | // Vectors for edges | 402 | // Vectors for edges |
377 | PhysicsVector e1; | 403 | Vector3 e1; |
378 | PhysicsVector e2; | 404 | Vector3 e2; |
379 | 405 | ||
380 | e1 = new PhysicsVector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); | 406 | e1 = new Vector3(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); |
381 | e2 = new PhysicsVector(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); | 407 | e2 = new Vector3(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); |
382 | 408 | ||
383 | // Cross product for normal | 409 | // Cross product for normal |
384 | PhysicsVector n = PhysicsVector.cross(e1, e2); | 410 | Vector3 n = Vector3.Cross(e1, e2); |
385 | 411 | ||
386 | // Length | 412 | // Length |
387 | float l = n.length(); | 413 | float l = n.Length(); |
388 | 414 | ||
389 | // Normalized "normal" | 415 | // Normalized "normal" |
390 | n = n/l; | 416 | n = n/l; |