Voltray Engine Docs
Loading...
Searching...
No Matches
Ray.h
Go to the documentation of this file.
1#pragma once
2
3#include "Vec3.h"
4#include "Mat4.h"
5#include <vector>
6
14struct Ray
15{
18
22 Ray();
23
29 Ray(const Vec3 &origin, const Vec3 &direction);
30
36 Vec3 GetPoint(float t) const;
37
45 bool IntersectSphere(const Vec3 &center, float radius, float &t) const;
46
54 bool IntersectAABB(const Vec3 &minBounds, const Vec3 &maxBounds, float &t) const;
55
64 bool IntersectTriangle(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2, float &t) const;
65
73 bool IntersectMesh(const std::vector<float> &vertices, const std::vector<unsigned int> &indices, float &t) const;
74
83 bool IntersectMesh(const std::vector<float> &vertices, const std::vector<unsigned int> &indices, const Mat4 &transform, float &t) const;
84
89 Vec3 GetOrigin() const;
90
95 Vec3 GetDirection() const;
96
105 static Vec3 ClosestPointOnLine(const Vec3 &rayOrigin,
106 const Vec3 &linePoint, const Vec3 &lineDirection);
107
116 static float DistanceToLineSegment(const Vec3 &rayOrigin, const Vec3 &rayDirection,
117 const Vec3 &segmentStart, const Vec3 &segmentEnd);
118};
4x4 Matrix structure for 3D transformations and projections.
Definition Mat4.h:16
Represents a ray in 3D space with an origin and direction.
Definition Ray.h:15
Vec3 GetPoint(float t) const
Gets a point along the ray at parameter t.
Definition Ray.cpp:27
Ray()
Default constructor - creates a ray at origin pointing in positive Z direction.
Definition Ray.cpp:8
Vec3 GetOrigin() const
Gets the origin of the ray.
Definition Ray.cpp:17
Vec3 origin
The starting point of the ray.
Definition Ray.h:16
Vec3 direction
The normalized direction vector of the ray.
Definition Ray.h:17
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.
Definition Ray.cpp:95
Vec3 GetDirection() const
Gets the direction of the ray.
Definition Ray.cpp:22
bool IntersectSphere(const Vec3 &center, float radius, float &t) const
Tests intersection with a sphere.
Definition Ray.cpp:32
bool IntersectAABB(const Vec3 &minBounds, const Vec3 &maxBounds, float &t) const
Tests intersection with an axis-aligned bounding box.
Definition Ray.cpp:58
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.
Definition Ray.cpp:126
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.
Definition Vec3.h:5