Browse Source

added handling for when ray origin is inside sphere

erichlof 11 years ago
parent
commit
2ee0e0c776
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/math/Ray.js

+ 3 - 2
src/math/Ray.js

@@ -229,8 +229,6 @@ THREE.Ray.prototype = {
 
 			var tca = v1.dot( this.direction );
 
-			if ( tca < 0 ) return null;
-
 			var d2 = v1.dot( v1 ) - tca * tca;
 
 			var radius2 = sphere.radius * sphere.radius;
@@ -244,6 +242,9 @@ THREE.Ray.prototype = {
 
 			// t1 = second intersect point - exit point on back of sphere
 			var t1 = tca + thc;
+			
+			// test to see if both t0 and t1 are behind the ray - if so, return null
+			if ( t0 < 0 && t1 < 0 ) return null;
 		
 			// test to see if t0 is behind the ray:
 			// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,