Docs

Ray

C++ type: Ray

Description

A ray defined by an origin point and a direction/length vector. Used for raycasting — detecting which objects lie along the ray. Doriax supports raycasts against geometric volumes (AABB, OBB, Sphere, Plane) and against the physics simulation (Body2D / Body3D).

The direction vector doubles as the length of the ray — objects beyond origin + direction are not reported as hits.

Properties

Type Name Langs
Vector3 origin C++ | Lua
Vector3 direction C++ | Lua

Methods

Type Name Langs
Vector3 getPoint C++ | Lua
RayReturn intersects C++ | Lua

Property details

origin / direction

  • Setter: void setOrigin(Vector3 point) / void setDirection(Vector3 direction)
  • Getter: Vector3 getOrigin() const / Vector3 getDirection() const

origin is the start of the ray. direction is both the normalised direction and the maximum reach (its magnitude = ray length). Use Camera::screenToRay() to generate a ray from a screen pixel.


Method details

getPoint

  • Vector3 getPoint(float distance) const

Returns the world-space point at distance units along the ray: origin + direction.normalized() * distance.


intersects

Multiple overloads for different collision targets:

Returns a RayReturn struct. Test the result with if (result) or result.hit.

// Screen-to-world raycast
Ray ray = camera.screenToRay(mouseX, mouseY);
RayReturn hit = ray.intersects(&scene, RayFilter::BODY_3D);
if (hit) {
    Log::print("Hit body at distance: " + std::to_string(hit.distance));
}
local ray = camera:screenToRay(mouseX, mouseY)
local hit = ray:intersects(scene, RayFilter.BODY_3D)
if hit.hit then
    Log.print("Hit at " .. tostring(hit.distance))
end

Enumerations

RayFilter

  • BODY_2D — Test against Body2D physics bodies.
  • BODY_3D — Test against Body3D physics bodies.