aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/StageLine.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/StageLine.js')
-rwxr-xr-xjs/helper-classes/3D/StageLine.js87
1 files changed, 44 insertions, 43 deletions
diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js
index 8292c469..c358108f 100755
--- a/js/helper-classes/3D/StageLine.js
+++ b/js/helper-classes/3D/StageLine.js
@@ -122,7 +122,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
122 // add the intersection 122 // add the intersection
123 var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; 123 var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3];
124 var deltaVis = (dot > 0) ? 1 : -1; 124 var deltaVis = (dot > 0) ? 1 : -1;
125// if (plane.isBackFacing()) 125// if (plane.isBackFacing())
126// deltaVis = (dot < 0) ? 1 : -1; 126// deltaVis = (dot < 0) ? 1 : -1;
127 127
128 this.addIntersection( plane, t, deltaVis ); 128 this.addIntersection( plane, t, deltaVis );
@@ -194,14 +194,14 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
194 MathUtils.negate( vec ); 194 MathUtils.negate( vec );
195 planeEq = [-vec[1], vec[0], 0]; 195 planeEq = [-vec[1], vec[0], 0];
196 var normal = [planeEq[0], planeEq[1], planeEq[2]]; 196 var normal = [planeEq[0], planeEq[1], planeEq[2]];
197// var d = -planeEq.dot(bPt0); 197// var d = -planeEq.dot(bPt0);
198 var d = -vecUtils.vecDot(3, planeEq, bPt0); 198 var d = -vecUtils.vecDot(3, planeEq, bPt0);
199 planeEq[3] = d; 199 planeEq[3] = d;
200 200
201 t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); 201 t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq );
202 if (t) 202 if (t)
203 { 203 {
204 if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! 204 if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT!
205 { 205 {
206 // get the intersection point 206 // get the intersection point
207 var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); 207 var pt = MathUtils.interpolateLine3D( pt0, pt1, t );
@@ -384,50 +384,51 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
384 if ((st0 >= 0) && (st1 >= 0)) 384 if ((st0 >= 0) && (st1 >= 0))
385 { 385 {
386 //if ( (plane.isBackFacing() && (s1 < 0)) || (!plane.isBackFacing() && (s1 > 0)) ) // entering the material from the beginning of the line that is to be drawn 386 //if ( (plane.isBackFacing() && (s1 < 0)) || (!plane.isBackFacing() && (s1 > 0)) ) // entering the material from the beginning of the line that is to be drawn
387 if (s1 > 0) // entering the material from the beginning of the line that is to be drawn
387 if (s1 > 0) 388 if (s1 > 0)
389 {
390 // see if the start point of the line is at a corner of the bounded plane
391 var lineDir = vecUtils.vecSubtract(3, pt1, pt0);
392 vecUtils.vecNormalize(3, lineDir);
393 var dist = vecUtils.vecDist( 3, pt0, bp1 );
394 var bp2, bv0, bv1, cross1, cross2, cross3;
395 if ( MathUtils.fpSign(dist) == 0)
388 { 396 {
389 // see if the start point of the line is at a corner of the bounded plane 397 bp2 = boundaryPts[(i+1) % 4];
390 var lineDir = vecUtils.vecSubtract(3, pt1, pt0); 398 bv0 = vecUtils.vecSubtract(3, bp2, bp1);
391 vecUtils.vecNormalize(3, lineDir); 399 bv1 = vecUtils.vecSubtract(3, bp0, bp1);
392 var dist = vecUtils.vecDist( 3, pt0, bp1 ); 400 cross1 = vecUtils.vecCross(3, bv0, lineDir);
393 var bp2, bv0, bv1, cross1, cross2, cross3; 401 cross2 = vecUtils.vecCross(3, lineDir, bv1);
394 if ( MathUtils.fpSign(dist) == 0) 402 cross3 = vecUtils.vecCross(3, bv0, bv1);
395 { 403 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
396 bp2 = boundaryPts[(i+1) % 4];
397 bv0 = vecUtils.vecSubtract(3, bp2, bp1);
398 bv1 = vecUtils.vecSubtract(3, bp0, bp1);
399 cross1 = vecUtils.vecCross(3, bv0, lineDir);
400 cross2 = vecUtils.vecCross(3, lineDir, bv1);
401 cross3 = vecUtils.vecCross(3, bv0, bv1);
402 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
403 {
404 gotEnter = true;
405 this.addIntersection( plane, t, 1 );
406 }
407 }
408 else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0)
409 { 404 {
410 bp2 = boundaryPts[(i+2) % 4]; 405 gotEnter = true;
411 bv0 = vecUtils.vecSubtract(3, bp2, bp0); 406 this.addIntersection( plane, t, 1 );
412 bv1 = vecUtils.vecSubtract(3, bp1, bp0);
413 cross1 = vecUtils.vecCross(3, bv0, lineDir);
414 cross2 = vecUtils.vecCross(3, lineDir, bv1);
415 cross3 = vecUtils.vecCross(3, bv0, bv1);
416 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
417 {
418 gotEnter = true;
419 this.addIntersection( plane, t, 1 );
420 }
421 } 407 }
422 else 408 }
409 else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0)
410 {
411 bp2 = boundaryPts[(i+2) % 4];
412 bv0 = vecUtils.vecSubtract(3, bp2, bp0);
413 bv1 = vecUtils.vecSubtract(3, bp1, bp0);
414 cross1 = vecUtils.vecCross(3, bv0, lineDir);
415 cross2 = vecUtils.vecCross(3, lineDir, bv1);
416 cross3 = vecUtils.vecCross(3, bv0, bv1);
417 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
423 { 418 {
424 // check if the line is on the edge of the boundary or goes to the interior
425 gotEnter = true; 419 gotEnter = true;
426 this.addIntersection( plane, t, 1 ); 420 this.addIntersection( plane, t, 1 );
427 } 421 }
428 } 422 }
423 else
424 {
425 // check if the line is on the edge of the boundary or goes to the interior
426 gotEnter = true;
427 this.addIntersection( plane, t, 1 );
428 }
429 } 429 }
430 } 430 }
431 }
431 else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) 432 else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0))
432 { 433 {
433 // get the point where the line crosses the edge of the element plane 434 // get the point where the line crosses the edge of the element plane
@@ -440,7 +441,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
440 if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) 441 if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0))
441 { 442 {
442 // determine if the line is entering or exiting 443 // determine if the line is entering or exiting
443 if (s0 <= 0) // entering 444 if (s0 <= 0) // entering
444 { 445 {
445 if (!gotEnter) 446 if (!gotEnter)
446 { 447 {
@@ -456,7 +457,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
456 this.addIntersection( plane, t, -1 ); 457 this.addIntersection( plane, t, -1 );
457 } 458 }
458 } 459 }
459 else // s0 == 0 460 else // s0 == 0
460 { 461 {
461 // TODO 462 // TODO
462 } 463 }
@@ -481,7 +482,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
481 } 482 }
482 else if (s0 > 0) 483 else if (s0 > 0)
483 { 484 {
484 var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case 485 var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case
485 if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) 486 if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0))
486 { 487 {
487 gotEnter = true; 488 gotEnter = true;
@@ -509,7 +510,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
509 } 510 }
510 else if (s0 > 0) 511 else if (s0 > 0)
511 { 512 {
512 var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case 513 var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case
513 if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) 514 if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0))
514 { 515 {
515 gotEnter = true; 516 gotEnter = true;
@@ -588,12 +589,12 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
588 { 589 {
589 var pt0 = pt1; 590 var pt0 = pt1;
590 var pt1 = boundaryPts[i]; 591 var pt1 = boundaryPts[i];
591 //var vec0 = pt1.subtract( pt0 ), 592 //var vec0 = pt1.subtract( pt0 ),
592 // vec1 = pt.subtract( pt0 ); 593 // vec1 = pt.subtract( pt0 );
593 var vec0 = vecUtils.vecSubtract(3, pt1, pt0), 594 var vec0 = vecUtils.vecSubtract(3, pt1, pt0),
594 vec1 = vecUtils.vecSubtract(pt, pt0); 595 vec1 = vecUtils.vecSubtract(pt, pt0);
595 596
596 // var cross = vec0.cross( vec1 ); 597 // var cross = vec0.cross( vec1 );
597 var cross = vecUtils.vecCross(3, vec0, vec1); 598 var cross = vecUtils.vecCross(3, vec0, vec1);
598 var inside; 599 var inside;
599 if (backFacing) 600 if (backFacing)