Browse Source

expand Frustum.contains() per @alteredq, @gero3

Ben Houston 12 years ago
parent
commit
b358c94547
1 changed files with 18 additions and 3 deletions
  1. 18 3
      src/math/Frustum.js

+ 18 - 3
src/math/Frustum.js

@@ -72,10 +72,25 @@ THREE.Frustum.prototype = {
 
 
 	contains: function ( object ) {
 	contains: function ( object ) {
 
 
-		var sphere = THREE.Frustum.__s0.copy( object.geometry.boundingSphere );
-		sphere.transform( object.matrixWorld );
+		// this method is expanded inlined for performance reasons.
+		var matrix = object.matrixWorld;
+		var planes = this.planes;
+		var center = matrix.getPosition();
+		var negRadius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
+		
+		for ( var i = 0; i < 6; i ++ ) {
+
+			var distance = planes[ i ].distanceToPoint( center );
+
+			if( distance < negRadius ) {
 
 
-		return this.containsSphere( sphere );
+				return false;
+
+			}
+
+		}
+
+		return true;
 
 
 	},
 	},