![]() |
Angel
A 2D Game Prototyping Engine
|
A two-dimensional floating point vector and associated math functions. More...
#include <Vector2.h>
Public Member Functions | |
| Vector2 (float x, float y) | |
| Vector2 (float value) | |
| Vector2 (const Vec2i ©) | |
| Vector2 () | |
| float | Length () |
| float | LengthSquared () |
| void | Normalize () |
| bool | operator== (const Vector2 &v) const |
| bool | operator!= (const Vector2 &v) const |
| Vector2 | operator- () const |
| Vector2 | operator- (const Vector2 &v) const |
| Vector2 | operator+ (const Vector2 &v) const |
| Vector2 | operator/ (float divider) const |
| Vector2 | operator* (float scaleFactor) const |
| Vector2 & | operator+= (const Vector2 &v) |
| Vector2 & | operator-= (const Vector2 &v) |
| Vector2 & | operator*= (float f) |
| Vector2 & | operator/= (float f) |
Static Public Member Functions | |
| static float | Distance (const Vector2 &value1, const Vector2 &value2) |
| static float | DistanceSquared (const Vector2 &value1, const Vector2 &value2) |
| static float | Dot (const Vector2 &value1, const Vector2 &value2) |
| static float | Cross (const Vector2 &value1, const Vector2 &value2) |
| static Vector2 | Normalize (const Vector2 &value) |
| static Vector2 | Reflect (const Vector2 &vector, const Vector2 &normal) |
| static Vector2 | Min (const Vector2 &value1, const Vector2 &value2) |
| static Vector2 | Max (const Vector2 &value1, const Vector2 &value2) |
| static Vector2 | Clamp (const Vector2 &value, const Vector2 &min, const Vector2 &max) |
| static Vector2 | Lerp (const Vector2 &value1, const Vector2 &value2, float amount) |
| static Vector2 | Negate (const Vector2 &value) |
| static Vector2 | Rotate (const Vector2 &value, const float radians) |
Public Attributes | |
| float | X |
| float | Y |
Static Public Attributes | |
| static Vector2 | Zero |
| static Vector2 | One |
| static Vector2 | UnitX |
| static Vector2 | UnitY |
A floating point two-dimensional vector. Can be used either as a traditional vector (indicating a direction) or a position (treating X and Y as coordinates).
| Vector2::Vector2 | ( | float | x, |
| float | y | ||
| ) |
Constructor to initialize the vector to set dimensions
| x | The X dimension |
| y | The Y dimension |
Definition at line 42 of file Vector2.cpp.
| Vector2::Vector2 | ( | float | value | ) |
Constructor to initialize the vector to uniform dimensions
| value | The value to use for both the X and Y dimension |
Definition at line 47 of file Vector2.cpp.
| Vector2::Vector2 | ( | const Vec2i & | copy | ) |
Constructor to initalize from a Vec2i struct.
Definition at line 57 of file Vector2.cpp.
| Vector2::Vector2 | ( | ) |
Constructor to initialize a zero-length vector (0, 0)
Definition at line 52 of file Vector2.cpp.
| float Vector2::Length | ( | ) |
Get the absolute magnitude of the vector. Uses a square-root, so be careful calling this too much within a loop.
Definition at line 62 of file Vector2.cpp.
| float Vector2::LengthSquared | ( | ) |
Get the squared magnitude of the vector -- if all you care about is comparison, it's a lot faster to consider the squared lengths of the vectors.
Definition at line 67 of file Vector2.cpp.
Get the absolute distance between two points (most useful if the Vector2 represents a position). Uses a square-root, so be careful calling this too much within a loop.
| value1 | The first point |
| value2 | The second point |
Definition at line 72 of file Vector2.cpp.
Get the absolute distance between two points -- if all you care about is comparison, it's a lot faster to consider the squared lengths of the vectors.
| value1 | The first point |
| value2 | The second point |
Definition at line 77 of file Vector2.cpp.
Get the dot product of two vectors.
| value1 | The first vector |
| value2 | The second vector |
Definition at line 82 of file Vector2.cpp.
Get the cross product of two vectors. Note that the mathematical definition of a cross product results in another vector perpendicular to the two inputs, but since both of our vectors are 2D, the returned vector will always have X and Y components of 0. Thus this function returns what would be the Z component of that vector.
| value1 | The first vector |
| value2 | The second vector |
Definition at line 87 of file Vector2.cpp.
| void Vector2::Normalize | ( | ) |
Normalizes a vector in place -- retains its direction, but ensures that its magnitude is equal to 1.0.
Definition at line 92 of file Vector2.cpp.
Get the normalized value for a Vector2 without affecting the original.
| value | The Vector2 to normalize |
Definition at line 110 of file Vector2.cpp.
Reflect one Vector around another
| vector | The vector to reflect |
| normal | The normal to reflect it around |
Definition at line 117 of file Vector2.cpp.
Get a new vector from the minimum X and minimum Y of the two
Definition at line 122 of file Vector2.cpp.
Get a new vector from the maximum X and maximum Y of the two
Definition at line 127 of file Vector2.cpp.
Clamp a vector to a given minimum and maximum
| value | The vector to be clamped |
| min | The vector representing the X and Y minimums for the clamping |
| max | The vector representing the X and Y maximums for the clamping |
Definition at line 132 of file Vector2.cpp.
Perform a linear interpolation between two vectors
| value1 | The starting point vector |
| value2 | The ending point vector |
| amount | The amount (from 0.0 to 1.0) to interpolate between them |
Definition at line 137 of file Vector2.cpp.
Get a negated vector -- if you add the result and the original, you should get a zero-length vector (0, 0)
| value | The vector to negate |
Definition at line 142 of file Vector2.cpp.
Rotate a vector
| value | The original vector to rotate |
| radians | The rotation angle (in radians) |
Definition at line 147 of file Vector2.cpp.
| float Vector2::X |
| float Vector2::Y |
Vector2 Vector2::Zero [static] |
Vector2 Vector2::One [static] |
Vector2 Vector2::UnitX [static] |
Vector2 Vector2::UnitY [static] |


1.7.5.1