v0.1.8
|
A two dimensional 32 bit floating point vector. More...
#include <Vector2.hpp>
Public Member Functions | |
Vector2T () | |
Initializes to (0, 0). | |
Vector2T (const Vector2T ©) | |
Copies a vector into this vector. More... | |
Vector2T (Type value) | |
Initializes all components to a given value. More... | |
Vector2T (Type x, Type y) | |
Initializes the vector with individual component values. More... | |
Vector2T & | operator= (const Vector2T &operand) |
Assigns another vector into this vector. More... | |
Type & | operator[] (UInt32 index) |
Accesses an individual component in this vector. More... | |
Type | operator[] (UInt32 index) const |
Accesses an individual (constant) component in this vector. More... | |
Vector2T | operator- () const |
Gets the inverse of the vector. More... | |
bool | operator== (const Vector2T &operand) const |
Checks if two vectors are exactly equal. More... | |
bool | operator!= (const Vector2T &operand) const |
Checks if two vectors are not exactly equal. More... | |
Vector2T | operator+ (const Vector2T &operand) const |
Performs component-based addition on two vectors. More... | |
Vector2T & | operator+= (const Vector2T &operand) |
Adds the individual components of another vector to this vector's components. More... | |
Vector2T | operator- (const Vector2T &operand) const |
Performs component-based subtraction on two vectors. More... | |
Vector2T & | operator-= (const Vector2T &operand) |
Subtracts the individual components of another vector from this vector's components. More... | |
Vector2T | operator* (Type operand) const |
Performs component-based multiplication on two vectors. More... | |
Vector2T | operator* (const MatrixT< Type > &operand) const |
Vector2T & | operator*= (Type operand) |
Multiplies the individual components of another vector onto this vector's components. More... | |
Vector2T & | operator*= (const MatrixT< Type > &operand) |
Vector2T | operator/ (Type operand) const |
Performs component-based division on two vectors. More... | |
Vector2T & | operator/= (Type operand) |
Divides the individual components of another vector onto this vector's components. More... | |
template<typename OtherType > | |
operator Vector2T< OtherType > () | |
Type & | At (UInt32 index) |
Accesses an individual component in this vector. More... | |
Type | At (UInt32 index) const |
Accesses an individual (constant) component in this vector. More... | |
void | Set (Type value) |
Sets all components to a given value. More... | |
void | Set (Type x, Type y) |
Sets all components to the given values. More... | |
void | Clear () |
Clears the vector to (0, 0). | |
Vector2T< Type > | Swizzle (UInt32 x, UInt32 y) const |
Performs a two dimensional swizzle. More... | |
Vector3T< Type > | Swizzle (UInt32 x, UInt32 y, UInt32 z) const |
Performs a three dimensional swizzle. More... | |
Vector4T< Type > | Swizzle (UInt32 x, UInt32 y, UInt32 z, UInt32 w) const |
Performs a four dimensional swizzle. More... | |
void | Normalize () |
Normalizes the vector resulting in a length of 1. More... | |
Boolean | IsNormalized (Type epsilon=0.00001f) const |
Checks if the vector is normalizes within a given epsilon. More... | |
Type | GetMagnitude () const |
Gets the magnitude of the vector. More... | |
Type | GetSquaredMagnitude () const |
Gets the squared magnitude of the vector. More... | |
Type | GetManhattanMagnitude () const |
Gets the manhattan magnitude of the vector. More... | |
Type | GetDistance (const Vector2T &other) const |
Gets the distance between two vectors. More... | |
Type | GetSquaredDistance (const Vector2T &other) const |
Gets the squared distance between two vectors. More... | |
Type | GetManhattanDistance (const Vector2T &other) const |
Gets the manhattan distance between two vectors. More... | |
void | SetAngle (Type angle) |
Sets the two dimensional angle of the vector. More... | |
Type | GetAngle () const |
Gets the two dimensional angle of the vector. More... | |
Vector2T | GetPerpendicular () const |
Gets a vector perpendicular to this one. More... | |
void | Floor () |
Rounds down each component to the nearest whole number. | |
void | Round () |
Rounds each component to the nearest whole number. | |
void | Ceil () |
Rounds up each component to the nearest whole number. | |
Vector2T | Floored () const |
Returns a vector with each component rounded down. More... | |
Vector2T | Rounded () const |
Returns a vector with each component rounded. More... | |
Vector2T | Ceiled () const |
Returns a vector with each component rounded up. More... | |
Type | SumComponents () const |
Gets the sum of the elements. More... | |
Type | MultiplyComponents () const |
Gets the product of the elements. More... | |
Type | IsNaN () const |
Static Public Member Functions | |
static Vector2T | FromAngle (Type angle, Type magnitude=1.0f) |
Creates a vector based on a given two dimensional angle with an optional magnitude. More... | |
static Type | DotProduct (const Vector2T &valueA, const Vector2T &valueB) |
static Type | CrossProduct (const Vector2T &valueA, const Vector2T &valueB) |
static Vector2T | Normalized (const Vector2T &value) |
static Type | Distance (const Vector2T &vectorA, const Vector2T &vectorB) |
static Type | DistanceSquared (const Vector2T &valueA, const Vector2T &vectorB) |
static Type | DistanceManhattan (const Vector2T &valueA, const Vector2T &vectorB) |
static Vector2T | Lerp (const Vector2T &from, const Vector2T &to, Type t) |
Performs linear interpolation on a vector2. | |
Public Attributes | |
Type | x |
The x component. | |
Type | y |
The y component. | |
Static Public Attributes | |
static const Vector2T | zero |
Zero vector, defined as (0, 0). | |
static const Vector2T | one |
One vector, defined as (1, 1). | |
static const Vector2T | unitX |
Unit X vector, defined as (1, 0). | |
static const Vector2T | unitY |
Unit Y vector, defined as (0, 1). | |
static const Vector2T | nan |
NaN vector, defined as (NaN, NaN). | |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const Vector2T< Type > &vector) |
An operator to output this vector on an output stream. | |
A two dimensional 32 bit floating point vector.
|
inline |
Copies a vector into this vector.
copy | The vector to copy. |
|
inline |
Initializes all components to a given value.
value | The value for each component. |
|
inline |
Initializes the vector with individual component values.
x | The x component. |
y | The y component. |
|
inline |
Accesses an individual component in this vector.
index | The component index, so 0 for x, and 1 for y. |
|
inline |
Accesses an individual (constant) component in this vector.
index | The component index, so 0 for x, and 1 for y. |
|
inline |
Returns a vector with each component rounded up.
|
inline |
Returns a vector with each component rounded down.
|
inlinestatic |
Creates a vector based on a given two dimensional angle with an optional magnitude.
Defined as (cos(angle) * magnitude, sin(angle) * magnitude). If no magnitude is given it will default to one.
angle | The angle in radians. |
magnitude | An optional magnitude. |
|
inline |
Gets the two dimensional angle of the vector.
Gets an angle from the vector.
|
inline |
Gets the distance between two vectors.
The distance between two vectors is defined as the magnitude of one vector subtracted by another. In other words: GetMagnitude(Vec1 - Vec2). Because of this the same notes in GetMagnitude apply to this method.
other | The other vector. |
|
inline |
Gets the magnitude of the vector.
Faster implementations of this method exist but are less accurate. For more information, see GetSquaredMagnitude and GetManhattanMagnitude.
|
inline |
Gets the manhattan distance between two vectors.
other | The other vector. |
|
inline |
Gets the manhattan magnitude of the vector.
The Manhattan magnitude is even faster than the GetMagnitudeSquared alternative, but far less accurate. The squared magnitude cannot be used to determine if one magnitude is larger than another, nor can it be used to compare magnitudes. The purpose of the Manhattan magnitude is mostly used as a guess to speed up algorithms that may use it as a heuristic.
|
inline |
Gets a vector perpendicular to this one.
|
inline |
Gets the squared distance between two vectors.
other | The other vector. |
|
inline |
Gets the squared magnitude of the vector.
The squared magnitude is a less accurate, but more quickly calculated alternative to the GetMagnitude method. A squared magnitude can be used to measure if one magnitude is larger than another, but cannot be used to accurately determine differences between magnitudes.
|
inline |
|
inline |
Checks if the vector is normalizes within a given epsilon.
|
inline |
Gets the product of the elements.
|
inline |
Normalizes the vector resulting in a length of 1.
|
inline |
Checks if two vectors are not exactly equal.
Due to floating point imprecision, vectors are rarely ever exactly equal. Use with care.
operand | The other vector. |
|
inline |
Performs component-based multiplication on two vectors.
operand | A scalar value. |
|
inline |
Multiplies the individual components of another vector onto this vector's components.
operand | A scalar value. |
|
inline |
Performs component-based addition on two vectors.
operand | The other vector. |
|
inline |
Adds the individual components of another vector to this vector's components.
operand | The other operand. |
|
inline |
Gets the inverse of the vector.
The inverse is defined as (-x, -y) of the original vector.
|
inline |
Performs component-based subtraction on two vectors.
operand | The other vector. |
|
inline |
Subtracts the individual components of another vector from this vector's components.
operand | The other operand. |
|
inline |
Performs component-based division on two vectors.
operand | The other vector. |
|
inline |
Divides the individual components of another vector onto this vector's components.
operand | The other operand. |
|
inline |
Assigns another vector into this vector.
operand | The other vector. |
|
inline |
Checks if two vectors are exactly equal.
Due to floating point imprecision, vectors are rarely ever exactly equal. Use with care.
operand | The other vector. |
|
inline |
Accesses an individual component in this vector.
index | The component index (0 for x, 1 for y). |
|
inline |
Accesses an individual (constant) component in this vector.
Unlike the other operator[], this one works on constant vectors and returns a value that cannot be modified to alter the original vector.
index | The component index (0 for x, 1 for y). |
|
inline |
Returns a vector with each component rounded.
|
inline |
Sets all components to a given value.
value | The value to set all components to. |
|
inline |
Sets all components to the given values.
x | The x component. |
y | The y component. |
|
inline |
Sets the two dimensional angle of the vector.
Sets the vector's angle while preserving its magnitude. The new x is calculated based off the cosine function and the new y is based off the sine function. The existing magnitude is calculated via GetMagnitude and applied back to the vector after the x and y have been calculated.
angle | The new angle (in radians) for the vector. |
|
inline |
Gets the sum of the elements.
|
inline |
Performs a two dimensional swizzle.
Swizzles the vector allowing the components to be re-arranged into a new vector.
x | The x component (0 for x, 1 for y). |
y | The y component (0 for x, 1 for y). |
|
inline |
Performs a three dimensional swizzle.
Swizzles the vector allowing the components to be re-arranged into a new vector.
x | The x component (0 for x, 1 for y). |
y | The y component (0 for x, 1 for y). |
z | The z component (0 for x, 1 for y). |
|
inline |
Performs a four dimensional swizzle.
Swizzles the vector allowing the components to be re-arranged into a new vector.
x | The x component (0 for x, 1 for y). |
y | The y component (0 for x, 1 for y). |
z | The z component (0 for x, 1 for y). |
w | The w component (0 for x, 1 for y). |