|
My Project
|
A 2D vector class template for mathematical operations. More...
#include <MVec2.hpp>
Public Member Functions | |
| Vec2 (T m_x, T m_y) | |
| Ensure that T is an arithmetic type (e.g., float, int). | |
| Vec2 ()=default | |
| Default constructor (initializes to (0,0)). | |
| ~Vec2 ()=default | |
| Destructor. | |
| T | x () const |
| Returns the x-component. | |
| T | y () const |
| Returns the y-component. | |
| void | SetX (T newX) |
| Sets the x-component to a new value. | |
| void | SetY (T newY) |
| Sets the y-component to a new value. | |
| void | Set (T newX, T newY) |
| Sets both components of the vector. | |
| Vec2 | Normalized () const |
| Returns a normalized (unit length) vector. | |
| T | SqrtMagnitude () const |
| Returns the squared magnitude of the vector. | |
| T | Magnitude () const |
| Returns the magnitude (length) of the vector. | |
| T | This (int i) const |
| Returns the component at index i (0 -> x, 1 -> y). | |
| bool | Equal (const Vec2 &other) const |
| Checks if this vector is equal to another vector. | |
| std::string | ToString () const |
| Converts the vector to a string representation. | |
| void | Normalize () |
| Normalizes the vector in place (makes it a unit vector). | |
| Vec2< T > | ToVec2 () const |
| Returns the vector as itself (no conversion). | |
| Vec3< T > | ToVec3 () const |
| Converts this 2D vector to a 3D vector (z-component = 0). | |
| Vec2 | operator- (const Vec2 &other) const |
| Subtracts another vector from this vector. | |
| Vec2 | operator+ (const Vec2 &other) const |
| Adds another vector to this vector. | |
| Vec2 | operator* (const Vec2 &other) const |
| Component-wise multiplication of two vectors. | |
| Vec2 | operator* (T scalar) const |
| Multiplies this vector by a scalar. | |
| Vec2 | operator/ (const Vec2 &other) const |
| Component-wise division of two vectors. | |
| Vec2 | operator/ (T scalar) const |
| Divides this vector by a scalar. | |
| bool | operator== (const Vec2 &other) const |
| Checks if this vector is equal to another vector. | |
| bool | operator!= (const Vec2 &other) const |
| Checks if this vector is not equal to another vector. | |
Static Public Member Functions | |
| static Vec2 | Down () |
| Returns a vector pointing down (0, -1). | |
| static Vec2 | Up () |
| Returns a vector pointing up (0, 1). | |
| static Vec2 | Left () |
| Returns a vector pointing left (-1, 0). | |
| static Vec2 | Right () |
| Returns a vector pointing right (1, 0). | |
| static Vec2 | One () |
| Returns a vector with both components set to 1 (1, 1). | |
| static Vec2 | Zero () |
| Returns a zero vector (0, 0). | |
| static Vec2 | PositiveInfinity () |
| Returns a vector with both components set to positive infinity. | |
| static Vec2 | NegativeInfinity () |
| Returns a vector with both components set to negative infinity. | |
| static Vec2 | MoveTowards (const Vec2 ¤t, const Vec2 &target, T maxDistanceDelta) |
| Moves the current vector towards the target vector by a maximum distance delta. | |
| static Vec2 | LerpUnclamped (const Vec2 &a, const Vec2 &b, T t) |
| Linearly interpolates (unclamped) between two vectors. | |
| static Vec2 | ClampMagnitude (const Vec2 &a, T maxLength) |
| Clamps the magnitude of a vector to a maximum length. | |
| static Vec2 | Perpendicular (const Vec2 &inDirection) |
| Returns a vector perpendicular to the input vector. | |
| static Vec2 | Lerp (const Vec2 &a, const Vec2 &b, T t) |
| Linearly interpolates (clamped) between two vectors. | |
| static Vec2 | Scale (const Vec2 &a, const Vec2 &b) |
| Component-wise multiplication of two vectors. | |
| static Vec2 | Min (const Vec2 &a, const Vec2 &b) |
| Returns the component-wise minimum of two vectors. | |
| static Vec2 | Max (const Vec2 &a, const Vec2 &b) |
| Returns the component-wise maximum of two vectors. | |
| static T | SignedAngle (const Vec2 &from, const Vec2 &to) |
| Calculates the signed angle (in radians) between two vectors. | |
| static T | Distance (const Vec2 &a, const Vec2 &b) |
| Calculates the distance between two vectors. | |
| static T | Angle (const Vec2 &a, const Vec2 &b) |
| Calculates the angle (in radians) between two vectors. | |
| static T | Dot (const Vec2 &a, const Vec2 &b) |
| Calculates the dot product of two vectors. | |
Public Attributes | |
| T | m_x |
| X component of the vector. | |
| T | m_y |
| Y component of the vector. | |
A 2D vector class template for mathematical operations.
| T | The numeric type (e.g., float, double, int). |
| Maths::Vec2< T >::Vec2 | ( | T | m_x, |
| T | m_y ) |
|
default |
Default constructor (initializes to (0,0)).
|
default |
Destructor.
|
static |
Calculates the angle (in radians) between two vectors.
| a | First vector. |
| b | Second vector. |
|
static |
Clamps the magnitude of a vector to a maximum length.
| a | The vector to clamp. |
| maxLength | The maximum allowed length. |
|
static |
Calculates the distance between two vectors.
| a | First vector. |
| b | Second vector. |
|
static |
Calculates the dot product of two vectors.
| a | First vector. |
| b | Second vector. |
|
static |
Returns a vector pointing down (0, -1).
| bool Maths::Vec2< T >::Equal | ( | const Vec2< T > & | other | ) | const |
Checks if this vector is equal to another vector.
| other | The vector to compare with. |
|
static |
Returns a vector pointing left (-1, 0).
|
static |
Linearly interpolates (clamped) between two vectors.
| a | The start vector. |
| b | The end vector. |
| t | Interpolation factor (clamped). |
|
static |
Linearly interpolates (unclamped) between two vectors.
| a | The start vector. |
| b | The end vector. |
| t | Interpolation factor (unclamped). |
| T Maths::Vec2< T >::Magnitude | ( | ) | const |
Returns the magnitude (length) of the vector.
|
static |
Returns the component-wise maximum of two vectors.
| a | First vector. |
| b | Second vector. |
|
static |
Returns the component-wise minimum of two vectors.
| a | First vector. |
| b | Second vector. |
|
static |
Moves the current vector towards the target vector by a maximum distance delta.
| current | The current vector. |
| target | The target vector. |
| maxDistanceDelta | The maximum distance to move. |
|
static |
Returns a vector with both components set to negative infinity.
| void Maths::Vec2< T >::Normalize | ( | ) |
Normalizes the vector in place (makes it a unit vector).
| Vec2 Maths::Vec2< T >::Normalized | ( | ) | const |
Returns a normalized (unit length) vector.
|
static |
Returns a vector with both components set to 1 (1, 1).
| bool Maths::Vec2< T >::operator!= | ( | const Vec2< T > & | other | ) | const |
Checks if this vector is not equal to another vector.
| other | The vector to compare with. |
| Vec2 Maths::Vec2< T >::operator* | ( | const Vec2< T > & | other | ) | const |
Component-wise multiplication of two vectors.
| other | The vector to multiply with. |
| Vec2 Maths::Vec2< T >::operator* | ( | T | scalar | ) | const |
Multiplies this vector by a scalar.
| scalar | The scalar to multiply with. |
| Vec2 Maths::Vec2< T >::operator+ | ( | const Vec2< T > & | other | ) | const |
Adds another vector to this vector.
| other | The vector to add. |
| Vec2 Maths::Vec2< T >::operator- | ( | const Vec2< T > & | other | ) | const |
Subtracts another vector from this vector.
| other | The vector to subtract. |
| Vec2 Maths::Vec2< T >::operator/ | ( | const Vec2< T > & | other | ) | const |
Component-wise division of two vectors.
| other | The vector to divide by. |
| Vec2 Maths::Vec2< T >::operator/ | ( | T | scalar | ) | const |
Divides this vector by a scalar.
| scalar | The scalar to divide by. |
| bool Maths::Vec2< T >::operator== | ( | const Vec2< T > & | other | ) | const |
Checks if this vector is equal to another vector.
| other | The vector to compare with. |
|
static |
Returns a vector perpendicular to the input vector.
| inDirection | The original vector. |
|
static |
Returns a vector with both components set to positive infinity.
|
static |
Returns a vector pointing right (1, 0).
|
static |
Component-wise multiplication of two vectors.
| a | First vector. |
| b | Second vector. |
|
inline |
Sets both components of the vector.
| newX | The new x value. |
| newY | The new y value. |
|
inline |
Sets the x-component to a new value.
| newX | The new x value. |
|
inline |
Sets the y-component to a new value.
| newY | The new y value. |
|
static |
Calculates the signed angle (in radians) between two vectors.
| from | The first vector. |
| to | The second vector. |
| T Maths::Vec2< T >::SqrtMagnitude | ( | ) | const |
Returns the squared magnitude of the vector.
| T Maths::Vec2< T >::This | ( | int | i | ) | const |
Returns the component at index i (0 -> x, 1 -> y).
| i | The index (0 or 1). |
| std::string Maths::Vec2< T >::ToString | ( | ) | const |
Converts the vector to a string representation.
| Vec2< T > Maths::Vec2< T >::ToVec2 | ( | ) | const |
Returns the vector as itself (no conversion).
| Vec3< T > Maths::Vec2< T >::ToVec3 | ( | ) | const |
Converts this 2D vector to a 3D vector (z-component = 0).
|
static |
Returns a vector pointing up (0, 1).
|
inline |
Returns the x-component.
|
inline |
Returns the y-component.
|
static |
Returns a zero vector (0, 0).
| T Maths::Vec2< T >::m_x |
X component of the vector.
| T Maths::Vec2< T >::m_y |
Y component of the vector.