Vector4
Construction
Constructors
Vector4() constexpr
Constructs a vector with all components set to the same value.
Vector4::Vector4(float value);| Parameter | Description |
|---|---|
| value | Value to assign to x, y, z, and w. |
Vector4() constexpr
Constructs a vector with specified x, y, z, and w components.
Vector4::Vector4(float x, float y, float z, float w);| Parameter | Description |
|---|---|
| x | X component. |
| y | Y component. |
| z | Z component. |
| w | W component. |
Properties
w float
W component of the vector.
float w {};x float
X component of the vector.
float x {};y float
Y component of the vector.
float y {};z float
Z component of the vector.
float z {};Functions
Length() auto
Computes the approximate magnitude of the vector.
This function uses a fast inverse square root approximation to compute the square root, which is significantly faster than the standard library sqrt, but introduces a small precision error (~0.001%).
auto Vector4::Length() const;LengthSquared() auto
Computes the squared length (magnitude) of the vector.
This is a precise and inexpensive operation that avoids computing a square root. Use this when comparing relative lengths or avoiding unnecessary precision loss.
auto Vector4::LengthSquared() const;Max() auto &
Component-wise in-place maximum.
Sets each component of this vector to the larger of the corresponding components in this vector and the given vector v.
auto& Vector4::Max(const Vector4& v) noexcept;| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Min() auto &
Component-wise in-place minimum.
Sets each component of this vector to the smaller of the corresponding components in this vector and the given vector v.
auto& Vector4::Min(const Vector4& v) noexcept;| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Normalize() auto &
Normalizes the vector in-place.
If the length is zero, the vector is left unchanged.
auto& Vector4::Normalize();operator*=() auto &
Scales each component by another vector.
auto& Vector4::operator* =(const Vector4& v);| Parameter | Description |
|---|---|
| v |
operator*=() auto &
Scales the vector by a scalar.
auto& Vector4::operator* =(float n);| Parameter | Description |
|---|---|
| n |
operator+=() auto &
Adds another vector to this one.
auto& Vector4::operator+=(const Vector4& v);| Parameter | Description |
|---|---|
| v |
operator-=() auto &
Subtracts another vector from this one.
auto& Vector4::operator-=(const Vector4& v);| Parameter | Description |
|---|---|
| v |
operator[]() auto &
Accesses vector components by index.
auto& Vector4::operator[](int i);| Parameter | Description |
|---|---|
| i | Index (0 for x, 1 for y, 2 for z, 3 for w). |
operator[]() const auto &
Accesses vector components by index (const).
const auto& Vector4::operator[](int i) const;| Parameter | Description |
|---|---|
| i | Index (0 for x, 1 for y, 2 for z, 3 for w). |
Vector4::Zero() auto
Returns a zero vector (0, 0, 0, 0).
static constexpr auto Vector4::Zero();Dot() float
Computes the dot product between two vectors.
float Dot(const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Lerp() auto
Linearly interpolates between two vectors.
auto Lerp(const Vector4& v1, const Vector4& v2, float f);| Parameter | Description |
|---|---|
| v1 | Start vector. |
| v2 | End vector. |
| f | Interpolation factor [0, 1]. |
Normalize() auto
Returns a normalized copy of the given vector.
auto Normalize(const Vector4& v);| Parameter | Description |
|---|---|
| v | Input vector. |