diff options
author | Dahlia Trimble | 2008-11-29 11:02:14 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-11-29 11:02:14 +0000 |
commit | fdd238833163eb947986bfcdd09da82f6949a5f2 (patch) | |
tree | 6b90177758405f6106f4f5d4d75e3b98bf08053c /OpenSim/Region/Physics/Meshing/Simplex.cs | |
parent | Comment the ScriptSponsor and restore the indefinite lifetime for (diff) | |
download | opensim-SC_OLD-fdd238833163eb947986bfcdd09da82f6949a5f2.zip opensim-SC_OLD-fdd238833163eb947986bfcdd09da82f6949a5f2.tar.gz opensim-SC_OLD-fdd238833163eb947986bfcdd09da82f6949a5f2.tar.bz2 opensim-SC_OLD-fdd238833163eb947986bfcdd09da82f6949a5f2.tar.xz |
Update meshing code to sync with current PrimMesher.cs on forge.
Migrate sculpt meshing code to primMesher version. This should result in more accurate physical sculpted prim proxies.
Remove much obsolete code from Region/Physics/Meshing
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Simplex.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Simplex.cs | 220 |
1 files changed, 0 insertions, 220 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Simplex.cs b/OpenSim/Region/Physics/Meshing/Simplex.cs deleted file mode 100644 index aeeef11..0000000 --- a/OpenSim/Region/Physics/Meshing/Simplex.cs +++ /dev/null | |||
@@ -1,220 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Physics.Manager; | ||
30 | |||
31 | namespace OpenSim.Region.Physics.Meshing | ||
32 | { | ||
33 | // A simplex is a section of a straight line. | ||
34 | // It is defined by its endpoints, i.e. by two vertices | ||
35 | // Operation on vertices are | ||
36 | public class Simplex : IComparable<Simplex> | ||
37 | { | ||
38 | public Vertex v1; | ||
39 | public Vertex v2; | ||
40 | |||
41 | public Simplex(Vertex _v1, Vertex _v2) | ||
42 | { | ||
43 | v1 = _v1; | ||
44 | v2 = _v2; | ||
45 | } | ||
46 | |||
47 | public int CompareTo(Simplex other) | ||
48 | { | ||
49 | Vertex lv1, lv2, ov1, ov2, temp; | ||
50 | |||
51 | lv1 = v1; | ||
52 | lv2 = v2; | ||
53 | ov1 = other.v1; | ||
54 | ov2 = other.v2; | ||
55 | |||
56 | if (lv1 > lv2) | ||
57 | { | ||
58 | temp = lv1; | ||
59 | lv1 = lv2; | ||
60 | lv2 = temp; | ||
61 | } | ||
62 | |||
63 | if (ov1 > ov2) | ||
64 | { | ||
65 | temp = ov1; | ||
66 | ov1 = ov2; | ||
67 | ov2 = temp; | ||
68 | } | ||
69 | |||
70 | if (lv1 > ov1) | ||
71 | { | ||
72 | return 1; | ||
73 | } | ||
74 | if (lv1 < ov1) | ||
75 | { | ||
76 | return -1; | ||
77 | } | ||
78 | |||
79 | if (lv2 > ov2) | ||
80 | { | ||
81 | return 1; | ||
82 | } | ||
83 | if (lv2 < ov2) | ||
84 | { | ||
85 | return -1; | ||
86 | } | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | private static void intersectParameter(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, | ||
92 | ref float lambda, ref float mu) | ||
93 | { | ||
94 | // Intersects two straights | ||
95 | // p1, p2, points on the straight | ||
96 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! | ||
97 | // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, | ||
98 | // thus allowing to decide whether an intersection is between two points | ||
99 | |||
100 | float r1x = r1.X; | ||
101 | float r1y = r1.Y; | ||
102 | float r2x = r2.X; | ||
103 | float r2y = r2.Y; | ||
104 | |||
105 | float denom = r1y*r2x - r1x*r2y; | ||
106 | |||
107 | float p1x = p1.X; | ||
108 | float p1y = p1.Y; | ||
109 | float p2x = p2.X; | ||
110 | float p2y = p2.Y; | ||
111 | |||
112 | float z1 = -p2x*r2y + p1x*r2y + (p2y - p1y)*r2x; | ||
113 | float z2 = -p2x*r1y + p1x*r1y + (p2y - p1y)*r1x; | ||
114 | |||
115 | if (denom == 0.0f) // Means the straights are parallel. Either no intersection or an infinite number of them | ||
116 | { | ||
117 | if (z1 == 0.0f) | ||
118 | { | ||
119 | // Means they are identical -> many, many intersections | ||
120 | lambda = Single.NaN; | ||
121 | mu = Single.NaN; | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | lambda = Single.PositiveInfinity; | ||
126 | mu = Single.PositiveInfinity; | ||
127 | } | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | |||
132 | lambda = z1/denom; | ||
133 | mu = z2/denom; | ||
134 | } | ||
135 | |||
136 | |||
137 | // Intersects the simplex with another one. | ||
138 | // the borders are used to deal with float inaccuracies | ||
139 | // As a rule of thumb, the borders are | ||
140 | // lowerBorder1 : 0.0 | ||
141 | // lowerBorder2 : 0.0 | ||
142 | // upperBorder1 : 1.0 | ||
143 | // upperBorder2 : 1.0 | ||
144 | // 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 | public static PhysicsVector Intersect( | ||
146 | Simplex s1, | ||
147 | Simplex s2, | ||
148 | float lowerBorder1, | ||
149 | float lowerBorder2, | ||
150 | float upperBorder1, | ||
151 | float upperBorder2) | ||
152 | { | ||
153 | PhysicsVector firstSimplexDirection = s1.v2 - s1.v1; | ||
154 | PhysicsVector secondSimplexDirection = s2.v2 - s2.v1; | ||
155 | |||
156 | float lambda = 0.0f; | ||
157 | float mu = 0.0f; | ||
158 | |||
159 | // Give us the parameters of an intersection. This subroutine does *not* take the constraints | ||
160 | // (intersection must be between v1 and v2 and it must be in the positive direction of the ray) | ||
161 | // into account. We do that afterwards. | ||
162 | intersectParameter(s1.v1, firstSimplexDirection, s2.v1, secondSimplexDirection, ref lambda, ref mu); | ||
163 | |||
164 | if (Single.IsInfinity(lambda)) // Special case. No intersection at all. directions parallel. | ||
165 | return null; | ||
166 | |||
167 | if (Single.IsNaN(lambda)) // Special case. many, many intersections. | ||
168 | return null; | ||
169 | |||
170 | if (lambda > upperBorder1) // We're behind v2 | ||
171 | return null; | ||
172 | |||
173 | if (lambda < lowerBorder1) | ||
174 | return null; | ||
175 | |||
176 | if (mu < lowerBorder2) // outside simplex 2 | ||
177 | return null; | ||
178 | |||
179 | if (mu > upperBorder2) // outside simplex 2 | ||
180 | return null; | ||
181 | |||
182 | return s1.v1 + lambda*firstSimplexDirection; | ||
183 | } | ||
184 | |||
185 | // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction | ||
186 | // where lambda >= 0 | ||
187 | public PhysicsVector RayIntersect(Vertex origin, PhysicsVector direction, bool bEndsIncluded) | ||
188 | { | ||
189 | PhysicsVector simplexDirection = v2 - v1; | ||
190 | |||
191 | float lambda = 0.0f; | ||
192 | float mu = 0.0f; | ||
193 | |||
194 | // Give us the parameters of an intersection. This subroutine does *not* take the constraints | ||
195 | // (intersection must be between v1 and v2 and it must be in the positive direction of the ray) | ||
196 | // into account. We do that afterwards. | ||
197 | intersectParameter(v1, simplexDirection, origin, direction, ref lambda, ref mu); | ||
198 | |||
199 | if (Single.IsInfinity(lambda)) // Special case. No intersection at all. directions parallel. | ||
200 | return null; | ||
201 | |||
202 | if (Single.IsNaN(lambda)) // Special case. many, many intersections. | ||
203 | return null; | ||
204 | |||
205 | if (mu < 0.0) // We're on the wrong side of the ray | ||
206 | return null; | ||
207 | |||
208 | if (lambda > 1.0) // We're behind v2 | ||
209 | return null; | ||
210 | |||
211 | if (lambda == 1.0 && !bEndsIncluded) | ||
212 | return null; // The end of the simplices are not included | ||
213 | |||
214 | if (lambda < 0.0f) // we're before v1; | ||
215 | return null; | ||
216 | |||
217 | return v1 + lambda*simplexDirection; | ||
218 | } | ||
219 | } | ||
220 | } | ||