aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D')
-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 23e8cf5b..540109dc 100755
--- a/js/helper-classes/3D/StageLine.js
+++ b/js/helper-classes/3D/StageLine.js
@@ -222,49 +222,59 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, {
222 if (s0 != s1) 222 if (s0 != s1)
223 { 223 {
224 var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); 224 var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) );
225 if (t == 0) 225 if (MathUtils.fpSign(t) === 0)
226 { 226 {
227 if (s1 > 0) // entering the material from the beginning of the line that is to be drawn 227 // the first point of the line is on the (infinite) extension of a side of the boundary.
228 // Make sure the point (pt0) is within the range of the polygon edge
229 var vt0 = vecUtils.vecSubtract(3, pt0, bp0),
230 vt1 = vecUtils.vecSubtract(3, bp1, pt0);
231 var dt0 = vecUtils.vecDot(3, vec, vt0),
232 dt1 = vecUtils.vecDot(3, vec, vt1);
233 var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1);
234 if ((st0 >= 0) && (st1 >= 0))
228 { 235 {
229 // see if the start point of the line is at a corner of the bounded plane 236 if (s1 > 0) // entering the material from the beginning of the line that is to be drawn
230 var lineDir = vecUtils.vecSubtract(3, pt1, pt0);
231 vecUtils.vecNormalize(3, lineDir);
232 var dist = vecUtils.vecDist( 3, pt0, bp1 );
233 var bp2, bv0, bv1, cross1, cross2, cross3;
234 if ( MathUtils.fpSign(dist) == 0)
235 { 237 {
236 bp2 = boundaryPts[(i+1) % 4]; 238 // see if the start point of the line is at a corner of the bounded plane
237 bv0 = vecUtils.vecSubtract(3, bp2, bp1); 239 var lineDir = vecUtils.vecSubtract(3, pt1, pt0);
238 bv1 = vecUtils.vecSubtract(3, bp0, bp1); 240 vecUtils.vecNormalize(3, lineDir);
239 cross1 = vecUtils.vecCross(3, bv0, lineDir); 241 var dist = vecUtils.vecDist( 3, pt0, bp1 );
240 cross2 = vecUtils.vecCross(3, lineDir, bv1); 242 var bp2, bv0, bv1, cross1, cross2, cross3;
241 cross3 = vecUtils.vecCross(3, bv0, bv1); 243 if ( MathUtils.fpSign(dist) == 0)
242 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
243 { 244 {
244 gotEnter = true; 245 bp2 = boundaryPts[(i+1) % 4];
245 this.addIntersection( plane, t, 1 ); 246 bv0 = vecUtils.vecSubtract(3, bp2, bp1);
247 bv1 = vecUtils.vecSubtract(3, bp0, bp1);
248 cross1 = vecUtils.vecCross(3, bv0, lineDir);
249 cross2 = vecUtils.vecCross(3, lineDir, bv1);
250 cross3 = vecUtils.vecCross(3, bv0, bv1);
251 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
252 {
253 gotEnter = true;
254 this.addIntersection( plane, t, 1 );
255 }
246 } 256 }
247 } 257 else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0)
248 else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0)
249 {
250 bp2 = boundaryPts[(i+2) % 4];
251 bv0 = vecUtils.vecSubtract(3, bp2, bp0);
252 bv1 = vecUtils.vecSubtract(3, bp1, bp0);
253 cross1 = vecUtils.vecCross(3, bv0, lineDir);
254 cross2 = vecUtils.vecCross(3, lineDir, bv1);
255 cross3 = vecUtils.vecCross(3, bv0, bv1);
256 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
257 { 258 {
259 bp2 = boundaryPts[(i+2) % 4];
260 bv0 = vecUtils.vecSubtract(3, bp2, bp0);
261 bv1 = vecUtils.vecSubtract(3, bp1, bp0);
262 cross1 = vecUtils.vecCross(3, bv0, lineDir);
263 cross2 = vecUtils.vecCross(3, lineDir, bv1);
264 cross3 = vecUtils.vecCross(3, bv0, bv1);
265 if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0))
266 {
267 gotEnter = true;
268 this.addIntersection( plane, t, 1 );
269 }
270 }
271 else
272 {
273 // check if the line is on the edge of the boundary or goes to the interior
258 gotEnter = true; 274 gotEnter = true;
259 this.addIntersection( plane, t, 1 ); 275 this.addIntersection( plane, t, 1 );
260 } 276 }
261 } 277 }
262 else
263 {
264 // check if the line is on the edge of the boundary or goes to the interior
265 gotEnter = true;
266 this.addIntersection( plane, t, 1 );
267 }
268 } 278 }
269 } 279 }
270 else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) 280 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 44e2499d..409d2750 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -815,7 +815,8 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
815 { 815 {
816 //var t = vec1.modulus() / vec0.modulus(); 816 //var t = vec1.modulus() / vec0.modulus();
817 var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0); 817 var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0);
818 if ((this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0)) 818 var dot = VecUtils.vecDot(2, vec0, vec1);
819 if ((this.fpSign(dot) >= 0) && (this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0))
819 return this.ON; 820 return this.ON;
820 else 821 else
821 return this.OUTSIDE; 822 return this.OUTSIDE;