Claire's Game Engine
Full C++ Engine using OpenGL
|
A class representing a 2D vector. More...
#include <Vector2.h>
Public Member Functions | |
Vector2 () | |
Default constructor. Initializes vector to (0, 0). | |
Vector2 (float x, float y) | |
Initializes the vector with specified x and y values. | |
Vector2 (float x) | |
Initializes both x and y with the same value. | |
float | Magnitude () const |
Returns the magnitude (length) of the vector. | |
float | SqrLength () const |
Returns the squared length of the vector (avoids square root for performance). | |
void | Normalize () |
Normalizes the vector to unit length. If the vector is zero-length, it remains unchanged. | |
Vector2 | Normalized () |
Returns a new unit-length vector in the same direction. If the original vector has zero length, returns Vector2::ZERO. | |
float | Dot (const Vector2 &left, const Vector2 &right) const |
Computes the dot product of two vectors. | |
float | Cross (const Vector2 &vector) const |
Computes the 2D cross product between this and another vector. The result is a scalar equal to the Z-component of a 3D cross product. | |
std::string | ToString () const |
Converts the vector to a readable string format. | |
void | operator+= (const Vector2 &vector) |
void | operator-= (const Vector2 &vector) |
void | operator*= (const float value) |
void | operator/= (const float value) |
Public Attributes | |
float | x = 0 |
float | y = 0 |
Static Public Attributes | |
static const Vector2 | ZERO |
static const Vector2 | ONE |
Friends | |
bool | operator== (const Vector2 &left, const Vector2 &right) |
Vector2 | operator+ (const Vector2 &left, const Vector2 &right) |
Vector2 | operator- (const Vector2 &left, const Vector2 &right) |
Vector2 | operator* (const float value, const Vector2 &vector) |
Vector2 | operator* (const Vector2 &vector, const float value) |
Vector2 | operator/ (const Vector2 &vector, const float value) |
A class representing a 2D vector.
It supports vector arithmetic, geometric computations such as magnitude, normalization, dot and cross products, and includes operator overloads for intuitive use.
Vector2::Vector2 | ( | ) |
Default constructor. Initializes vector to (0, 0).
Vector2::Vector2 | ( | float | x, |
float | y ) |
Initializes the vector with specified x and y values.
x | The x component. |
y | The y component. |
Vector2::Vector2 | ( | float | x | ) |
Initializes both x and y with the same value.
x | The value to assign to both x and y. |
float Vector2::Cross | ( | const Vector2 & | vector | ) | const |
Computes the 2D cross product between this and another vector. The result is a scalar equal to the Z-component of a 3D cross product.
vector | The other vector. |
Computes the dot product of two vectors.
left | The first vector. |
right | The second vector. |
float Vector2::Magnitude | ( | ) | const |
Returns the magnitude (length) of the vector.
void Vector2::Normalize | ( | ) |
Normalizes the vector to unit length. If the vector is zero-length, it remains unchanged.
Vector2 Vector2::Normalized | ( | ) |
Returns a new unit-length vector in the same direction. If the original vector has zero length, returns Vector2::ZERO.
void Vector2::operator*= | ( | const float | value | ) |
void Vector2::operator+= | ( | const Vector2 & | vector | ) |
void Vector2::operator-= | ( | const Vector2 & | vector | ) |
void Vector2::operator/= | ( | const float | value | ) |
float Vector2::SqrLength | ( | ) | const |
Returns the squared length of the vector (avoids square root for performance).
std::string Vector2::ToString | ( | ) | const |
Converts the vector to a readable string format.
|
static |
float Vector2::x = 0 |
float Vector2::y = 0 |
|
static |