Vector3
Vector3 stores an (x, y, z) triple and is used for positions, directions, normals, and general 3D math. It provides basic arithmetic, normalization, and utility helpers.
Construction
Constructors
Vector3() constexpr
Constructs a vector with all components set to the same value.
Vector3::Vector3(float value);| Parameter | Description |
|---|---|
| value | Value to assign to all components. |
Vector3() constexpr
Constructs a vector from individual components.
Vector3::Vector3(float x, float y, float z);| Parameter | Description |
|---|---|
| x | X component. |
| y | Y component. |
| z | Z component. |
Properties
x float
X component.
float x {};y float
Y component.
float y {};z float
Z component.
float z {};Functions
Length() float
Returns the vector length.
float Vector3::Length() const;LengthSquared() float
Returns the squared vector length.
Useful when comparing lengths without paying the cost of a square root.
float Vector3::LengthSquared() const;Applies a component-wise maximum with another vector.
Vector3& Vector3::Max(const Vector3& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Applies a component-wise minimum with another vector.
Vector3& Vector3::Min(const Vector3& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Normalizes the vector in-place.
If the length is zero, the vector is left unchanged.
Vector3& Vector3::Normalize();Multiplies the vector component-wise by another vector in-place.
Vector3& Vector3::operator* =(const Vector3& v);| Parameter | Description |
|---|---|
| v | Vector to multiply. |
Multiplies the vector by a scalar in-place.
Vector3& Vector3::operator* =(float n);| Parameter | Description |
|---|---|
| n | Scalar value. |
Adds another vector in-place.
Vector3& Vector3::operator+=(const Vector3& v);| Parameter | Description |
|---|---|
| v | Vector to add. |
Subtracts another vector in-place.
Vector3& Vector3::operator-=(const Vector3& v);| Parameter | Description |
|---|---|
| v | Vector to subtract. |
operator[]() float &
Accesses a component by index.
float& Vector3::operator[](int i);| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y, 2 → z. |
operator[]() const float
Accesses a component by index.
const float Vector3::operator[](int i) const;| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y, 2 → z. |
Returns a unit vector pointing forward.
static constexpr Vector3 Vector3::Forward();Returns a unit vector pointing right.
static constexpr Vector3 Vector3::Right();Computes the cross product of two 3D vectors.
Returns a vector perpendicular to both inputs, following the right-hand rule.
Vector3 Cross(const Vector3& a, const Vector3& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Dot() float
Computes the dot product of two 3D vectors.
Computes the scalar product (), which measures how aligned the two vectors are.
float Dot(const Vector3& a, const Vector3& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Linearly interpolates between two 3D vectors.
Vector3 Lerp(const Vector3& v1, const Vector3& 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.
Vector3 Normalize(const Vector3& v);| Parameter | Description |
|---|---|
| v | Input vector. |
Multiplies two vectors component-wise.
Vector3 operator* (const Vector3& a, const Vector3& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Multiplies a vector by a scalar.
Vector3 operator* (const Vector3& v, float n);| Parameter | Description |
|---|---|
| v | Input vector. |
| n | Scalar value. |
Multiplies a scalar by a vector.
Vector3 operator* (float n, const Vector3& v);| Parameter | Description |
|---|---|
| n | Scalar value. |
| v | Input vector. |
Adds two 3D vectors.
Vector3 operator+(const Vector3& a, const Vector3& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Subtracts one 3D vector from another.
Vector3 operator-(const Vector3& a, const Vector3& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |