Represents a ray in 3D space with an origin and direction. More...
#include <Ray.h>
Public Member Functions | |
Ray () | |
Default constructor - creates a ray at origin pointing in positive Z direction. | |
Ray (const Vec3 &origin, const Vec3 &direction) | |
Constructs a ray with specified origin and direction. | |
Vec3 | GetPoint (float t) const |
Gets a point along the ray at parameter t. | |
bool | IntersectSphere (const Vec3 ¢er, float radius, float &t) const |
Tests intersection with a sphere. | |
bool | IntersectAABB (const Vec3 &minBounds, const Vec3 &maxBounds, float &t) const |
Tests intersection with an axis-aligned bounding box. | |
bool | IntersectTriangle (const Vec3 &v0, const Vec3 &v1, const Vec3 &v2, float &t) const |
Tests intersection with a triangle using the Möller-Trumbore algorithm. | |
bool | IntersectMesh (const std::vector< float > &vertices, const std::vector< unsigned int > &indices, float &t) const |
Tests intersection with a mesh by testing all triangles. | |
bool | IntersectMesh (const std::vector< float > &vertices, const std::vector< unsigned int > &indices, const Mat4 &transform, float &t) const |
Tests intersection with a mesh by testing all triangles, with transformation. | |
Vec3 | GetOrigin () const |
Gets the origin of the ray. | |
Vec3 | GetDirection () const |
Gets the direction of the ray. | |
Static Public Member Functions | |
static Vec3 | ClosestPointOnLine (const Vec3 &rayOrigin, const Vec3 &linePoint, const Vec3 &lineDirection) |
Calculate the closest point on a line to a ray. | |
static float | DistanceToLineSegment (const Vec3 &rayOrigin, const Vec3 &rayDirection, const Vec3 &segmentStart, const Vec3 &segmentEnd) |
Calculate the distance from a ray to a line segment. | |
Public Attributes | |
Vec3 | origin |
The starting point of the ray. | |
Vec3 | direction |
The normalized direction vector of the ray. | |
Represents a ray in 3D space with an origin and direction.
A ray is defined by an origin point and a normalized direction vector. Used for ray casting operations like object picking and collision detection.
Ray::Ray | ( | ) |
Default constructor - creates a ray at origin pointing in positive Z direction.
Constructs a ray with specified origin and direction.
origin | The starting point of the ray. |
direction | The direction vector (will be normalized). |
|
static |
Calculate the closest point on a line to a ray.
rayOrigin | Origin of the ray. |
rayDirection | Direction of the ray. |
linePoint | A point on the line. |
lineDirection | Direction of the line. |
|
static |
Calculate the distance from a ray to a line segment.
rayOrigin | Origin of the ray. |
rayDirection | Direction of the ray. |
segmentStart | Start point of the line segment. |
segmentEnd | End point of the line segment. |
Vec3 Ray::GetDirection | ( | ) | const |
Gets the direction of the ray.
Vec3 Ray::GetOrigin | ( | ) | const |
Gets the origin of the ray.
Vec3 Ray::GetPoint | ( | float | t | ) | const |
Gets a point along the ray at parameter t.
t | The parameter value (distance along ray). |
Tests intersection with an axis-aligned bounding box.
minBounds | Minimum corner of the box. |
maxBounds | Maximum corner of the box. |
t | Output parameter for intersection distance. |
bool Ray::IntersectMesh | ( | const std::vector< float > & | vertices, |
const std::vector< unsigned int > & | indices, | ||
const Mat4 & | transform, | ||
float & | t | ||
) | const |
Tests intersection with a mesh by testing all triangles, with transformation.
vertices | Vertex data array (position, normal, texcoord per vertex). |
indices | Index data array. |
transform | Transformation matrix from object local space to world space. |
t | Output parameter for closest intersection distance. |
bool Ray::IntersectMesh | ( | const std::vector< float > & | vertices, |
const std::vector< unsigned int > & | indices, | ||
float & | t | ||
) | const |
Tests intersection with a mesh by testing all triangles.
vertices | Vertex data array (position, normal, texcoord per vertex). |
indices | Index data array. |
t | Output parameter for closest intersection distance. |
bool Ray::IntersectSphere | ( | const Vec3 & | center, |
float | radius, | ||
float & | t | ||
) | const |
Tests intersection with a sphere.
center | Center of the sphere. |
radius | Radius of the sphere. |
t | Output parameter for intersection distance. |
Tests intersection with a triangle using the Möller-Trumbore algorithm.
v0 | First vertex of the triangle. |
v1 | Second vertex of the triangle. |
v2 | Third vertex of the triangle. |
t | Output parameter for intersection distance. |
Vec3 Ray::direction |
The normalized direction vector of the ray.
Vec3 Ray::origin |
The starting point of the ray.