Skip to main content

Ray

Ray defined by origin and direction, stored as [ox, oy, oz, dx, dy, dz]. Functions modify the first argument in-place unless noted.


Functions Reference

Creation

FunctionReturnsDescription
ray_create(origin = [0,0,0], direction = [0,0,-1])ArrayCreates a new ray.
ray_set(r, origin, direction)-Sets origin and direction.
ray_copy(r, src)-Copies values from src.
ray_clone(r)ArrayReturns a copy of the ray.

Operations

FunctionReturnsDescription
ray_at(r, t, [out])ArrayPoint along ray at distance t.
ray_recenter(r, origin)-Moves origin to given point.
ray_look_at(r, target)-Points ray direction towards target.
ray_intersect_sphere(r, sphere)numberDistance to intersection or -1.
ray_intersect_box(r, box)numberDistance to intersection or -1.
ray_apply_matrix4(r, m)-Transforms origin and direction by 4x4 matrix.
ray_equals(r, other)booleanReturns true if origin and direction match.
ray_recast(r, t)-Shifts origin along direction by distance t.
ray_intersect_plane(r, plane, [out])Array | undefinedIntersection point with plane or undefined.
ray_distance_to_plane(r, plane)number | undefinedDistance to intersection with plane or undefined.
ray_intersects_box(r, box)booleanReturns true if ray intersects box.
ray_intersects_plane(r, plane)booleanReturns true if ray intersects plane.
ray_intersects_sphere(r, sphere)booleanReturns true if ray intersects sphere.
ray_distance_to_point(r, point)numberDistance from ray to point.
ray_distance_sq_to_point(r, point)numberSquared distance from ray to point.
ray_closest_point_to_point(r, point, [out])ArrayClosest point on ray to given point.
ray_distance_sq_to_segment(r, v0, v1, [outRay], [outSeg])numberSquared distance between ray and segment; optional closest points.
ray_intersect_sphere_point(r, sphere, [out])Array | undefinedIntersection point with sphere or undefined.
ray_intersect_triangle(r, a, b, c, backfaceCulling?, [out])Array | undefinedIntersection point with triangle or undefined.