diff options
author | Ananya Sen | 2012-07-09 16:52:49 -0700 |
---|---|---|
committer | Ananya Sen | 2012-07-09 16:52:49 -0700 |
commit | 2eb84584f44b8c774479d1af2ee1d810597474cf (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/helper-classes/3D/StageLine.js | |
parent | bf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff) | |
parent | cee0deca695359ab468bd06d0e05ed3b2010b338 (diff) | |
download | ninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts:
js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css
js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/helper-classes/3D/StageLine.js')
-rwxr-xr-x | js/helper-classes/3D/StageLine.js | 401 |
1 files changed, 206 insertions, 195 deletions
diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index 787a4568..5aaa325a 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -120,7 +121,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
120 | // add the intersection | 121 | // add the intersection |
121 | var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; | 122 | var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; |
122 | var deltaVis = (dot > 0) ? 1 : -1; | 123 | var deltaVis = (dot > 0) ? 1 : -1; |
123 | // if (plane.isBackFacing()) | 124 | // if (plane.isBackFacing()) |
124 | // deltaVis = (dot < 0) ? 1 : -1; | 125 | // deltaVis = (dot < 0) ? 1 : -1; |
125 | 126 | ||
126 | this.addIntersection( plane, t, deltaVis ); | 127 | this.addIntersection( plane, t, deltaVis ); |
@@ -175,14 +176,14 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
175 | MathUtils.negate( vec ); | 176 | MathUtils.negate( vec ); |
176 | planeEq = [-vec[1], vec[0], 0]; | 177 | planeEq = [-vec[1], vec[0], 0]; |
177 | var normal = [planeEq[0], planeEq[1], planeEq[2]]; | 178 | var normal = [planeEq[0], planeEq[1], planeEq[2]]; |
178 | // var d = -planeEq.dot(bPt0); | 179 | // var d = -planeEq.dot(bPt0); |
179 | var d = -vecUtils.vecDot(3, planeEq, bPt0); | 180 | var d = -vecUtils.vecDot(3, planeEq, bPt0); |
180 | planeEq[3] = d; | 181 | planeEq[3] = d; |
181 | 182 | ||
182 | t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); | 183 | t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); |
183 | if (t) | 184 | if (t) |
184 | { | 185 | { |
185 | if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! | 186 | if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! |
186 | { | 187 | { |
187 | // get the intersection point | 188 | // get the intersection point |
188 | var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); | 189 | var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); |
@@ -207,184 +208,194 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { | |||
207 | } | 208 | } |
208 | }, | 209 | }, |
209 | 210 | ||
210 | doCoplanarIntersection: { | 211 | doCoplanarIntersection: { |
211 | value: function( plane ) | 212 | value: function( plane ) |
212 | { | 213 | { |
213 | // get the boundary points for the plane | 214 | // get the boundary points for the plane |
214 | var boundaryPts = plane.getBoundaryPoints(); | 215 | var boundaryPts = plane.getBoundaryPoints(); |
215 | var planeEq = plane.getPlaneEq(); | 216 | var planeEq = plane.getPlaneEq(); |
216 | 217 | ||
217 | if (plane.isBackFacing()) | 218 | if (plane.isBackFacing()) |
218 | { | 219 | { |
219 | var tmp; | 220 | var tmp; |
220 | tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; | 221 | tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; |
221 | tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; | 222 | tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; |
222 | } | 223 | } |
223 | 224 | ||
224 | var pt0 = this.getPoint0(), | 225 | var pt0 = this.getPoint0(), |
225 | pt1 = this.getPoint1(); | 226 | pt1 = this.getPoint1(); |
226 | 227 | ||
227 | // keep a couple flags to prevent counting crossings twice in edge cases | 228 | // keep a couple flags to prevent counting crossings twice in edge cases |
228 | var gotEnter = false, | 229 | var gotEnter = false, |
229 | gotExit = false; | 230 | gotExit = false; |
230 | 231 | ||
231 | var bp1 = boundaryPts[3]; | 232 | var bp1 = boundaryPts[3]; |
232 | for (var i=0; i<4; i++) | 233 | for (var i=0; i<4; i++) |
233 | { | 234 | { |
234 | var bp0 = bp1; | 235 | var bp0 = bp1; |
235 | bp1 = boundaryPts[i]; | 236 | bp1 = boundaryPts[i]; |
236 | var vec = vecUtils.vecSubtract(3, bp1, bp0); | 237 | var vec = vecUtils.vecSubtract(3, bp1, bp0); |
237 | var nrm = vecUtils.vecCross(3, vec, planeEq); | 238 | var nrm = vecUtils.vecCross(3, vec, planeEq); |
238 | nrm[3] = -vecUtils.vecDot(3, bp0, nrm); | 239 | nrm[3] = -vecUtils.vecDot(3, bp0, nrm); |
239 | 240 | ||
240 | var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], | 241 | var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], |
241 | d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; | 242 | d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; |
242 | 243 | ||
243 | var s0 = MathUtils.fpSign(d0), | 244 | var s0 = MathUtils.fpSign(d0), |
244 | s1 = MathUtils.fpSign(d1); | 245 | s1 = MathUtils.fpSign(d1); |
245 | 246 | ||
246 | if (s0 != s1) | 247 | if (s0 != s1) |
247 | { | 248 | { |
248 | var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); | 249 | var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); |
249 | if (t == 0) | 250 | if (MathUtils.fpSign(t) === 0) |
250 | { | 251 | { |
251 | if (s1 > 0) // entering the material from the beginning of the line that is to be drawn | 252 | // the first point of the line is on the (infinite) extension of a side of the boundary. |
252 | { | 253 | // Make sure the point (pt0) is within the range of the polygon edge |
253 | // see if the start point of the line is at a corner of the bounded plane | 254 | var vt0 = vecUtils.vecSubtract(3, pt0, bp0), |
254 | var lineDir = vecUtils.vecSubtract(3, pt1, pt0); | 255 | vt1 = vecUtils.vecSubtract(3, bp1, pt0); |
255 | vecUtils.vecNormalize(3, lineDir); | 256 | var dt0 = vecUtils.vecDot(3, vec, vt0), |
256 | var dist = vecUtils.vecDist( 3, pt0, bp1 ); | 257 | dt1 = vecUtils.vecDot(3, vec, vt1); |
257 | var bp2, bv0, bv1, cross1, cross2, cross3; | 258 | var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1); |
258 | if ( MathUtils.fpSign(dist) == 0) | 259 | if ((st0 >= 0) && (st1 >= 0)) |
259 | { | ||
260 | bp2 = boundaryPts[(i+1) % 4]; | ||
261 | bv0 = vecUtils.vecSubtract(3, bp2, bp1); | ||
262 | bv1 = vecUtils.vecSubtract(3, bp0, bp1); | ||
263 | cross1 = vecUtils.vecCross(3, bv0, lineDir); | ||
264 | cross2 = vecUtils.vecCross(3, lineDir, bv1); | ||
265 | cross3 = vecUtils.vecCross(3, bv0, bv1); | ||
266 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) | ||
267 | { | ||
268 | gotEnter = true; | ||
269 | this.addIntersection( plane, t, 1 ); | ||
270 | } | ||
271 | } | ||
272 | else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) | ||
273 | { | ||
274 | bp2 = boundaryPts[(i+2) % 4]; | ||
275 | bv0 = vecUtils.vecSubtract(3, bp2, bp0); | ||
276 | bv1 = vecUtils.vecSubtract(3, bp1, bp0); | ||
277 | cross1 = vecUtils.vecCross(3, bv0, lineDir); | ||
278 | cross2 = vecUtils.vecCross(3, lineDir, bv1); | ||
279 | cross3 = vecUtils.vecCross(3, bv0, bv1); | ||
280 | if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) | ||
281 | { | ||
282 | gotEnter = true; | ||
283 | this.addIntersection( plane, t, 1 ); | ||
284 | } | ||
285 | } | ||
286 | else | ||
287 | { | ||
288 | // check if the line is on the edge of the boundary or goes to the interior | ||
289 | gotEnter = true; | ||
290 | this.addIntersection( plane, t, 1 ); | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) | ||
295 | { | ||
296 | // get the point where the line crosses the edge of the element plane | ||
297 | var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); | ||
298 | |||
299 | // we know that the line crosses the infinite extension of the edge. Determine | ||
300 | // if that crossing is within the bounds of the edge | ||
301 | var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), | ||
302 | dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); | ||
303 | if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) | ||
304 | { | ||
305 | // determine if the line is entering or exiting | ||