提交 bd236dab 编写于 作者: M Mugen87

Added Box3/Sphere intersection tests

上级 717c5b29
......@@ -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();
......
......@@ -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 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册