Voltray Engine Docs
Loading...
Searching...
No Matches
Ray Struct Reference

Represents a ray in 3D space with an origin and direction. More...

#include <Ray.h>

Collaboration diagram for Ray:

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 &center, 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Ray() [1/2]

Ray::Ray ( )

Default constructor - creates a ray at origin pointing in positive Z direction.

◆ Ray() [2/2]

Ray::Ray ( const Vec3 origin,
const Vec3 direction 
)

Constructs a ray with specified origin and direction.

Parameters
originThe starting point of the ray.
directionThe direction vector (will be normalized).

Member Function Documentation

◆ ClosestPointOnLine()

static Vec3 Ray::ClosestPointOnLine ( const Vec3 rayOrigin,
const Vec3 linePoint,
const Vec3 lineDirection 
)
static

Calculate the closest point on a line to a ray.

Parameters
rayOriginOrigin of the ray.
rayDirectionDirection of the ray.
linePointA point on the line.
lineDirectionDirection of the line.
Returns
The closest point on the line to the ray.

◆ DistanceToLineSegment()

static float Ray::DistanceToLineSegment ( const Vec3 rayOrigin,
const Vec3 rayDirection,
const Vec3 segmentStart,
const Vec3 segmentEnd 
)
static

Calculate the distance from a ray to a line segment.

Parameters
rayOriginOrigin of the ray.
rayDirectionDirection of the ray.
segmentStartStart point of the line segment.
segmentEndEnd point of the line segment.
Returns
The shortest distance between the ray and line segment.

◆ GetDirection()

Vec3 Ray::GetDirection ( ) const

Gets the direction of the ray.

Returns
The normalized direction vector of the ray.

◆ GetOrigin()

Vec3 Ray::GetOrigin ( ) const

Gets the origin of the ray.

Returns
The origin point of the ray.

◆ GetPoint()

Vec3 Ray::GetPoint ( float  t) const

Gets a point along the ray at parameter t.

Parameters
tThe parameter value (distance along ray).
Returns
Point at origin + t * direction.

◆ IntersectAABB()

bool Ray::IntersectAABB ( const Vec3 minBounds,
const Vec3 maxBounds,
float &  t 
) const

Tests intersection with an axis-aligned bounding box.

Parameters
minBoundsMinimum corner of the box.
maxBoundsMaximum corner of the box.
tOutput parameter for intersection distance.
Returns
True if intersection occurs, false otherwise.

◆ IntersectMesh() [1/2]

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.

Parameters
verticesVertex data array (position, normal, texcoord per vertex).
indicesIndex data array.
transformTransformation matrix from object local space to world space.
tOutput parameter for closest intersection distance.
Returns
True if intersection occurs, false otherwise.

◆ IntersectMesh() [2/2]

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.

Parameters
verticesVertex data array (position, normal, texcoord per vertex).
indicesIndex data array.
tOutput parameter for closest intersection distance.
Returns
True if intersection occurs, false otherwise.

◆ IntersectSphere()

bool Ray::IntersectSphere ( const Vec3 center,
float  radius,
float &  t 
) const

Tests intersection with a sphere.

Parameters
centerCenter of the sphere.
radiusRadius of the sphere.
tOutput parameter for intersection distance.
Returns
True if intersection occurs, false otherwise.

◆ IntersectTriangle()

bool Ray::IntersectTriangle ( const Vec3 v0,
const Vec3 v1,
const Vec3 v2,
float &  t 
) const

Tests intersection with a triangle using the Möller-Trumbore algorithm.

Parameters
v0First vertex of the triangle.
v1Second vertex of the triangle.
v2Third vertex of the triangle.
tOutput parameter for intersection distance.
Returns
True if intersection occurs, false otherwise.

Member Data Documentation

◆ direction

Vec3 Ray::direction

The normalized direction vector of the ray.

◆ origin

Vec3 Ray::origin

The starting point of the ray.


The documentation for this struct was generated from the following files: