vec3 Struct Template
Represents a 3-dimensional vector of the generic type <T>. More...
Declaration
Public Constructors Index
template <helios::math::Numeric T> | |
| constexpr | vec3 () noexcept |
|
Creates a new vec3 with its values initialized to (0, 0, 0). More... | |
template <helios::math::Numeric T> | |
| constexpr | vec3 (const T x, const T y, const T z) noexcept |
|
Constructs a new vec3 with the specified x, y, z components. More... | |
template <helios::math::Numeric T> | |
| constexpr | vec3 (const T v) noexcept |
|
Constructs a new vec3 with the specified value as the x,y,z components. More... | |
template <helios::math::Numeric T> | |
| constexpr | vec3 (const helios::math::vec2< T > v) noexcept |
|
Constructs a new vec3 with x,y components initialized to those of the vec2 and vec3 set to 0. More... | |
template <helios::math::Numeric T> | |
| constexpr | vec3 (const helios::math::vec2< T > v, T f) noexcept |
|
Constructs a new vec3 with x,y components initialized to those of the vec2 and the z component set to the specified value. More... | |
Public Operators Index
template <helios::math::Numeric T> | |
| constexpr const T & | operator[] (const size_t i) const noexcept |
|
Provides read only access to the vector components. Bounds checking is performed via `assert` in debug builds. More... | |
template <helios::math::Numeric T> | |
| constexpr T & | operator[] (const size_t i) noexcept |
|
Provides read-write access to the vector components. Bounds checking is performed via `assert` in debug builds. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | operator== (const vec3< T > &rgt) const |
|
Strictly compares the elements of this vector with the elements of the rgt vector. More... | |
Public Member Functions Index
template <helios::math::Numeric T> | |
| auto | length () const noexcept -> FloatingPointType< T > |
|
Computes the Euclidean norm (magnitude) of this vector and returns it. More... | |
template <helios::math::Numeric T> | |
| auto | cross (const helios::math::vec3< T > &v2) const noexcept -> vec3< T > |
|
Computes the cross product of this vector and v2. More... | |
template <helios::math::Numeric T> | |
| T | dot (const helios::math::vec3< T > &v2) const noexcept |
|
Computes the dot product of this vector and v2. More... | |
template <helios::math::Numeric T> | |
| auto | toVec4 () const noexcept -> vec4< T > |
|
Converts this 3D vector to a 4D homogeneous vector. More... | |
template <helios::math::Numeric T> | |
| auto | toVec2 () const noexcept -> vec2< T > |
|
Converts this 3D vector to a 2D vector by discarding the z-component. More... | |
template <helios::math::Numeric T> | |
| auto | toVec4 (T w) const noexcept -> vec4< T > |
|
Converts this 3D vector to a 4D homogeneous vector. More... | |
template <helios::math::Numeric T> | |
| auto | normalize () const noexcept -> vec3< FloatingPointType< T > > |
|
Returns a normalized version of this vector. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | same (const vec3< T > &rgt, T epsilon=0.0001) const |
|
Compares this vector's elements with the rgt vector considering an epsilon value. Returns true if for all elements the equation |a-b| <= epsilon holds. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | flipY () const noexcept -> helios::math::vec3< T > |
|
Returns a new vector with the y-component negated. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | withY (T y) const noexcept -> helios::math::vec3< T > |
|
Returns a new vector with the y-component replaced by the given value. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | flipX () const noexcept -> helios::math::vec3< T > |
|
Returns a new vector with the x-component negated. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | withX (T x) const noexcept -> helios::math::vec3< T > |
|
Returns a new vector with the x-component replaced by the given value. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | isNormalized () const noexcept |
|
Checks if this vector is normalized (unit length). More... | |
Private Member Attributes Index
template <helios::math::Numeric T> | |
| T | v[3] |
|
Internal array storing the vector components. More... | |
Description
Represents a 3-dimensional vector of the generic type <T>.
The `vec3` struct provides a lightweight and efficient way to handle 3D vector mathematics for the numeric types float, int, double. For convenient access, the shorthands `vec3f`, `vec3d` and `vec3i` are available.
- Template Parameters
-
T The numeric type of the vector components.
Definition at line 33 of file vec3.ixx.
Public Constructors
vec3()
| inline constexpr noexcept |
Creates a new vec3 with its values initialized to (0, 0, 0).
Definition at line 47 of file vec3.ixx.
Referenced by helios::math::vec3< T >::cross, helios::math::vec3< T >::dot and helios::math::vec3< T >::normalize.
vec3()
| inline constexpr noexcept |
vec3()
| inline explicit constexpr noexcept |
vec3()
| inline explicit constexpr noexcept |
vec3()
| inline explicit constexpr noexcept |
Constructs a new vec3 with x,y components initialized to those of the vec2 and the z component set to the specified value.
- Parameters
-
v The vec2 to use for the x,y components.
f The value for the z component.
Definition at line 85 of file vec3.ixx.
Public Operators
operator[]()
| inline constexpr noexcept |
Provides read only access to the vector components. Bounds checking is performed via `assert` in debug builds.
- Parameters
-
i The index to query
- Returns
A const ref to the requested component.
Definition at line 95 of file vec3.ixx.
operator[]()
| inline constexpr noexcept |
Provides read-write access to the vector components. Bounds checking is performed via `assert` in debug builds.
- Parameters
-
i The index to query
- Returns
A const ref to the requested component.
Definition at line 109 of file vec3.ixx.
operator==()
| inline constexpr |
Strictly compares the elements of this vector with the elements of the rgt vector.
- Parameters
-
rgt The right vector to compare for equal values.
- Returns
True if all elements are equal (==), false otherwise.
Public Member Functions
cross()
| inline nodiscard noexcept |
Computes the cross product of this vector and v2.
- Parameters
-
v2 The second vec3<T> vector.
- Returns
The cross product as a value of type vec3<T>.
Definition at line 135 of file vec3.ixx.
Reference helios::math::vec3< T >::vec3.
dot()
| inline nodiscard noexcept |
Computes the dot product of this vector and v2.
- Parameters
-
v2 The second vec3<T> vector.
- Returns
The dot product as a value of type T.
Definition at line 144 of file vec3.ixx.
Reference helios::math::vec3< T >::vec3.
flipX()
| inline constexpr noexcept |
Returns a new vector with the x-component negated.
- Returns
A new vec3<T> with (-x, y, z).
Definition at line 244 of file vec3.ixx.
flipY()
| inline constexpr noexcept |
Returns a new vector with the y-component negated.
- Returns
A new vec3<T> with (x, -y, z).
Definition at line 225 of file vec3.ixx.
isNormalized()
| inline constexpr noexcept |
Checks if this vector is normalized (unit length).
A vector is considered normalized if its squared length equals 1 within the tolerance defined by EPSILON_LENGTH.
- Returns
true if the vector is approximately unit length, false otherwise.
Definition at line 266 of file vec3.ixx.
Referenced by helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::AxisSpawnPlacer and helios::engine::modules::physics::motion::components::SteeringComponent::setSteeringIntent.
length()
| inline noexcept |
Computes the Euclidean norm (magnitude) of this vector and returns it.
- Returns
The norm (magnitude) of this vector as a value of type FloatingPointType<T>.
Definition at line 120 of file vec3.ixx.
Referenced by helios::ext::imgui::widgets::CameraWidget::draw and helios::math::vec3< T >::normalize.
normalize()
| inline nodiscard noexcept |
Returns a normalized version of this vector.
- Returns
A new vec3<FloatingPointType<T>> instance representing the normalized vector.
Definition at line 182 of file vec3.ixx.
References helios::math::vec3< T >::length and helios::math::vec3< T >::vec3.
Referenced by helios::scene::CameraSceneNode::lookAt, helios::scene::CameraSceneNode::lookAtLocal and helios::engine::modules::ai::systems::ChaseSystem::update.
same()
| inline constexpr |
Compares this vector's elements with the rgt vector considering an epsilon value. Returns true if for all elements the equation |a-b| <= epsilon holds.
- Parameters
-
rgt The other vector to compare with this vector for equality.
epsilon The epsilon value to use for comparison. If omitted, the default epsilon (0.0001) is used.
- Returns
True if the elements of the vectors are considered equal, otherwise false.
- Todo
-
account for abs (values close to zero) and rel (larger values), move epsilon to global constant?
toVec2()
| inline nodiscard noexcept |
toVec4()
| inline nodiscard noexcept |
Converts this 3D vector to a 4D homogeneous vector.
Creates a vec4 with the x, y, z components from this vector and sets the w component to 0, representing a direction in homogeneous coordinates.
- Returns
A new vec4<T> instance with components (x, y, z, 0).
Definition at line 155 of file vec3.ixx.
Referenced by helios::engine::mechanics::bounds::systems::LevelBoundsBehaviorSystem::update.
toVec4()
| inline nodiscard noexcept |
Converts this 3D vector to a 4D homogeneous vector.
Creates a vec4 with the x, y, z components from this vector and sets the w component accordingly, representing a direction in homogeneous coordinates.
- Parameters
-
w The value of the w component.
- Returns
A new vec4<T> instance with components (x, y, z, w).
Definition at line 175 of file vec3.ixx.
withX()
| inline constexpr noexcept |
Returns a new vector with the x-component replaced by the given value.
- Parameters
-
x The new x value.
- Returns
A new vec3<T> with (x, y, z).
Definition at line 254 of file vec3.ixx.
withY()
| inline constexpr noexcept |
Returns a new vector with the y-component replaced by the given value.
- Parameters
-
y The new y value.
- Returns
A new vec3<T> with (x, y, z).
Definition at line 235 of file vec3.ixx.
The documentation for this struct was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.