![]() |
CUGL 2.1
Cornell University Game Library
|
#include <CUVec2.h>
Public Member Functions | |
Vec2 () | |
Vec2 (float x, float y) | |
Vec2 (const float *array) | |
Vec2 (const Vec2 p1, const Vec2 p2) | |
Vec2 & | operator= (const float *array) |
Vec2 & | set (float x, float y) |
Vec2 & | set (const float *array) |
Vec2 & | set (const Vec2 v) |
Vec2 & | set (const Vec2 p1, const Vec2 p2) |
Vec2 & | setZero () |
Vec2 & | clamp (const Vec2 min, const Vec2 max) |
Vec2 | getClamp (const Vec2 min, const Vec2 max) const |
Vec2 & | add (const Vec2 v) |
Vec2 & | add (float x, float y) |
Vec2 & | subtract (const Vec2 v) |
Vec2 & | subtract (float x, float y) |
Vec2 & | scale (float s) |
Vec2 & | scale (float sx, float sy) |
Vec2 & | scale (const Vec2 v) |
Vec2 & | divide (float s) |
Vec2 & | divide (float sx, float sy) |
Vec2 & | divide (const Vec2 v) |
Vec2 & | negate () |
Vec2 & | reciprocate () |
Vec2 | getNegation () const |
Vec2 | getReciprocal () const |
Vec2 & | map (std::function< float(float)> func) |
Vec2 | getMap (std::function< float(float)> func) const |
Vec2 & | operator+= (const Vec2 v) |
Vec2 & | operator-= (const Vec2 v) |
Vec2 & | operator*= (float s) |
Vec2 & | operator*= (const Vec2 v) |
Vec2 & | operator/= (float s) |
Vec2 & | operator/= (const Vec2 v) |
const Vec2 | operator+ (const Vec2 v) const |
const Vec2 | operator- (const Vec2 v) const |
const Vec2 | operator- () const |
const Vec2 | operator* (float s) const |
const Vec2 | operator* (const Vec2 v) const |
const Vec2 | operator/ (float s) const |
const Vec2 | operator/ (const Vec2 v) const |
bool | operator< (const Vec2 v) const |
bool | operator<= (const Vec2 v) const |
bool | operator> (const Vec2 v) const |
bool | operator>= (const Vec2 v) const |
bool | operator== (const Vec2 v) const |
bool | operator!= (const Vec2 v) const |
bool | under (const Vec2 v) const |
bool | over (const Vec2 v) const |
bool | equals (const Vec2 v, float variance=CU_MATH_EPSILON) const |
float | getAngle () const |
float | getAngle (const Vec2 other) const |
bool | isZero () const |
bool | isNearZero (float variance=CU_MATH_EPSILON) const |
bool | isOne () const |
bool | isInvertible () const |
bool | isUnit (float variance=CU_MATH_EPSILON) const |
float | distance (const Vec2 v) const |
float | distanceSquared (const Vec2 v) const |
float | distanceSegment (const Vec2 a, const Vec2 b) const |
float | distanceSegmentSquared (const Vec2 a, const Vec2 b) const |
float | length () const |
float | lengthSquared () const |
float | dot (const Vec2 v) const |
float | cross (const Vec2 other) const |
Vec2 & | normalize () |
Vec2 | getNormalization () const |
Vec2 & | rotate (float angle) |
Vec2 & | rotate (float angle, const Vec2 point) |
Vec2 & | rotate (const Vec2 other) |
Vec2 & | unrotate (const Vec2 other) |
Vec2 | getRotation (float angle) |
Vec2 | getRotation (float angle, const Vec2 point) |
Vec2 | getRotation (const Vec2 other) |
Vec2 | getUnrotation (const Vec2 other) |
Vec2 & | perp () |
Vec2 & | rperp () |
Vec2 | getPerp () const |
Vec2 | getRPerp () const |
Vec2 | getMidpoint (const Vec2 other) const |
Vec2 & | project (const Vec2 other) |
Vec2 | getProjection (const Vec2 other) const |
Vec2 & | lerp (const Vec2 other, float alpha) |
Vec2 | getLerp (const Vec2 other, float alpha) |
std::string | toString (bool verbose=false) const |
operator std::string () const | |
operator Size () const | |
Vec2 (const Size size) | |
Vec2 & | operator= (const Size size) |
Vec2 & | operator+= (const Size right) |
Vec2 & | operator-= (const Size right) |
const Vec2 | operator+ (const Size right) const |
const Vec2 | operator- (const Size &right) const |
operator Vec3 () const | |
Vec2 (const Vec3 v) | |
Vec2 & | operator= (const Vec3 size) |
operator Vec4 () const | |
Vec2 (const Vec4 v) | |
Vec2 & | operator= (const Vec4 size) |
Static Public Member Functions | |
static Vec2 | forAngle (const float a) |
static Vec2 * | clamp (const Vec2 v, const Vec2 min, const Vec2 max, Vec2 *dst) |
static float | angle (const Vec2 v1, const Vec2 v2) |
static Vec2 * | add (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | subtract (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | scale (const Vec2 v, float s, Vec2 *dst) |
static Vec2 * | scale (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | divide (const Vec2 v, float s, Vec2 *dst) |
static Vec2 * | divide (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | reciprocate (const Vec2 v, Vec2 *dst) |
static Vec2 * | negate (const Vec2 v, Vec2 *dst) |
static float | dot (const Vec2 v1, const Vec2 v2) |
static float | cross (const Vec2 v1, const Vec2 v2) |
static Vec2 * | normalize (const Vec2 v, Vec2 *dst) |
static Vec2 * | midpoint (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | project (const Vec2 v1, const Vec2 v2, Vec2 *dst) |
static Vec2 * | lerp (const Vec2 v1, const Vec2 v2, float alpha, Vec2 *dst) |
static bool | doesLineIntersect (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D, float *S=nullptr, float *T=nullptr) |
static bool | doesLineOverlap (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D) |
static bool | isLineParallel (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D) |
static bool | doesSegmentIntersect (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D) |
static bool | doesSegmentOverlap (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D, Vec2 *S=nullptr, Vec2 *E=nullptr) |
static Vec2 | getIntersection (const Vec2 A, const Vec2 B, const Vec2 C, const Vec2 D) |
Public Attributes | |
float | x |
float | y |
Static Public Attributes | |
static const Vec2 | ZERO |
static const Vec2 | ONE |
static const Vec2 | UNIT_X |
static const Vec2 | UNIT_Y |
static const Vec2 | ANCHOR_CENTER |
static const Vec2 | ANCHOR_BOTTOM_LEFT |
static const Vec2 | ANCHOR_TOP_LEFT |
static const Vec2 | ANCHOR_BOTTOM_RIGHT |
static const Vec2 | ANCHOR_TOP_RIGHT |
static const Vec2 | ANCHOR_MIDDLE_RIGHT |
static const Vec2 | ANCHOR_MIDDLE_LEFT |
static const Vec2 | ANCHOR_TOP_CENTER |
static const Vec2 | ANCHOR_BOTTOM_CENTER |
This class defines a 2-element floating point vector.
This class may be used to represent either a normal, a direction or a point interchangeably without casting. In addition, instances of this class may be freely cast to Size and vectors of other sizes.
This class is in standard layout with fields of uniform type. This means that it is safe to reinterpret_cast objects to float arrays.
|
inline |
Constructs a new vector initialized to all zeros.
|
inline |
Constructs a new vector initialized to the specified values.
x | The x coordinate. |
y | The y coordinate. |
|
inline |
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. |
Constructs a vector that describes the direction between the specified points.
p1 | The first point. |
p2 | The second point. |
|
explicit |
Creates a vector from the given size.
The width is converted to the x coordinate and height to y.
size | The size to convert |
|
explicit |
Creates a 2d vector from the given 3d one.
The z-value is dropped.
v | The vector to convert |
|
explicit |
Creates a 2d vector from the given 4d one.
All coordinates are divided by the w-coordinate (assuming it is not zero) before this conversion. Afterwards, both z and w are dropped.
v | The vector to convert |
Adds the given vector to this one in place.
v | The vector to add |
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 |
|
inline |
Adds the given values to this vector.
x | The x coordinate to add. |
y | The y coordinate to add. |
Returns the angle (in radians) between the specified vectors.
v1 | The first vector. |
v2 | The second vector. |
Clamps this vector within the given range.
min | The minimum value. |
max | The maximum value. |
Clamps the specified vector within the given 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. |
|
inline |
Returns the cross product of this vector with another
The cross-product of any two vectors in the plane is perpendicular to the plane. This method returns the magnitude of that z-vector.
other | The vector to cross with |
Returns the cross product of the specified vectors.
The cross-product of any two vectors in the plane is perpendicular to the plane. This method returns the magnitude of that z-vector.
v1 | The first vector. |
v2 | The second vector. |
|
inline |
Returns the distance between this vector and v.
v | The other vector. |
{
Returns the distance between this vector and line segment ab
a | The first point of the line segment. |
b | The second point of the line segment. |
{
Returns the squared distance between this vector and line segment ab
This method is faster than distanceSegment because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact distance to the segement (e.g. when simply comparing the distance to a value).
a | The first point of the line segment. |
b | The second point of the line segment. |
{
|
inline |
Returns the squared distance between this vector and v.
This method is faster than distance because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact distance between two vectors (e.g. when simply comparing the distance between different vectors).
v | The other vector. |
{
Divides this vector in place by the given vector.
This method is provided to support non-uniform scaling.
v | The vector to divide by |
Divides the specified vector and stores the result in dst.
The division is uniform by the constant s.
v | The vector to divide. |
s | The uniform division factor. |
dst | The destination vector. |
Divides the specified vector and stores the result in dst.
The division is nonuniform by the attributes in v2.
v1 | The vector to divide. |
v2 | The nonuniform division factor. |
dst | The destination vector. |
Vec2& cugl::Vec2::divide | ( | float | s | ) |
Divides this vector in place by the given factor.
s | The scalar to divide by |
Vec2& cugl::Vec2::divide | ( | float | sx, |
float | sy | ||
) |
Divides this vector nonuniformly by the given factors.
sx | The scalar to divide the x-axis |
sy | The scalar to divide the y-axis |
|
static |
Returns true if lines AB and CD intersect
The line segment parameters of the hit-points are stored in S and T. These values are left unchanged if there is no intersection.
The hit point is given by C + T * (D - C) [ or alternatively by A + S * (B - A)]
The return value for this function only tests for lines. To test intersection for segments, you must verify that both S & T lie in [0..1] . For rays, we have to make sure S & T > 0.
This method returns false if the lines overlap.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
S | the range for a hitpoint in L1 (p = A + S*(B - A)) |
T | the range for a hitpoint in L2 (p = C + T*(D - C)) |
|
static |
Returns true if line AB overlaps segment CD.
This result means that AB and CD are both parallel and are on top of each other. AB and CD are treated as lines for this function.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
|
static |
Returns true if segment AB intersects with segment CD
This method returns false if the segments overlap.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
|
static |
Returns true if Segment AB overlaps with segment CD
This result means that AB and CD are both parallel and are on top of each other. AB and CD are treated as segments for this function.
The bounds of the overlap are stored in S and E. If there is no overlap, these values may or may not be modified.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
S | the initial overlap position |
E | the terminal overlap position |
|
inline |
Returns the dot product of this vector and the specified vector.
v | The vector to compute the dot product with. |
Returns the dot product between the specified vectors.
v1 | The first vector. |
v2 | The second vector. |
|
inline |
Returns true if the vectors are within tolerance of each other.
The tolerance bounds the traditional Euclidean difference between the two vectors (treated as points)
v | The vector to compare against. |
variance | The comparison tolerance. |
|
inlinestatic |
Returns the unit vector for the given angle (in radians)
a | The defining angle in radians. |
|
inline |
Returns the angle in radians between this vector and the x axis.
If the vector is zero, the result is undefined.
float cugl::Vec2::getAngle | ( | const Vec2 | other | ) | const |
Returns the angle between this vector and other.
The angle is measured starting at this one. If either vector is zero, the result is undefined.
other | The vector to sweep towards. |
Returns a copy of this vector clamped within the given range.
Note: this does not modify this vector.
min | The minimum value. |
max | The maximum value. |
|
static |
Returns the intersection point of lines AB and CD.
This function treats AB and CD as lines, not segments. To get finer control over the intersection point, use doesLineIntersect.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
Returns the linear interpolation of this vector with other.
If alpha is 0, the vector is unchanged. If alpha is 1, the vector is other. Otherwise it is a value on the line ab. This method supports alpha outside of the range 0..1.
other | The other end of the line segment. |
alpha | The interpolation value |
|
inline |
Returns a copy of this vector with func applied to each component.
This method supports any function that has the signature float func(float); This includes many of the functions in math.h.
func | The function to map on the coordinates. |
Returns the midpoint between this point and another.
Note: this does not modify this vector.
other | The other end of the line segment. |
|
inline |
Returns a negated copy of this vector.
Note: This method does not modify the vector
|
inline |
Returns a normalized copy of this vector.
This method creates a copy of this vector that is of unit length (i.e. 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. Note: this does not modify this vector.
|
inline |
Returns a perpendicular of v, rotated 90 degrees counter-clockwise.
The result guarantees cross(v, perp(v)) >= 0
Note: this does not modify this vector.
Returns the projection of this vector on to the other one.
Note: this does not modify this vector.
other | The vector to project on. |
|
inline |
Returns a reciprocated copy of this vector.
The reciprocal is computed for each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.
Note: This method does not modify the vector
Returns a rotated copy of this vector using the angle of the other.
This rotation uses complex multiplication to add the angles of the two vectors together. This method is faster than rotating by an angle.
Note: this does not modify this vector.
other | The vector representing the angle to rotate by |
Vec2 cugl::Vec2::getRotation | ( | float | angle | ) |
Returns a copy of this vector rotated by the angle around the origin.
The angle is measured in radians. Note: this does not modify this vector.
angle | The angle to rotate by (in radians). |
Returns a copy of this vector rotated by the angle around the given point.
The angle is measured in radians. Note: this does not modify this vector.
point | The point to rotate around. |
angle | The angle to rotate by (in radians). |
|
inline |
Returns a perpendicular of v, rotated 90 degrees clockwise.
The result guarantees cross(v, perp(v)) <= 0
Note: this does not modify this vector.
Returns an unrotated copy of this vector using the angle of the other.
This rotation uses complex multiplication to add the angles of the two vectors together. This method is faster than rotating by an angle.
Note: this does not modify this vector.
other | The vector representing the angle to unrotate by |
|
inline |
Returns true if this vector contains no zeroes.
|
static |
Returns true if line AB is non-trivially parallel with segment CD.
This result means that AB and CD are parallel and are NOT overlappping. AB and CD are treated as lines for this function.
A | the startpoint for the first line L1 = (A - B) |
B | the endpoint for the first line L1 = (A - B) |
C | the startpoint for the second line L2 = (C - D) |
D | the endpoint for the second line L2 = (C - D) |
|
inline |
Returns true if this vector is with tolerance of the origin.
variance | The comparison tolerance |
|
inline |
Returns true if this vector contains all ones.
|
inline |
Returns true if this vector is a unit vector.
variance | The comparison tolerance |
|
inline |
Returns true this vector contains all zeros.
|
inline |
|
inline |
Returns the squared length of this vector.
This method is faster than length because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact length of a vectors (e.g. when simply comparing the length to a threshold value).
{
Modifies this vector to be the linear interpolation with other.
If alpha is 0, the vector is unchanged. If alpha is 1, the vector is other. Otherwise it is a value on the line ab. This method supports alpha outside of the range 0..1.
other | The other end of the line segment. |
alpha | The interpolation value |
Computes the linear interpolation of two vectors and stores it in dst.
If alpha is 0, the vector is a copy of v1. If alpha is 1, the vector is a copy of v2. Otherwise it is a value on the line v1v2. This method supports alpha outside of the range 0..1.
v1 | The first point. |
v2 | The second point. |
alpha | The interpolation value. |
dst | The destination vector. |
|
inline |
Maps the given function to the vector coordinates in place.
This method supports any function that has the signature float func(float); This includes many of the functions in math.h.
func | The function to map on the coordinates. |
Computes the midpoint between two points and stores it in dst.
v1 | The first point. |
v2 | The second point. |
dst | The destination vector. |
|
inline |
Negates this vector.
Negates the specified vector and stores the result in dst.
v | The vector to negate. |
dst | The destination vector. |
Vec2& cugl::Vec2::normalize | ( | ) |
Normalizes this vector.
This method normalizes the vector so that it is of unit length (i.e. 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.
Normalizes the specified vector and stores the result in dst.
If the quaternion already has unit length or if the length of the quaternion is zero, this method copies v into dst.
v | The vector to normalize. |
dst | The destination vector. |
|
inline |
Cast from Vec2 to a string.
cugl::Vec2::operator Vec4 | ( | ) | const |
|
inline |
Returns true if this vector is not equal to the given vector.
Comparison is exact, which may be unreliable given that the attributes are floats.
v | The vector to compare against. |
Returns the scalar product of this vector with the given vector.
This method is provided to support non-uniform scaling. Note: this does not modify this vector.
v | The vector to scale by. |
|
inline |
Returns the scalar product of this vector with the given value.
Note: this does not modify this vector.
s | The value to scale by. |
Scales this vector nonuniformly by the given vector.
v | The vector to scale by |
|
inline |
Scales this vector in place by the given factor.
s | The value to scale by |
Returns the sum of this vector with the given size.
Note: this does not modify this vector.
right | The suze to add. |
Returns 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 one in place.
v | The vector to add |
|
inline |
Returns the negation of this vector.
Note: this does not modify this vector.
Returns the difference of this vector with the given size.
Note: this does not modify this vector.
right | The size to subtract. |
Returns the difference of this vector with the given vector.
Note: this does not modify this vector.
v | The vector to subtract. |
Subtracts the given vector from this one in place.
v | The vector to subtract |
Returns a copy of this vector divided by the given vector.
This method is provided to support non-uniform scaling. Note: this does not modify this vector.
v | the vector to divide this vector with |
|
inline |
Returns a copy of this vector divided by the given constant
Note: this does not modify this vector.
s | the constant to divide this vector with |
Divides this vector in place by the given vector.
This method is provided to support non-uniform scaling.
v | The vector to divide by |
|
inline |
Divides this vector in place by the given factor.
s | The scalar to divide by |
|
inline |
Returns true if this vector is less than the given vector.
This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().
v | The vector to compare against. |
|
inline |
Returns true if this vector is less than or equal the given vector.
This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().
v | The vector to compare against. |
|
inline |
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. |
Sets the coordinates of this vector to those of the given size.
The width is converted to the x coordinate and height to y.
size | The size to convert. |
Sets the coordinates of this vector to those of the given 3d vector.
The z-value is dropped.
size | The vector to convert |
Sets the coordinates of this vector to those of the given 4d vector.
All coordinates are divided by the w-coordinate (assuming it is not zero) before this conversion. Afterwards, both z and w are dropped.
size | The vector to convert |
|
inline |
Returns true if this vector is equal to the given vector.
Comparison is exact, which may be unreliable given that the attributes are floats.
v | The vector to compare against. |
|
inline |
Returns true if this vector is greater than the given vector.
This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().
v | The vector to compare against. |
|
inline |
Returns true if this vector is greater than or equal the given vector.
This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().
v | The vector to compare against. |
|
inline |
Returns true if this vector dominates the given vector.
Domination means that all components of this vector are greater than or equal to the components of the given vector.
v | The vector to compare against. |
|
inline |
Converts this vector to its perpendicular, rotated 90 degrees counter-clockwise.
The result guarantees cross(original, v) >= 0
Modifies this vector to be its projection on to the other one.
other | The vector to project on. |
Computes the projection of one vector on to another and stores it in dst.
v1 | The original vector. |
v2 | The vector to project on. |
dst | The destination vector. |
|
inline |
Reciprovates this vector in place.
The reciprocal is computed for each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.
Reciprocates the specified quaternion and stores the result in dst.
Reciprocation is applied to each element invidiually. This method does not check that all elements are non-zero. If any element is zero, the result will be system-dependent.
v | The vector to reciprocate. |
dst | The destination vector. |
Rotates this vector so that its angle is increased by that of the other.
This rotation uses complex multiplication to add the angles of the two vectors together. This method is faster than rotating by an angle.
other | The vector representing the angle to rotate by |
Vec2& cugl::Vec2::rotate | ( | float | angle | ) |
Rotates this vector by the angle (in radians) around the origin.
angle | The angle to rotate by (in radians). |
Rotates this vector by the angle (in radians) around the given point.
point | The point to rotate around. |
angle | The angle to rotate by (in radians). |
|
inline |
Converts this vector to its perpendicular, rotated 90 degrees clockwise.
The result guarantees cross(original, v) <= 0
Scales this vector nonuniformly by the given vector.
v | The vector to scale by |
Scales the specified vector and stores the result in dst.
The scale is uniform by the constant s.
v | The vector to scale. |
s | The uniform scaling factor. |
dst | The destination vector. |
Scales the specified vector and stores the result in dst.
The scale is nonuniform by the attributes in v2.
v1 | The vector to scale. |
v2 | The nonuniform scaling factor. |
dst | The destination vector. |
|
inline |
Scales this vector in place by the given factor.
s | The scalar to multiply by |
|
inline |
Scales this vector nonuniformly by the given factors.
sx | The scalar to multiply the x-axis |
sy | The scalar to multiply the y-axis |
|
inline |
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. |
Sets this vector to the directional vector between the specified points.
p1 | The initial point of the vector. |
p2 | The terminal point of the vector. |
Sets the elements of this vector to those in the specified vector.
v | The vector to copy. |
|
inline |
Sets the elements of this vector to the specified values.
x | The new x coordinate. |
y | The new y coordinate. |
|
inline |
Sets the elements of this vector to zero.
Subtracts the given vector from this one in place.
v | The vector to subtract |
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. |
|
inline |
Subtracts the given values from this vector.
x | The x coordinate to subtract. |
y | The y coordinate to subtract. |
std::string cugl::Vec2::toString | ( | bool | verbose = false | ) | const |
Returns a string representation of this vector for debugging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information |
|
inline |
Returns true if this vector is dominated by the given vector.
Domination means that all components of the given vector are greater than or equal to the components of this one.
v | The vector to compare against. |
Rotates this vector so that its angle is decreased by that of the other.
This rotation uses complex multiplication to add the angles of the two vectors together. This method is faster than rotating by an angle.
other | The vector representing the angle to unrotate by |
|
static |
The relative anchor Vec2(0.5, 0) in the unit square
|
static |
The relative anchor Vec2(0, 0) in the unit square
|
static |
The relative anchor Vec2(1, 0) in the unit square
|
static |
The relative anchor Vec2(0, 0.5) in the unit square
|
static |
The relative anchor Vec2(1, 0.5) in the unit square
|
static |
The relative anchor Vec2(0, 1) in the unit square
|
static |
The relative anchor Vec2(1, 1) in the unit square
|
static |
The unit vector Vec2(1,1)
|
static |
The x-axis Vec2(1,0)
|
static |
The y-axis Vec2(0,1)
float cugl::Vec2::x |
The x coordinate.
float cugl::Vec2::y |
The x coordinate.
|
static |
The zero vector Vec2(0,0)