Vector3
Properties
x float
float x
X component of the vector.
y float
float y
Y component of the vector.
z float
float z
Z component of the vector.
Functions
Length() auto
auto vglx::Vector3::Length() const
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%).
LengthSquared() auto
auto vglx::Vector3::LengthSquared() const
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.
Max() auto &
auto & vglx::Vector3::Max(const Vector3 &v) noexcept
Parameter | Description |
---|---|
v | Vector to compare against. |
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
.
Min() auto &
auto & vglx::Vector3::Min(const Vector3 &v) noexcept
Parameter | Description |
---|---|
v | Vector to compare against. |
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
.
Normalize() auto &
auto & vglx::Vector3::Normalize()
Normalizes the vector in-place. If the length is zero, the vector is left unchanged.
operator*=() auto &
auto & vglx::Vector3::operator*=(const Vector3 &v)
Parameter | Description |
---|---|
v | None |
Scales each component by another vector.
operator*=() auto &
auto & vglx::Vector3::operator*=(float n)
Parameter | Description |
---|---|
n | None |
Scales the vector by a scalar.
operator+=() auto &
auto & vglx::Vector3::operator+=(const Vector3 &v)
Parameter | Description |
---|---|
v | None |
Adds another vector to this one.
operator-=() auto &
auto & vglx::Vector3::operator-=(const Vector3 &v)
Parameter | Description |
---|---|
v | None |
Subtracts another vector from this one.
operator[]() auto &
auto & vglx::Vector3::operator[](int i)
Parameter | Description |
---|---|
i | Index (0 for x, 1 for y, 2 for z). |
Accesses vector components by index.
operator[]() const auto &
const auto & vglx::Vector3::operator[](int i) const
Parameter | Description |
---|---|
i | Index (0 for x, 1 for y, 2 for z). |
Accesses vector components by index (const).
Vector3() constexpr
vglx::Vector3::Vector3(float value)
Parameter | Description |
---|---|
value | Value to assign to x, y and z. |
Constructs a vector with all components set to the same value.
Vector3() constexpr
vglx::Vector3::Vector3(float x, float y, float z)
Parameter | Description |
---|---|
x | X component. |
y | Y component. |
z | Z component. |
Constructs a vector with specified x, y, and z components.
Vector3::Forward() auto
static constexpr auto vglx::Vector3::Forward()
Returns the unit vector pointing forward (0, 0, 1).
Vector3::Right() auto
static constexpr auto vglx::Vector3::Right()
Returns the unit vector pointing to the right (1, 0, 0).
Vector3::Up() auto
static constexpr auto vglx::Vector3::Up()
Returns the unit vector pointing upward (0, 1, 0).
Vector3::Zero() auto
static constexpr auto vglx::Vector3::Zero()
Returns a zero vector (0, 0, 0).
Cross() auto
auto Cross(const Vector3 &a, const Vector3 &b)
Parameter | Description |
---|---|
a | First vector. |
b | Second vector. |
Computes the cross product between two vectors.
Dot() float
float Dot(const Vector3 &a, const Vector3 &b)
Parameter | Description |
---|---|
a | First vector. |
b | Second vector. |
Computes the dot product between two vectors.
Lerp() auto
auto Lerp(const Vector3 &v1, const Vector3 &v2, float f)
Parameter | Description |
---|---|
v1 | Start vector. |
v2 | End vector. |
f | Interpolation factor [0, 1]. |
Linearly interpolates between two vectors.
Normalize() auto
auto Normalize(const Vector3 &v)
Parameter | Description |
---|---|
v | Input vector. |
Returns a normalized copy of the given vector.