aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorValerio Virgillito2012-07-09 12:16:36 -0700
committerValerio Virgillito2012-07-09 12:16:36 -0700
commitbab026fb07f6137ca32cb501f2d7c8167a6bd733 (patch)
treee3d5acb6eb3f8c3be2e065b2ed7a602b65d53fba /js/helper-classes
parent1839f24e8dcbad38d1381bbcd65c17a9caa45987 (diff)
parent3df60279083f2cda60b3b871037c6d58454de5b2 (diff)
downloadninja-bab026fb07f6137ca32cb501f2d7c8167a6bd733.tar.gz
Merge pull request #357 from ericmueller/GridFixes
Fixes for incorrect line/polygon intersections.
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-xjs/helper-classes/3D/StageLine.js76
-rwxr-xr-xjs/helper-classes/3D/math-utils.js3
2 files changed, 45 insertions, 34 deletions
diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js
index 787a4568..aaa9f95d 100755
--- a/js/helper-classes/3D/StageLine.js
+++ b/js/helper-classes/3D/StageLine.js
@@ -246,49 +246,59 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
246 if (s0 != s1) 246 if (s0 != s1)
247 { 247 {
248 var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); 248 var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) );
249 if (t == 0) 249 if (MathUtils.fpSign(t) === 0)
250 { 250 {
251 if (s1 > 0) // entering the material from the beginning of the line that is to be drawn 251 // the first point of the line is on the (infinite) extension of a side of the boundary.
252 // Make sure the point (pt0) is within the range of the polygon edge
253 var vt0 = vecUtils.vecSubtract(3, pt0, bp0),
254 vt1 = vecUtils.vecSubtract(3, bp1, pt0);
255 var dt0 = vecUtils.vecDot(3, vec, vt0),
256 dt1 = vecUtils.vecDot(3, vec, vt1);
257 var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1);
258 if ((st0 >= 0) && (st1 >= 0))
252 { 259 {
253 // see if the start point of the line is at a corner of the bounded plane 260 if (s1 > 0) // entering the material from the beginning of the line that is to be drawn
254 var lineDir = vecUtils.vecSubtract(3, pt1, pt0);
255 vecUtils.vecNormalize(3, lineDir);
256 var dist = vecUtils.vecDist( 3, pt0, bp1 );
257 var bp2, bv0, bv1, cross1, cross2, cross3;
258 if ( MathUtils.fpSign(dist) == 0)
259 { 261 {
260 bp2 = boundaryPts[(i+1) % 4]; 262 // see if the start point of the line is at a corner of the bounded plane
261 bv0 = vecUtils.vecSubtract(3, bp2, bp1); 263 var lineDir = vecUtils.vecSubtract(3, pt1, pt0);
262 bv1 = vecUtils.vecSubtract(3, bp0, bp1); 264 vecUtils.vecNormalize(3, lineDir);
263 cross1 = vecUtils.vecCross(3, bv0, lineDir); 265 var dist = vecUtils.vecDist( 3, pt0, bp1 );
264 cross2 = vecUtils.vecCross(3, lineDir, bv1); 266 var bp2, bv0, bv1, cross1, cross2, cross3;
265 cross3 = vecUtils.vecCross(3, bv0, bv1); 267 if ( MathUtils.fpSign(dist) == 0)
266 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
267 { 268 {
268 gotEnter = true; 269 bp2 = boundaryPts[(i+1) % 4];
269 this.addIntersection( plane, t, 1 ); 270 bv0 = vecUtils.vecSubtract(3, bp2, bp1);
271 bv1 = vecUtils.vecSubtract(3, bp0, bp1);
272 cross1 = vecUtils.vecCross(3, bv0, lineDir);
273 cross2 = vecUtils.vecCross(3, lineDir, bv1);
274 cross3 = vecUtils.vecCross(3, bv0, bv1);
275 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
276 {
277 gotEnter = true;
278 this.addIntersection( plane, t, 1 );
279 }
270 } 280 }
271 } 281 else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0)
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 {
283 bp2 = boundaryPts[(i+2) % 4];
284 bv0 = vecUtils.vecSubtract(3, bp2, bp0);
285 bv1 = vecUtils.vecSubtract(3, bp1, bp0);
286 cross1 = vecUtils.vecCross(3, bv0, lineDir);
287 cross2 = vecUtils.vecCross(3, lineDir, bv1);
288 cross3 = vecUtils.vecCross(3, bv0, bv1);
289 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
290 {
291 gotEnter = true;
292 this.addIntersection( plane, t, 1 );
293 }
294 }
295 else
296 {
297 // check if the line is on the edge of the boundary or goes to the interior
282 gotEnter = true; 298 gotEnter = true;
283 this.addIntersection( plane, t, 1 ); 299 this.addIntersection( plane, t, 1 );
284 } 300 }
285 } 301 }
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 } 302 }
293 } 303 }
294 else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) 304 else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0))
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 8a9be4b5..d793960c 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -839,7 +839,8 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
839 { 839 {
840 //var t = vec1.modulus() / vec0.modulus(); 840 //var t = vec1.modulus() / vec0.modulus();
841 var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0); 841 var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0);
842 if ((this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0)) 842 var dot = VecUtils.vecDot(2, vec0, vec1);
843 if ((this.fpSign(dot) >= 0) && (this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0))
843 return this.ON; 844 return this.ON;
844 else 845 else
845 return this.OUTSIDE; 846 return this.OUTSIDE;