#include <Vector2.h>
Public Member Functions | |
Vector2 () | |
Vector2 (float x, float y) | |
Vector2 (const float *array) | |
Vector2 (const Vector2 &p1, const Vector2 &p2) | |
Vector2 (const Vector2 ©) | |
~Vector2 () | |
bool | isZero () const |
bool | isOne () const |
void | add (const Vector2 &v) |
void | clamp (const Vector2 &min, const Vector2 &max) |
float | distance (const Vector2 &v) const |
float | distanceSquared (const Vector2 &v) const |
float | dot (const Vector2 &v) const |
float | length () const |
float | lengthSquared () const |
void | negate () |
Vector2 & | normalize () |
void | normalize (Vector2 *dst) const |
void | scale (float scalar) |
void | scale (const Vector2 &scale) |
void | rotate (const Vector2 &point, float angle) |
void | set (float x, float y) |
void | set (const float *array) |
void | set (const Vector2 &v) |
void | set (const Vector2 &p1, const Vector2 &p2) |
void | subtract (const Vector2 &v) |
void | smooth (const Vector2 &target, float elapsedTime, float responseTime) |
const Vector2 | operator+ (const Vector2 &v) const |
Vector2 & | operator+= (const Vector2 &v) |
const Vector2 | operator- (const Vector2 &v) const |
Vector2 & | operator-= (const Vector2 &v) |
const Vector2 | operator- () const |
const Vector2 | operator* (float x) const |
Vector2 & | operator*= (float x) |
const Vector2 | operator/ (float x) const |
bool | operator< (const Vector2 &v) const |
bool | operator== (const Vector2 &v) const |
bool | operator!= (const Vector2 &v) const |
Static Public Member Functions | |
static const Vector2 & | zero () |
static const Vector2 & | one () |
static const Vector2 & | unitX () |
static const Vector2 & | unitY () |
static float | angle (const Vector2 &v1, const Vector2 &v2) |
static void | add (const Vector2 &v1, const Vector2 &v2, Vector2 *dst) |
static void | clamp (const Vector2 &v, const Vector2 &min, const Vector2 &max, Vector2 *dst) |
static float | dot (const Vector2 &v1, const Vector2 &v2) |
static void | subtract (const Vector2 &v1, const Vector2 &v2, Vector2 *dst) |
Public Attributes | |
float | x |
float | y |
Defines a 2-element floating point vector.
Constructs a new vector initialized to all zeros.
gameplay::Vector2::Vector2 | ( | float | x, |
float | y | ||
) |
Constructs a new vector initialized to the specified values.
x | The x coordinate. |
y | The y coordinate. |
gameplay::Vector2::Vector2 | ( | const float * | array | ) |
Constructs a new vector from the values in the specified array.
array | An array containing the elements of the vector in the order x, y. |
gameplay::Vector2::Vector2 | ( | const Vector2 & | p1, |
const Vector2 & | p2 | ||
) |
Constructs a vector that describes the direction between the specified points.
p1 | The first point. |
p2 | The second point. |
gameplay::Vector2::Vector2 | ( | const Vector2 & | copy | ) |
Constructs a new vector that is a copy of the specified vector.
copy | The vector to copy. |
Destructor.
void gameplay::Vector2::add | ( | const Vector2 & | v | ) |
Adds the elements of the specified vector to this one.
v | The vector to add. |
static void gameplay::Vector2::add | ( | const Vector2 & | v1, |
const Vector2 & | v2, | ||
Vector2 * | dst | ||
) | [static] |
Adds the specified vectors and stores the result in dst.
v1 | The first vector. |
v2 | The second vector. |
dst | A vector to store the result in. |
static float gameplay::Vector2::angle | ( | const Vector2 & | v1, |
const Vector2 & | v2 | ||
) | [static] |
Returns the angle (in radians) between the specified vectors.
v1 | The first vector. |
v2 | The second vector. |
void gameplay::Vector2::clamp | ( | const Vector2 & | min, |
const Vector2 & | max | ||
) |
Clamps this vector within the specified range.
min | The minimum value. |
max | The maximum value. |
static void gameplay::Vector2::clamp | ( | const Vector2 & | v, |
const Vector2 & | min, | ||
const Vector2 & | max, | ||
Vector2 * | dst | ||
) | [static] |
Clamps the specified vector within the specified range and returns it in dst.
v | The vector to clamp. |
min | The minimum value. |
max | The maximum value. |
dst | A vector to store the result in. |
float gameplay::Vector2::distance | ( | const Vector2 & | v | ) | const |
Returns the distance between this vector and v.
v | The other vector. |
float gameplay::Vector2::distanceSquared | ( | const Vector2 & | v | ) | const |
Returns the squared distance between this vector and v.
When it is not necessary to get the exact distance between two vectors (for example, when simply comparing the distance between different vectors), it is advised to use this method instead of distance.
v | The other vector. |
float gameplay::Vector2::dot | ( | const Vector2 & | v | ) | const |
Returns the dot product of this vector and the specified vector.
v | The vector to compute the dot product with. |
static float gameplay::Vector2::dot | ( | const Vector2 & | v1, |
const Vector2 & | v2 | ||
) | [static] |
Returns the dot product between the specified vectors.
v1 | The first vector. |
v2 | The second vector. |
bool gameplay::Vector2::isOne | ( | ) | const |
Indicates whether this vector contains all ones.
bool gameplay::Vector2::isZero | ( | ) | const |
Indicates whether this vector contains all zeros.
float gameplay::Vector2::length | ( | ) | const |
float gameplay::Vector2::lengthSquared | ( | ) | const |
Returns the squared length of this vector.
When it is not necessary to get the exact length of a vector (for example, when simply comparing the lengths of different vectors), it is advised to use this method instead of length.
void gameplay::Vector2::negate | ( | ) |
Negates this vector.
Normalizes this vector.
This method normalizes this Vector2 so that it is of unit length (in other words, the length of the vector after calling this method will be 1.0f). If the vector already has unit length or if the length of the vector is zero, this method does nothing.
void gameplay::Vector2::normalize | ( | Vector2 * | dst | ) | const |
Normalizes this vector and stores the result in dst.
If the vector already has unit length or if the length of the vector is zero, this method simply copies the current vector into dst.
dst | The destination vector. |
static const Vector2& gameplay::Vector2::one | ( | ) | [static] |
Returns the one vector.
bool gameplay::Vector2::operator!= | ( | const Vector2 & | v | ) | const [inline] |
Determines if this vector is not equal to the given vector.
v | The vector to compare against. |
const Vector2 gameplay::Vector2::operator* | ( | float | x | ) | const [inline] |
Calculates the scalar product of this vector with the given value.
Note: this does not modify this vector.
x | The value to scale by. |
Vector2& gameplay::Vector2::operator*= | ( | float | x | ) | [inline] |
Scales this vector by the given value.
x | The value to scale by. |
Calculates the sum of this vector with the given vector.
Note: this does not modify this vector.
v | The vector to add. |
Adds the given vector to this vector.
v | The vector to add. |
Calculates the sum of this vector with the given vector.
Note: this does not modify this vector.
v | The vector to add. |
const Vector2 gameplay::Vector2::operator- | ( | ) | const [inline] |
Calculates the negation of this vector.
Note: this does not modify this vector.
Subtracts the given vector from this vector.
v | The vector to subtract. |
const Vector2 gameplay::Vector2::operator/ | ( | float | x | ) | const [inline] |
Returns the components of this vector divided by the given constant
Note: this does not modify this vector.
x | the constant to divide this vector with |
bool gameplay::Vector2::operator< | ( | const Vector2 & | v | ) | const [inline] |
Determines if this vector is less than the given vector.
v | The vector to compare against. |
bool gameplay::Vector2::operator== | ( | const Vector2 & | v | ) | const [inline] |
Determines if this vector is equal to the given vector.
v | The vector to compare against. |
void gameplay::Vector2::rotate | ( | const Vector2 & | point, |
float | angle | ||
) |
Rotates this vector by angle (specified in radians) around the given point.
point | The point to rotate around. |
angle | The angle to rotate by (in radians). |
void gameplay::Vector2::scale | ( | float | scalar | ) |
Scales all elements of this vector by the specified value.
scalar | The scalar value. |
void gameplay::Vector2::scale | ( | const Vector2 & | scale | ) |
Scales each element of this vector by the matching component of scale.
scale | The vector to scale by. |
void gameplay::Vector2::set | ( | float | x, |
float | y | ||
) |
Sets the elements of this vector to the specified values.
x | The new x coordinate. |
y | The new y coordinate. |
void gameplay::Vector2::set | ( | const float * | array | ) |
Sets the elements of this vector from the values in the specified array.
array | An array containing the elements of the vector in the order x, y. |
void gameplay::Vector2::set | ( | const Vector2 & | v | ) |
Sets the elements of this vector to those in the specified vector.
v | The vector to copy. |
void gameplay::Vector2::set | ( | const Vector2 & | p1, |
const Vector2 & | p2 | ||
) |
Sets this vector to the directional vector between the specified points.
p1 | The first point. |
p2 | The second point. |
void gameplay::Vector2::smooth | ( | const Vector2 & | target, |
float | elapsedTime, | ||
float | responseTime | ||
) |
Updates this vector towards the given target using a smoothing function. The given response time determines the amount of smoothing (lag). A longer response time yields a smoother result and more lag. To force this vector to follow the target closely, provide a response time that is very small relative to the given elapsed time.
target | target value. |
elapsedTime | elapsed time between calls. |
responseTime | response time (in the same units as elapsedTime). |
void gameplay::Vector2::subtract | ( | const Vector2 & | v | ) |
Subtracts this vector and the specified vector as (this - v) and stores the result in this vector.
v | The vector to subtract. |
static void gameplay::Vector2::subtract | ( | const Vector2 & | v1, |
const Vector2 & | v2, | ||
Vector2 * | dst | ||
) | [static] |
Subtracts the specified vectors and stores the result in dst. The resulting vector is computed as (v1 - v2).
v1 | The first vector. |
v2 | The second vector. |
dst | The destination vector. |
static const Vector2& gameplay::Vector2::unitX | ( | ) | [static] |
Returns the unit x vector.
static const Vector2& gameplay::Vector2::unitY | ( | ) | [static] |
Returns the unit y vector.
static const Vector2& gameplay::Vector2::zero | ( | ) | [static] |
Returns the zero vector.
float gameplay::Vector2::x |
The x coordinate.
float gameplay::Vector2::y |
The y coordinate.