ray
| Type | Struct |
| Namespace | conjure::math |
| Include File Path | engine/include/conjure/core/math/ray.h |
| Source File Path | engine/src/core/math/ray.cpp |
| API ↗ | Math |
Syntax
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | direction | vec3 | vec3(0.0f, | |
| public | origin | vec3 | vec3(0.0f) |
Functions
Public
from_points
from_pointsThe ray from a to b with a normalised direction; a == b yields the default direction.
from_viewport
from_viewport[[nodiscard]] static ray from_viewport(
vec2 pixel,
uvec2 viewportSize,
const mat4 &inverseViewProjection) noexcept;The world-space pick ray through a viewport pixel (origin top-left, y down; pixel centres are at +0.5). The origin lies on the near plane (depth 0). Works for perspective, infinite and orthographic projections. A zero-sized viewport asserts and uses the viewport centre. Assumes forward depth (near plane at depth 0, far plane at 1, as math::perspective builds). The renderer's matrices are reverse-Z: use renderer::ray_from_viewport for them.
intersect
intersectSlab test against a box. Returns 0 when the origin is inside, nullopt for a miss, an invalid box or a box entirely behind the origin. Rays parallel to a slab are handled.
intersect_plane
intersect_planeHit with an infinite plane from either side. Returns nullopt when the ray is parallel to the plane (including when it lies in it) or the plane is behind the origin.
intersect_sphere
intersect_sphereNearest hit with a sphere. Returns 0 when the origin is inside; nullopt for a miss, a sphere behind the origin or a negative radius.
intersect_triangle
intersect_triangle[[nodiscard]] std::optional<f32> intersect_triangle(
vec3 a,
vec3 b,
vec3 c,
bool cullBackFaces = true) const noexcept;Moller-Trumbore triangle test. Triangles are counter-clockwise when seen from the front; with cullBackFaces the back side is ignored. Degenerate (collinear) triangles and rays parallel to the triangle never hit; the test is relative to the triangle size and the direction length, so millimetre triangles and grazing angles work. Edges and vertices count as hits.