Browse Source

integrate Sphere class into Raycaster

Ben Houston 12 years ago
parent
commit
49cdafe26e
1 changed files with 8 additions and 9 deletions
  1. 8 9
      src/core/Raycaster.js

+ 8 - 9
src/core/Raycaster.js

@@ -12,6 +12,8 @@
 
 	};
 
+	var sphere = new THREE.Sphere();
+
 	var originCopy = new THREE.Vector3();
 
 	var localOriginCopy = new THREE.Vector3();
@@ -76,15 +78,12 @@
 
 		} else if ( object instanceof THREE.Mesh ) {
 
-			// Checking boundingSphere
-
-			var scaledRadius = object.geometry.boundingSphere.radius * object.matrixWorld.getMaxScaleOnAxis();
-
-			// Checking distance to raycaster
-
-			var distance = raycaster.ray.distanceToPoint( object.matrixWorld.getPosition() );
-
-			if ( distance > scaledRadius) {
+			// Checking boundingSphere distance to ray
+			sphere.set(
+				object.matrixWorld.getPosition(),
+				object.geometry.boundingSphere.radius* object.matrixWorld.getMaxScaleOnAxis() );
+			
+			if ( ! raycaster.ray.isIntersectionSphere( sphere ) ) {
 
 				return intersects;