diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Simplex.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Simplex.cs | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Simplex.cs b/OpenSim/Region/Physics/Meshing/Simplex.cs index 98e693a..8fba2bf 100644 --- a/OpenSim/Region/Physics/Meshing/Simplex.cs +++ b/OpenSim/Region/Physics/Meshing/Simplex.cs | |||
@@ -27,8 +27,6 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using OpenSim.Region.Physics.Manager; | 30 | using OpenSim.Region.Physics.Manager; |
33 | 31 | ||
34 | namespace OpenSim.Region.Physics.Meshing | 32 | namespace OpenSim.Region.Physics.Meshing |
@@ -49,7 +47,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
49 | 47 | ||
50 | public int CompareTo(Simplex other) | 48 | public int CompareTo(Simplex other) |
51 | { | 49 | { |
52 | |||
53 | Vertex lv1, lv2, ov1, ov2, temp; | 50 | Vertex lv1, lv2, ov1, ov2, temp; |
54 | 51 | ||
55 | lv1 = v1; | 52 | lv1 = v1; |
@@ -92,8 +89,9 @@ namespace OpenSim.Region.Physics.Meshing | |||
92 | return 0; | 89 | return 0; |
93 | } | 90 | } |
94 | 91 | ||
95 | private static void intersectParameter(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu) | 92 | private static void intersectParameter(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, |
96 | { | 93 | ref float lambda, ref float mu) |
94 | { | ||
97 | // Intersects two straights | 95 | // Intersects two straights |
98 | // p1, p2, points on the straight | 96 | // p1, p2, points on the straight |
99 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! | 97 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! |
@@ -112,27 +110,28 @@ namespace OpenSim.Region.Physics.Meshing | |||
112 | float p2x = p2.X; | 110 | float p2x = p2.X; |
113 | float p2y = p2.Y; | 111 | float p2y = p2.Y; |
114 | 112 | ||
115 | float z1=-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x; | 113 | float z1 = -p2x*r2y + p1x*r2y + (p2y - p1y)*r2x; |
116 | float z2=-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x; | 114 | float z2 = -p2x*r1y + p1x*r1y + (p2y - p1y)*r1x; |
117 | 115 | ||
118 | if (denom == 0.0f) // Means the straights are parallel. Either no intersection or an infinite number of them | 116 | if (denom == 0.0f) // Means the straights are parallel. Either no intersection or an infinite number of them |
119 | { | 117 | { |
120 | if (z1==0.0f) {// Means they are identical -> many, many intersections | 118 | if (z1 == 0.0f) |
119 | { | ||
120 | // Means they are identical -> many, many intersections | ||
121 | lambda = Single.NaN; | 121 | lambda = Single.NaN; |
122 | mu = Single.NaN; | 122 | mu = Single.NaN; |
123 | } else { | 123 | } |
124 | else | ||
125 | { | ||
124 | lambda = Single.PositiveInfinity; | 126 | lambda = Single.PositiveInfinity; |
125 | mu = Single.PositiveInfinity; | 127 | mu = Single.PositiveInfinity; |
126 | } | 128 | } |
127 | return; | 129 | return; |
128 | |||
129 | } | 130 | } |
130 | 131 | ||
131 | 132 | ||
132 | 133 | lambda = z1/denom; | |
133 | lambda = z1 / denom; | 134 | mu = z2/denom; |
134 | mu = z2 / denom; | ||
135 | |||
136 | } | 135 | } |
137 | 136 | ||
138 | 137 | ||
@@ -145,12 +144,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
145 | // upperBorder2 : 1.0 | 144 | // upperBorder2 : 1.0 |
146 | // Set these to values near the given parameters (e.g. 0.001 instead of 1 to exclude simplex starts safely, or to -0.001 to include them safely) | 145 | // Set these to values near the given parameters (e.g. 0.001 instead of 1 to exclude simplex starts safely, or to -0.001 to include them safely) |
147 | public static PhysicsVector Intersect( | 146 | public static PhysicsVector Intersect( |
148 | Simplex s1, | 147 | Simplex s1, |
149 | Simplex s2, | 148 | Simplex s2, |
150 | float lowerBorder1, | 149 | float lowerBorder1, |
151 | float lowerBorder2, | 150 | float lowerBorder2, |
152 | float upperBorder1, | 151 | float upperBorder1, |
153 | float upperBorder2) | 152 | float upperBorder2) |
154 | { | 153 | { |
155 | PhysicsVector firstSimplexDirection = s1.v2 - s1.v1; | 154 | PhysicsVector firstSimplexDirection = s1.v2 - s1.v1; |
156 | PhysicsVector secondSimplexDirection = s2.v2 - s2.v1; | 155 | PhysicsVector secondSimplexDirection = s2.v2 - s2.v1; |
@@ -181,8 +180,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
181 | if (mu > upperBorder2) // outside simplex 2 | 180 | if (mu > upperBorder2) // outside simplex 2 |
182 | return null; | 181 | return null; |
183 | 182 | ||
184 | return s1.v1 + lambda * firstSimplexDirection; | 183 | return s1.v1 + lambda*firstSimplexDirection; |
185 | |||
186 | } | 184 | } |
187 | 185 | ||
188 | // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction | 186 | // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction |
@@ -212,15 +210,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
212 | return null; | 210 | return null; |
213 | 211 | ||
214 | if (lambda == 1.0 && !bEndsIncluded) | 212 | if (lambda == 1.0 && !bEndsIncluded) |
215 | return null; // The end of the simplices are not included | 213 | return null; // The end of the simplices are not included |
216 | 214 | ||
217 | if (lambda < 0.0f) // we're before v1; | 215 | if (lambda < 0.0f) // we're before v1; |
218 | return null; | 216 | return null; |
219 | 217 | ||
220 | return this.v1 + lambda * simplexDirection; | 218 | return v1 + lambda*simplexDirection; |
221 | |||
222 | } | 219 | } |
223 | |||
224 | |||
225 | } | 220 | } |
226 | } \ No newline at end of file | 221 | } \ No newline at end of file |