#include <muu/ray.h>
template <typename Scalar>
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
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
template <typename T>
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
template <typename T>
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
template <typename T>
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 } . |