C4 Engine Terathon Software C4 Engine API Documentation

• Math Library

API Links
Developer Links

class Vector2D

Defined in:  C4Vector2D.h
The Vector2D class encapsulates a 2D vector.
Definition

class Vector2D

Member Functions
Vector2D::Set Sets both components of a vector.
Vector2D::Normalize Normalizes a 2D vector.
Vector2D::Rotate Rotates a vector in the x-y plane.
Data Members
float   x; The x coordinate.
float   y; The y coordinate.
Constructor

Vector2D();

Vector2D(float r, float s);

Parameters
r The value of the x coordinate.
s The value of the y coordinate.
Description
The Vector2D class is used to store a two-dimensional direction vector having floating-point components x and y. A direction vector stored in this class is assumed to have a w coordinate of 0 whenever it needs to be converted to a four-dimensional representation. Two-dimensional points (for which the w coordinate is 1) should be stored using the Point2D class. The z coordinate of a 2D vector is always assumed to be 0.

The default constructor leaves the components of the vector undefined. If the values r and s are supplied, then they are assigned to the x and y components of the vector, respectively.
Overloaded Operators
floatoperator [](long k); Returns a reference to the k-th component of a vector. The value of k must be 0 or 1.
const floatoperator [](long k) const; Returns a constant reference to the k-th component of a vector. The value of k must be 0 or 1.
Vector2D& operator +=(const Vector2D& v); Adds the vector v.
Vector2D& operator -=(const Vector2D& v); Subtracts the vector v.
Vector2D& operator *=(float t); Multiplies by the scalar t.
Vector2D& operator /=(float t); Divides by the scalar t.
Vector2D& operator &=(const Vector2D& v); Calculates the componentwise product with the vector v.
Nonmember Operations
Vector2D operator -(const Vector2D& v) const; Returns the negation of the vector v.
Vector2D operator +(const Vector2D& v1, const Vector2D& v2) const; Returns the sum of the vectors v1 and v2.
Vector2D operator -(const Vector2D& v1, const Vector2D& v2) const; Returns the difference of the vectors v1 and v2.
Vector2D operator *(const Vector2D& v, float t) const; Returns the product of the vector v and the scalar t.
Vector2D operator *(float t, const Vector2D& v); Returns the product of the vector v and the scalar t.
Vector2D operator /(const Vector2D& v, float t) const; Returns the product of the vector v and the inverse of the scalar t.
float operator *(const Vector2D& v1, const Vector2D& v2) const; Returns the dot product of the vectors v1 and v2.
Vector2D operator &(const Vector2D& v1, const Vector2D& v2) const; Returns the componentwise product of the vectors v1 and v2.
bool operator ==(const Vector2D& v1, const Vector2D& v2) const; Returns a boolean value indicating the equality of the two vectors v1 and v2.
bool operator !=(const Vector2D& v1, const Vector2D& v2) const; Returns a boolean value indicating the inequality of the two vectors v1 and v2.
float Dot(const Vector2D& v1, const Vector2D& v2); Returns the dot product between v1 and v2.
Vector2D ProjectOnto(const Vector2D& v1, const Vector2D& v2); Returns the projection of v1 onto v2 scaled by the squared magnitude of v2.
float Magnitude(const Vector2D& v); Returns the magnitude of the vector v.
float InverseMag(const Vector2D& v); Returns the inverse magnitude of the vector v.
float SquaredMag(const Vector2D& v); Returns the squared magnitude of the vector v.
See Also

Point2D

Vector4D