Skip to main content

vec4 Struct Template

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

Declaration

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

Public Constructors Index

template <helios::math::concepts::IsNumeric T>
constexprvec4 () noexcept

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

template <helios::math::concepts::IsNumeric 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::concepts::IsNumeric T>
constexprvec4 (const T v) noexcept

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

template <helios::math::concepts::IsNumeric 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::concepts::IsNumeric 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::concepts::IsNumeric 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::concepts::IsNumeric 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::concepts::IsNumeric T>
auto withW (T w) const noexcept -> constexpr vec4< T >

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

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

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

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

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

Private Member Attributes Index

template <helios::math::concepts::IsNumeric 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 34 of file vec4.ixx.

Public Constructors

vec4()

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

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

Definition at line 47 of file vec4.ixx.

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

vec4()

template <helios::math::concepts::IsNumeric T>
constexpr 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 58 of file vec4.ixx.

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

vec4()

template <helios::math::concepts::IsNumeric T>
constexpr 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 65 of file vec4.ixx.

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

vec4()

template <helios::math::concepts::IsNumeric T>
constexpr 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 74 of file vec4.ixx.

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

vec4()

template <helios::math::concepts::IsNumeric T>
constexpr 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 82 of file vec4.ixx.

82 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::concepts::IsNumeric T>
constexpr 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 106 of file vec4.ixx.

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

operator[]()

template <helios::math::concepts::IsNumeric T>
constexpr 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 120 of file vec4.ixx.

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

Public Member Functions

toVec2()

template <helios::math::concepts::IsNumeric T>
vec2< T > helios::math::vec4< T >::toVec2 ()
inline 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 142 of file vec4.ixx.

153 return vec2<T>{v[0], v[1]};
154 }

toVec3()

template <helios::math::concepts::IsNumeric T>
vec3< T > helios::math::vec4< T >::toVec3 ()
inline 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 133 of file vec4.ixx.

148 return vec3<T>{v[0], v[1], v[2]};
149 }

withW()

template <helios::math::concepts::IsNumeric T>
constexpr vec4< T > helios::math::vec4< T >::withW (T w)
inline 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 94 of file vec4.ixx.

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

Private Member Attributes

v

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

Internal array storing the vector components.

Definition at line 40 of file vec4.ixx.

40 T v[4];

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.