2
0
Эх сурвалжийг харах

Merge pull request #7376 from Mugen87/dev

Added Box3/Sphere intersection tests
Mr.doob 9 жил өмнө
parent
commit
80c4bbab81
2 өөрчлөгдсөн 23 нэмэгдсэн , 0 устгасан
  1. 10 0
      src/math/Box3.js
  2. 13 0
      src/math/Sphere.js

+ 10 - 0
src/math/Box3.js

@@ -247,6 +247,16 @@ THREE.Box3.prototype = {
 
 	},
 
+	isIntersectionSphere: function ( sphere ) {
+
+		// Find the point on the AABB closest to the sphere center.
+		var closestPoint = this.clampPoint( sphere.center );
+
+		// If that point is inside the sphere, the AABB and sphere intersect.
+		return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius )
+
+	},
+
 	clampPoint: function ( point, optionalTarget ) {
 
 		var result = optionalTarget || new THREE.Vector3();

+ 13 - 0
src/math/Sphere.js

@@ -92,12 +92,25 @@ THREE.Sphere.prototype = {
 
 	intersectsSphere: function ( sphere ) {
 
+		console.warn( 'THREE.Sphere: .intersectsSphere() has been renamed to .isIntersectionSphere().' );
+
+		return this.isIntersectionSphere( sphere );
+	},
+
+	isIntersectionSphere: function ( sphere ) {
+
 		var radiusSum = this.radius + sphere.radius;
 
 		return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
 
 	},
 
+	isIntersectionBox: function ( box ) {
+
+		return box.isIntersectionSphere( this );
+
+	},
+
 	clampPoint: function ( point, optionalTarget ) {
 
 		var deltaLengthSq = this.center.distanceToSquared( point );