Browse Source

Frustum.contains -> intersectsObject, containsSphere->intersectsSphere, removed Frustum.containsAnyPoints, .transform. Update unit tests accordingly.

Ben Houston 12 years ago
parent
commit
6f72a001c2

+ 1 - 1
docs/api/math/Frustum.html

@@ -29,7 +29,7 @@
 
 		<h3>.setFromMatrix( [page:Matrix4 matrix] )</h3>
 
-		<h3>.contains( [page:Object3D object] ) [page:Boolean]</h3>
+		<h3>.intersectsObject( [page:Object3D object] ) [page:Boolean]</h3>
 		<div>
 		Checks whether the object is inside the Frustum.
 		</div>

+ 1 - 1
src/core/Projector.js

@@ -94,7 +94,7 @@ THREE.Projector = function() {
 
 				} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) {
 
-					if ( object.frustumCulled === false || _frustum.contains( object ) === true ) {
+					if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
 
 						_object = getNextObjectInPool();
 						_object.object = object;

+ 1 - 1
src/extras/renderers/plugins/DepthPassPlugin.js

@@ -88,7 +88,7 @@ THREE.DepthPassPlugin = function ( ) {
 
 			if ( object.visible ) {
 
-				if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
+				if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.intersectsObject( object ) ) {
 
 					object._modelViewMatrix.multiply( camera.matrixWorldInverse, object.matrixWorld );
 

+ 1 - 1
src/extras/renderers/plugins/ShadowMapPlugin.js

@@ -238,7 +238,7 @@ THREE.ShadowMapPlugin = function ( ) {
 
 				if ( object.visible && object.castShadow ) {
 
-					if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
+					if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.intersectsObject( object ) ) {
 
 						object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld );
 

+ 2 - 48
src/math/Frustum.js

@@ -70,7 +70,7 @@ THREE.Frustum.prototype = {
 
 	},
 
-	contains: function ( object ) {
+	intersectsObject: function ( object ) {
 
 		// this method is expanded inlined for performance reasons.
 		var matrix = object.matrixWorld;
@@ -94,7 +94,7 @@ THREE.Frustum.prototype = {
 
 	},
 
-	containsSphere: function ( sphere ) {
+	intersectsSphere: function ( sphere ) {
 		
 		var planes = this.planes;
 		var center = sphere.center;
@@ -134,52 +134,6 @@ THREE.Frustum.prototype = {
 
 	},
 
-	containsAnyPoints: function ( points ) {
-
-		var planes = this.planes;
-		var p0 = planes[ 0 ];
-		var p1 = planes[ 1 ];
-		var p2 = planes[ 2 ];
-		var p3 = planes[ 3 ];
-		var p4 = planes[ 4 ];
-		var p5 = planes[ 5 ];
-			
-		for( var j = 0, jl = points.length; j < jl; j ++ ) {
-
-			var pt = points[j];
-
-			if(
-				( p0.distanceToPoint( pt ) >= 0 ) && 
-				( p1.distanceToPoint( pt ) >= 0 ) && 
-				( p2.distanceToPoint( pt ) >= 0 ) && 
-				( p3.distanceToPoint( pt ) >= 0 ) && 
-				( p4.distanceToPoint( pt ) >= 0 ) && 
-				( p5.distanceToPoint( pt ) >= 0 )
-				) {
-
-				return true;
-
-			}
-
-		}
-
-		return false;
-	},
-
-	transform: function ( matrix, optionalNormalMatrix ) {
-
-		optionalNormalMatrix = optionalNormalMatrix || new THREE.Matrix3().getInverse( matrix ).transpose();
-
-		for( var i = 0; i < 6; i ++ ) {
-
-			this.planes[i].transform( matrix, optionalNormalMatrix );
-
-		}
-
-		return this;
-		
-	},
-
 	clone: function () {
 
 		var planes = this.planes;

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -4107,7 +4107,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			if ( object.visible ) {
 
-				if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
+				if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.intersectsObject( object ) ) {
 
 					setupMatrices( object, camera );
 

+ 21 - 56
test/unit/math/Frustum.js

@@ -106,65 +106,30 @@ test( "setFromMatrix/makeFrustum/containsPoint", function() {
 	ok( ! a.containsPoint( new THREE.Vector3( 0, 0, -101 ) ), "Passed!" );
 });
 
-test( "setFromMatrix/makeFrustum/containsSphere", function() {
+test( "setFromMatrix/makeFrustum/intersectsSphere", function() {
 	var m = new THREE.Matrix4().makeFrustum( -1, 1, -1, 1, 1, 100 )
 	var a = new THREE.Frustum().setFromMatrix( m );
 
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 0 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 0.9 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 1.1 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -50 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -1.001 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( -1, -1, -1.001 ), 0 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( -1.1, -1.1, -1.001 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( -1.1, -1.1, -1.001 ), 0.5 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 1, 1, -1.001 ), 0 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( 1.1, 1.1, -1.001 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 1.1, 1.1, -1.001 ), 0.5 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -99.999 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( -99.999, -99.999, -99.999 ), 0 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( -100.1, -100.1, -100.1 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( -100.1, -100.1, -100.1 ), 0.5 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 99.999, 99.999, -99.999 ), 0 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( 100.1, 100.1, -100.1 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 100.1, 100.1, -100.1 ), 0.2 ) ), "Passed!" );
-	ok( ! a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -101 ), 0 ) ), "Passed!" );
-	ok( a.containsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -101 ), 1.1 ) ), "Passed!" );
-});
-
-test( "transform", function() {
-
-	var p0 = new THREE.Plane( unit3, -1 );
-	var p1 = new THREE.Plane( unit3, 1 );
-	var p2 = new THREE.Plane( unit3, 2 );
-	var p3 = new THREE.Plane( unit3, 3 );
-	var p4 = new THREE.Plane( unit3, 4 );
-	var p5 = new THREE.Plane( unit3, 5 );
-
-	var b = new THREE.Frustum( p0, p1, p2, p3, p4, p5 );
-	var a = new THREE.Frustum().copy( b ).transform( new THREE.Matrix4() );
-	ok( a.planes[0].equals( p0 ), "Passed!" );
-	ok( a.planes[1].equals( p1 ), "Passed!" );
-	ok( a.planes[2].equals( p2 ), "Passed!" );
-	ok( a.planes[3].equals( p3 ), "Passed!" );
-	ok( a.planes[4].equals( p4 ), "Passed!" );
-	ok( a.planes[5].equals( p5 ), "Passed!" );
-
-	a = new THREE.Frustum().copy( b ).transform( new THREE.Matrix4().makeRotationZ( Math.PI ) );
-	ok( ! planeEquals( a.planes[0], p0 ), "Passed!" );
-	ok( ! planeEquals( a.planes[1], p1 ), "Passed!" );
-	ok( ! planeEquals( a.planes[2], p2 ), "Passed!" );
-	ok( ! planeEquals( a.planes[3], p3 ), "Passed!" );
-	ok( ! planeEquals( a.planes[4], p4 ), "Passed!" );
-	ok( ! planeEquals( a.planes[5], p5 ), "Passed!" );
-
-	a = a.transform( new THREE.Matrix4().makeRotationZ( Math.PI ) );
-	ok( planeEquals( a.planes[0], p0 ), "Passed!" );
-	ok( planeEquals( a.planes[1], p1 ), "Passed!" );
-	ok( planeEquals( a.planes[2], p2 ), "Passed!" );
-	ok( planeEquals( a.planes[3], p3 ), "Passed!" );
-	ok( planeEquals( a.planes[4], p4 ), "Passed!" );
-	ok( planeEquals( a.planes[5], p5 ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 0 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 0.9 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, 0 ), 1.1 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -50 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -1.001 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -1, -1, -1.001 ), 0 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -1.1, -1.1, -1.001 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -1.1, -1.1, -1.001 ), 0.5 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 1, 1, -1.001 ), 0 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 1.1, 1.1, -1.001 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 1.1, 1.1, -1.001 ), 0.5 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -99.999 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -99.999, -99.999, -99.999 ), 0 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -100.1, -100.1, -100.1 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( -100.1, -100.1, -100.1 ), 0.5 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 99.999, 99.999, -99.999 ), 0 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 100.1, 100.1, -100.1 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 100.1, 100.1, -100.1 ), 0.2 ) ), "Passed!" );
+	ok( ! a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -101 ), 0 ) ), "Passed!" );
+	ok( a.intersectsSphere( new THREE.Sphere( new THREE.Vector3( 0, 0, -101 ), 1.1 ) ), "Passed!" );
 });
 
 test( "clone", function() {