Skip to main content

vec4 Struct Template

Represents a 4-dimensional vector of the generic type <T>. More...

Declaration

template <helios::math::Numeric T> struct helios::math::vec4<T> { ... }

Public Constructors Index

template <helios::math::Numeric T>
constexprvec4 () noexcept

Creates a new vec4 with its values initialized to (0, 0, 0, 0). More...

template <helios::math::Numeric T>
constexprvec4 (const T x, const T y, const T z, const T w) noexcept

Constructs a new vec4 with the specified x, y, z, w components. More...

template <helios::math::Numeric T>
constexprvec4 (const T v) noexcept

Constructs a new vec4 with v used for the x, y, z, w components. More...

template <helios::math::Numeric T>
constexprvec4 (const vec3< T > &vec, const T w) noexcept

Constructs a new vec4 from the vec3 vector and the w value. More...

template <helios::math::Numeric T>
constexprvec4 (const vec3< T > &vec) noexcept

Constructs a new vec4 from the vec3 vector and sets w to 1. 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...

Public Member Functions Index

template <helios::math::Numeric T>
constexpr auto withW (T w) const noexcept -> vec4< T >

Creates a new vec4 with the same x, y, z components but a modified w component. More...

template <helios::math::Numeric T>
auto toVec3 () const noexcept -> vec3< T >

Converts this 4D vector to a 3D vector. More...

template <helios::math::Numeric T>
auto toVec2 () const noexcept -> vec2< T >

Converts this 4D vector to a 2D vector. More...

Private Member Attributes Index

template <helios::math::Numeric T>
Tv[4]

Internal array storing the vector components. More...

Description

Represents a 4-dimensional vector of the generic type <T>.

The `vec4` struct provides a lightweight and efficient way to handle 4D vector mathematics for the numeric types float, int, double. For convenient access, the shorthands `vec4f`, `vec4d` and `vec4i` are available.

Template Parameters
T

The numeric type of the vector components.

Definition at line 33 of file vec4.ixx.

Public Constructors

vec4()

template <helios::math::Numeric T>
helios::math::vec4< T >::vec4 ()
inline constexpr noexcept

Creates a new vec4 with its values initialized to (0, 0, 0, 0).

Definition at line 46 of file vec4.ixx.

46 constexpr vec4() noexcept : v{static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0)} {}

Referenced by helios::math::vec4< T >::toVec3.

vec4()

template <helios::math::Numeric T>
helios::math::vec4< T >::vec4 (const T x, const T y, const T z, const T w)
inline constexpr noexcept

Constructs a new vec4 with the specified x, y, z, w components.

Parameters
x

The value for the x component.

y

The value for the y component.

z

The value for the z component.

w

The value for the w component.

Definition at line 57 of file vec4.ixx.

57 constexpr vec4(const T x, const T y, const T z, const T w) noexcept : v{x, y, z, w} {}

vec4()

template <helios::math::Numeric T>
helios::math::vec4< T >::vec4 (const T v)
inline constexpr noexcept

Constructs a new vec4 with v used for the x, y, z, w components.

Parameters
v

The value for the x, y, z, w component.

Definition at line 64 of file vec4.ixx.

64 constexpr vec4(const T v) noexcept : v{v, v, v, v} {}

vec4()

template <helios::math::Numeric T>
helios::math::vec4< T >::vec4 (const vec3< T > & vec, const T w)
inline constexpr noexcept

Constructs a new vec4 from the vec3 vector and the w value.

Parameters
vec

The vec3<T> vector.

w

The value for the w component.

Definition at line 73 of file vec4.ixx.

73 constexpr vec4(const vec3<T>& vec, const T w) noexcept : v{vec[0], vec[1], vec[2], w} {}

vec4()

template <helios::math::Numeric T>
helios::math::vec4< T >::vec4 (const vec3< T > & vec)
inline explicit constexpr noexcept

Constructs a new vec4 from the vec3 vector and sets w to 1.

Parameters
vec

The vec3<T> vector.

Definition at line 81 of file vec4.ixx.

81 explicit constexpr vec4(const vec3<T>& vec) noexcept : v{vec[0], vec[1], vec[2], static_cast<T>(1)} {}

Public Operators

operator[]()

template <helios::math::Numeric T>
const T & helios::math::vec4< T >::operator[] (const size_t i)
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 105 of file vec4.ixx.

105 constexpr const T& operator[](const size_t i) const noexcept {
106 assert(i <= 3 && "vec4 - Index out of bounds.");
107 return this->v[i];
108 }

operator[]()

template <helios::math::Numeric T>
T & helios::math::vec4< T >::operator[] (const size_t i)
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 ref to the requested component.

Definition at line 119 of file vec4.ixx.

119 constexpr T& operator[](const size_t i) noexcept {
120 assert(i <= 3 && "vec4 - Index out of bounds.");
121 return this->v[i];
122 }

Public Member Functions

toVec2()

template <helios::math::Numeric T>
vec2< T > helios::math::vec4< T >::toVec2 ()
inline nodiscard noexcept

Converts this 4D vector to a 2D vector.

Extracts the x, y components from this vec4, discarding the z,w components.

Returns

A new vec2<T> instance with components (x, y).

Definition at line 141 of file vec4.ixx.

151 inline vec2<T> vec4<T>::toVec2() const noexcept {
152 return vec2<T>{v[0], v[1]};
153 }

toVec3()

template <helios::math::Numeric T>
vec3< T > helios::math::vec4< T >::toVec3 ()
inline nodiscard noexcept

Converts this 4D vector to a 3D vector.

Extracts the x, y, z components from this vec4, discarding the w component. This is useful when converting from homogeneous coordinates back to 3D space.

Returns

A new vec3<T> instance with components (x, y, z).

Definition at line 132 of file vec4.ixx.

146 inline vec3<T> vec4<T>::toVec3() const noexcept {
147 return vec3<T>{v[0], v[1], v[2]};
148 }

References helios::math::vec4< T >::toVec3 and helios::math::vec4< T >::vec4.

Referenced by helios::math::vec4< T >::toVec3 and helios::engine::mechanics::bounds::systems::LevelBoundsBehaviorSystem::update.

withW()

template <helios::math::Numeric T>
vec4< T > helios::math::vec4< T >::withW (T w)
inline nodiscard constexpr noexcept

Creates a new vec4 with the same x, y, z components but a modified w component.

This method returns a new vec4 instance where the x, y, and z components remain unchanged, and the w component is set to the specified value.

Parameters
w

The new value for the w component.

Returns

A new vec4<T> instance with the updated w component.

Definition at line 93 of file vec4.ixx.

93 [[nodiscard]] constexpr vec4<T> withW(T w) const noexcept {
94 return helios::math::vec4<T>{v[0], v[1], v[2], w};
95 }

Private Member Attributes

v

template <helios::math::Numeric T>
T helios::math::vec4< T >::v[4]

Internal array storing the vector components.

Definition at line 39 of file vec4.ixx.

39 T v[4];

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.