Vector4
Vector4 stores four components (x, y, z, w) and is typically used for homogeneous coordinates, and general 4D math. It provides basic arithmetic, and utility helpers.
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 all four components. |
Vector4() constexpr
Constructs a vector from individual components.
Vector4::Vector4(float x, float y, float z, float w);| Parameter | Description |
|---|---|
| x | |
| y | |
| z | |
| w |
Properties
w float
W component.
float w {};x float
X component.
float x {};y float
Y component.
float y {};z float
Z component.
float z {};Functions
Length() float
Computes the vector length.
float Vector4::Length() const;LengthSquared() float
Computes the squared vector length.
Useful when comparing lengths without paying the cost of a square root.
float Vector4::LengthSquared() const;Applies a component-wise maximum.
Vector4& Vector4::Max(const Vector4& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Applies a component-wise minimum.
Vector4& Vector4::Min(const Vector4& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Normalizes the vector in-place.
If the length is zero, the vector is unchanged.
Vector4& Vector4::Normalize();Multiplies the vector component-wise by another vector in-place.
Vector4& Vector4::operator* =(const Vector4& v);| Parameter | Description |
|---|---|
| v | Vector to multiply. |
Multiplies the vector by a scalar in-place.
Vector4& Vector4::operator* =(float n);| Parameter | Description |
|---|---|
| n | Scalar value. |
Adds another vector in-place.
Vector4& Vector4::operator+=(const Vector4& v);| Parameter | Description |
|---|---|
| v | Vector to add. |
Subtracts another vector in-place.
Vector4& Vector4::operator-=(const Vector4& v);| Parameter | Description |
|---|---|
| v | Vector to subtract. |
operator[]() float &
Accesses a component by index.
float& Vector4::operator[](int i);| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y, 2 → z, 3 → w. |
operator[]() float
Accesses a component by index.
float Vector4::operator[](int i) const;| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y, 2 → z, 3 → w. |
Dot() float
Computes the dot product of two 4D vectors.
Computes the scalar product (), which measures how aligned the two vectors are.
float Dot(const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Lerp() auto
Linearly interpolates between two 4D vectors.
auto Lerp(const Vector4& v1, const Vector4& v2, float f);| Parameter | Description |
|---|---|
| v1 | Start vector. |
| v2 | End vector. |
| f | Interpolation factor in . |
Returns a normalized copy of a vector.
If the input has zero length, the zero vector is returned.
Vector4 Normalize(const Vector4& v);| Parameter | Description |
|---|---|
| v | Input vector. |
Multiplies two vectors component-wise.
Vector4 operator* (const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Multiplies a vector by a scalar.
Vector4 operator* (const Vector4& v, float n);| Parameter | Description |
|---|---|
| v | Input vector. |
| n | Scalar value. |
Multiplies a scalar by avector.
Vector4 operator* (float n, const Vector4& v);| Parameter | Description |
|---|---|
| n | Scalar value. |
| v | Input vector. |
Adds two 4D vectors.
Vector4 operator+(const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Subtracts one 4D vector from another.
Vector4 operator-(const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Divides two vectors component-wise.
Vector4 operator/(const Vector4& a, const Vector4& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |