#include <muu/ray.h>
template <typename Scalar>
muu::ray struct

A ray.

Template parameters
Scalar The ray's scalar component type. Must be a floating-point type.

Public types

using result_type = std::optional<scalar_type>
The result type returned by a raycast test.
using scalar_type = Scalar
The ray's scalar type.
using vector_type = vector<scalar_type, 3>
The three-dimensional muu::vector with the same scalar_type as the ray.

Constructors, destructors, conversion operators

ray() defaulted noexcept
Default constructor. Values are not initialized.
ray(const ray&) defaulted constexpr noexcept
Copy constructor.
ray(const vector_type& o, const vector_type& dir) constexpr noexcept
Constructs a ray from an origin and direction.
ray(scalar_type o_x, scalar_type o_y, scalar_type o_z, scalar_type dir_x, scalar_type dir_y, scalar_type dir_z) constexpr noexcept
Constructs a ray from an origin and direction (in scalar form).
template <typename S>
ray(const ray<S>& r) explicit constexpr noexcept
Converting constructor.
template <typename T>
ray(const T& obj) constexpr noexcept
Constructs a ray from an implicitly bit-castable type.

Public functions

auto operator=(const ray&) -> ray& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

vector_type origin
The ray's origin point.
vector_type direction
The ray's direction.

Equality (approximate)

template <typename T>
static auto approx_equal(const ray& ray1, const ray<T>& ray2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two rays are approximately equal.
template <typename T>
auto approx_equal(const ray<T>& r, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the ray is approximately equal to another.

Equality (exact)

static auto infinity_or_nan(const ray& r) -> bool constexpr noexcept
Returns true if any of the scalars in a ray are infinity or NaN.
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the scalars in the ray are infinity or NaN.
template <typename T>
auto operator!=(const ray& lhs, const ray<T>& rhs) -> bool constexpr noexcept
Returns true if two rays are not exactly equal.
template <typename T>
auto operator==(const ray& lhs, const ray<T>& rhs) -> bool constexpr noexcept
Returns true if two rays are exactly equal.

Hit positions

static auto at(const ray& r, scalar_type distance) -> vector_type constexpr noexcept
Converts a hit distance into a hit position from a ray.
static auto at(const ray& r, const result_type& hit) -> vector_type constexpr noexcept
Converts a hit result into a hit position from a ray.
static auto bounce(const ray& r, scalar_type distance, const vector_type& dir) -> ray constexpr noexcept
Creates a new ray as a 'bounce' from the hit position of a previous one.
static auto bounce(const ray& r, const result_type& hit, const vector_type& dir) -> ray constexpr noexcept
Creates a new ray as a 'bounce' from the hit position of a previous one.
auto at(scalar_type distance) const -> vector_type constexpr noexcept
Converts a hit distance into a hit position from this ray.
auto at(const result_type& hit) const -> vector_type constexpr noexcept
Converts a hit result into a hit position from this ray.
auto bounce(scalar_type distance, const vector_type& dir) const -> ray constexpr noexcept
Creates a new ray as a 'bounce' from a previous hit position of this one.
auto bounce(const result_type& hit, const vector_type& dir) const -> ray constexpr noexcept
Creates a new ray as a 'bounce' from a previous hit position of this one.

Hit tests

static auto hits(const ray& r, const plane<scalar_type>& p) -> result_type constexpr noexcept
Tests if a ray hits a plane.
static auto hits(const ray& r, const triangle<scalar_type>& tri) -> result_type constexpr noexcept
Tests if a ray hits a triangle.
static auto hits(const ray& r, const bounding_sphere<scalar_type>& bs) -> result_type constexpr noexcept
Tests if a ray hits a bounding-sphere.
static auto hits(const ray& r, const bounding_box<scalar_type>& bb) -> result_type constexpr noexcept
Tests if a ray hits a bounding-box.
auto hits(const plane<scalar_type>& p) const -> result_type constexpr noexcept
Tests if the ray hits a plane.
auto hits(const triangle<scalar_type>& tri) const -> result_type constexpr noexcept
Tests if the ray hits a plane.
auto hits(const bounding_sphere<scalar_type>& bs) const -> result_type constexpr noexcept
Tests if the ray hits a bounding-sphere.
auto hits(const bounding_box<scalar_type>& bb) const -> result_type constexpr noexcept
Tests if the ray hits a bounding-box.

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const ray& r) -> std::basic_ostream<Char, Traits>&
Writes a ray out to a text stream.

Function documentation

template <typename Scalar>
template <typename T>
muu::ray::ray(const T& obj) constexpr noexcept

Constructs a ray from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar>
template <typename T>
bool muu::ray::operator!=(const ray& lhs, const ray<T>& rhs) constexpr noexcept

Returns true if two rays are not exactly equal.

template <typename Scalar>
template <typename T>
bool muu::ray::operator==(const ray& lhs, const ray<T>& rhs) constexpr noexcept

Returns true if two rays are exactly equal.

template <typename Scalar>
static vector_type muu::ray::at(const ray& r, const result_type& hit) constexpr noexcept

Converts a hit result into a hit position from a ray.

template <typename Scalar>
static ray muu::ray::bounce(const ray& r, scalar_type distance, const vector_type& dir) constexpr noexcept

Creates a new ray as a 'bounce' from the hit position of a previous one.

Parameters
r The previous ray
distance The previous hit distance
dir The direction for the new ray
Returns ray{ r.at(distance), dir }.

template <typename Scalar>
static ray muu::ray::bounce(const ray& r, const result_type& hit, const vector_type& dir) constexpr noexcept

Creates a new ray as a 'bounce' from the hit position of a previous one.

Parameters
r The previous ray
hit The previous hit position
dir The direction for the new ray
Returns ray{ r.at(hit), dir }.

template <typename Scalar>
vector_type muu::ray::at(const result_type& hit) const constexpr noexcept

Converts a hit result into a hit position from this ray.

template <typename Scalar>
ray muu::ray::bounce(scalar_type distance, const vector_type& dir) const constexpr noexcept

Creates a new ray as a 'bounce' from a previous hit position of this one.

Parameters
distance The previous hit distance
dir The direction for the new ray
Returns ray{ r.at(distance), dir }.

template <typename Scalar>
ray muu::ray::bounce(const result_type& hit, const vector_type& dir) const constexpr noexcept

Creates a new ray as a 'bounce' from a previous hit position of this one.

Parameters
hit The previous hit position
dir The direction for the new ray
Returns ray{ r.at(hit), dir }.