Stowy Physics Engine 0.1.0
|
A struct representing a 2D Vector. More...
#include <Vector2.hpp>
Public Member Functions | |
constexpr | Vector2 () |
constexpr | Vector2 (const float x, const float y) |
float | Magnitude () const |
Gets the magnitude of this vector. | |
float | SqrMagnitude () const |
Gets the squared magnitude of this vector. It is faster that Magnitude, so it should be used for size comparison. | |
Vector2 | Normalized () const |
Gets this vector normalized. | |
float | Dot (const Vector2 &other) const |
Computes the dot product between this and other. | |
float | Distance (const Vector2 &other) const |
Computes the distance between this and other. | |
float | Angle (const Vector2 &other) const |
Computes the angle between this and other. | |
float | Major () const |
Gets the biggest component of this vector. | |
Vector2 | PositivePerpendicular () const |
Computes the perpendicular vector in +90 degrees. | |
Vector2 | NegativePerpendicular () const |
Computes the perpendicular vector in -90 degrees. | |
Vector2 | NewMagnitude (float newMagnitude) const |
Sets the magnitude of this vector. | |
void | RotateAround (const Vector2 ¢er, float angle) |
Rotates this vector around the provided axis. | |
std::string | ToString () const |
Gets a string representing this vector. | |
Vector2 | operator+ (const Vector2 &other) const |
Vector2 | operator- (const Vector2 &other) const |
Vector2 | operator+= (const Vector2 &other) |
Vector2 | operator-= (const Vector2 &other) |
Vector2 | operator+= (float scalar) |
Vector2 | operator-= (float scalar) |
Vector2 | operator*= (float scalar) |
Vector2 | operator/= (float scalar) |
bool | operator== (const Vector2 &other) const |
Vector2 | operator- () const |
Static Public Member Functions | |
static Vector2 | Normalize (const Vector2 &v) |
Normalizes the given vector. | |
static Vector2 | Lerp (const Vector2 &a, const Vector2 &b, float t) |
Linearly interpolates between A and B. | |
static Vector2 | TripleProduct (const Vector2 &a, const Vector2 &b, const Vector2 &c) |
Compute the triple product with all of these vectors as 3d vectors with z = 0. p = a x (b x c) | |
static constexpr Vector2 | Zero () |
Public Attributes | |
float | x |
The X component of the 2D Vector. | |
float | y |
The Y component of the 2D Vector. | |
Friends | |
Vector2 | operator+ (Vector2 vec, float scalar) |
Vector2 | operator- (Vector2 vec, float scalar) |
Vector2 | operator* (Vector2 vec, float scalar) |
Vector2 | operator* (float scalar, Vector2 vec) |
Vector2 | operator/ (Vector2 vec, float scalar) |
A struct representing a 2D Vector.
|
inlineconstexpr |
|
inlineconstexpr |
float stw::Vector2::Angle | ( | const Vector2 & | other | ) | const |
Computes the angle between this and other.
other | The other vector. |
float stw::Vector2::Distance | ( | const Vector2 & | other | ) | const |
Computes the distance between this and other.
other | The other vector. |
float stw::Vector2::Dot | ( | const Vector2 & | other | ) | const |
Computes the dot product between this and other.
other | The other vector. |
Linearly interpolates between A and B.
a | Start vector. |
b | End vector. |
t | Value indicating the progression between a and b. Should be between 0 and 1. |
float stw::Vector2::Magnitude | ( | ) | const |
Gets the magnitude of this vector.
float stw::Vector2::Major | ( | ) | const |
Gets the biggest component of this vector.
Vector2 stw::Vector2::NegativePerpendicular | ( | ) | const |
Computes the perpendicular vector in -90 degrees.
Vector2 stw::Vector2::NewMagnitude | ( | float | newMagnitude | ) | const |
Sets the magnitude of this vector.
newMagnitude | The new magnitude. |
Normalizes the given vector.
v | The vector to normalize. |
Vector2 stw::Vector2::Normalized | ( | ) | const |
Gets this vector normalized.
Vector2 stw::Vector2::operator*= | ( | float | scalar | ) |
Vector2 stw::Vector2::operator+= | ( | float | scalar | ) |
Vector2 stw::Vector2::operator- | ( | ) | const |
Vector2 stw::Vector2::operator-= | ( | float | scalar | ) |
Vector2 stw::Vector2::operator/= | ( | float | scalar | ) |
bool stw::Vector2::operator== | ( | const Vector2 & | other | ) | const |
Vector2 stw::Vector2::PositivePerpendicular | ( | ) | const |
Computes the perpendicular vector in +90 degrees.
void stw::Vector2::RotateAround | ( | const Vector2 & | center, |
float | angle ) |
Rotates this vector around the provided axis.
center | The axis to rotate around. |
angle | The angle by which this vector should be rotated. |
float stw::Vector2::SqrMagnitude | ( | ) | const |
Gets the squared magnitude of this vector. It is faster that Magnitude, so it should be used for size comparison.
std::string stw::Vector2::ToString | ( | ) | const |
Gets a string representing this vector.
|
static |
Compute the triple product with all of these vectors as 3d vectors with z = 0. p = a x (b x c)
a | Vector a. |
b | Vector b. |
c | Vector c. |
|
staticconstexpr |
float stw::Vector2::x |
The X component of the 2D Vector.
float stw::Vector2::y |
The Y component of the 2D Vector.