intersectsBoundingSphere
是Yuka js库中的一种函数,用于检测光线是否与包围球相交。
intersectsBoundingSphere(ray, sphere, target)
ray
: 需要检测的光线,是一个Ray
对象。sphere
: 需要检测的包围球,是一个Sphere
对象。target
: 可选参数,返回结果的向量。如果没有传递该参数,则会创建一个新的向量。import { Ray, Sphere } from 'yuka';
const ray = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ) );
const sphere = new Sphere( new Vector3( 0, 2, 0 ), 1 );
const intersection = new Vector3();
const result = intersectsBoundingSphere( ray, sphere, intersection );
if ( result !== Infinity ) {
console.log( `Intersection found at [${intersection.x}, ${intersection.y}, ${intersection.z}].` );
} else {
console.log( "No intersection found." );
}