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.js76
1 files changed, 43 insertions, 33 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))