MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / rayIntersectsSphere

Function rayIntersectsSphere

src/math/index.ts:340–346  ·  view source on GitHub ↗
(ray: Ray, center: Vec3, radius: number)

Source from the content-addressed store, hash-verified

338}
339
340export function rayIntersectsSphere(ray: Ray, center: Vec3, radius: number): boolean {
341 const oc: Vec3 = { x: ray.position.x - center.x, y: ray.position.y - center.y, z: ray.position.z - center.z };
342 const a = vec3Dot(ray.direction, ray.direction);
343 const b = 2.0 * vec3Dot(oc, ray.direction);
344 const c = vec3Dot(oc, oc) - radius * radius;
345 return b * b - 4 * a * c >= 0;
346}
347
348export function checkCollisionSpheres(center1: Vec3, radius1: number, center2: Vec3, radius2: number): boolean {
349 return vec3Distance(center1, center2) <= radius1 + radius2;

Callers

nothing calls this directly

Calls 1

vec3DotFunction · 0.85

Tested by

no test coverage detected