C4 Engine Terathon Software C4 Engine API Documentation

• Math Library

API Links
Developer Links

class Vector4D

Defined in:  C4Vector4D.h
The Vector4D class encapsulates a 4D vector.
Definition

class Vector4D

Member Functions
Vector4D::Set Sets all four components of a vector.
Vector4D::Normalize Normalizes a 4D vector.
Vector4D::GetVector3D Returns a reference to a Vector3D object.
Vector4D::GetPoint3D Returns a reference to a Point3D object.
Vector4D::RotateAboutX Rotates a vector about the x axis.
Vector4D::RotateAboutY Rotates a vector about the y axis.
Vector4D::RotateAboutZ Rotates a vector about the z axis.
Vector4D::RotateAboutAxis Rotates a vector about a given axis.
Data Members
float   x; The x coordinate.
float   y; The y coordinate.
float   z; The z coordinate.
float   w; The w coordinate.
Constructor

Vector4D();

Vector4D(float r, float s, float t, float u);

Vector4D(const Vector3D& v, float u);

Vector4D(const Vector3D& v);

Vector4D(const Point3D& p);

Vector4D(const Vector2D& v);

Vector4D(const Point2D& p);

Vector4D(const Vector3D& v, const Point3D& q);

Parameters
r The value of the x coordinate.
s The value of the y coordinate.
t The value of the z coordinate.
u The value of the w coordinate.
v A 3D vector whose entries are copied to the x, y, and z coordinates.
p A 3D point whose entries are copied to the x, y, and z coordinates.
q A 3D point that lies in a plane having the normal direction given by the v parameter.
Description
The Vector4D class is used to store a four-dimensional vector having floating-point components x, y, z, and w.

The default constructor leaves the components of the vector undefined. If the values r, s, t, and u are supplied, then they are assigned to the x, y, z, and w components of the vector, respectively. If the Vector4D object is constructed using a Vector3D or Vector2D object, then the w coordinate is set to 0. If the Vector4D object is constructed using a Point3D or Point2D object, then the w coordinate is set to 1. The z coordinate of a 2D vector or point is assumed to be 0.

If the q parameter is specified, then the 4D vector is treated as a plane having the normal direction given by the v parameter and containing the point q. In this case, the w coordinate is given by -(v * q).
Overloaded Operators
floatoperator [](long k); Returns a reference to the k-th component of a vector. The value of k must be 0, 1, 2, or 3.
const floatoperator [](long k) const; Returns a constant reference to the k-th component of a vector. The value of k must be 0, 1, 2, or 3.
Vector4D& operator =(const Vector3D& v); Copies the x, y, and z components of v, and assigns a value of 0 to the w component.
Vector4D& operator =(const Point3D& p); Copies the x, y, and z components of p, and assigns a value of 1 to the w component.
Vector4D& operator =(const Vector2D& v); Copies the x and y components of v, assigns a value of 0 to the z component, and assigns a value of 0 to the w component.
Vector4D& operator =(const Point2D& p); Copies the x and y components of p, assigns a value of 0 to the z component, and assigns a value of 1 to the w component.
Vector4D& operator +=(const Vector4D& v); Adds the vector v.
Vector4D& operator +=(const Vector3D& v); Adds the vector v. The w component is not modified.
Vector4D& operator +=(const Vector2D& v); Adds the vector v. The z and w components are not modified.
Vector4D& operator -=(const Vector4D& v); Subtracts the vector v.
Vector4D& operator -=(const Vector3D& v); Subtracts the vector v. The w component is not modified.
Vector4D& operator -=(const Vector2D& v); Subtracts the vector v. The z and w components are not modified.
Vector4D& operator *=(float t); Multiplies by the scalar t.
Vector4D& operator /=(float t); Multiplies by the inverse of the scalar t.
Vector4D& operator &=(const Vector4D& v); Calculates the componentwise product with the vector v.
Nonmember Operations
Vector4D operator -(const Vector4D& v); Returns the negation of the vector v.
Vector4D operator +(const Vector4D& v1, const Vector4D& v2); Returns the sum of the vectors v1 and v2.
Vector4D operator +(const Vector4D& v1, const Vector3D& v2); Returns the sum of the vectors v1 and v2. The w component of v2 is assumed to be 0.
Vector4D operator +(const Vector3D& v1, const Vector4D& v2); Returns the sum of the vectors v1 and v2. The w component of v1 is assumed to be 0.
Vector4D operator +(const Vector4D& v1, const Vector2D& v2); Returns the sum of the vectors v1 and v2. The z and w components of v2 are assumed to be 0.
Vector4D operator +(const Vector2D& v1, const Vector4D& v2); Returns the sum of the vectors v1 and v2. The z and w components of v1 are assumed to be 0.
Vector4D operator -(const Vector4D& v1, const Vector4D& v2); Returns the difference of the vectors v1 and v2.
Vector4D operator -(const Vector4D& v1, const Vector3D& v2); Returns the difference of the vectors v1 and v2. The w component of v2 is assumed to be 0.
Vector4D operator -(const Vector3D& v1, const Vector4D& v2); Returns the difference of the vectors v1 and v2. The w component of v1 is assumed to be 0.
Vector4D operator -(const Vector4D& v1, const Vector2D& v2); Returns the difference of the vectors v1 and v2. The z and w components of v2 are assumed to be 0.
Vector4D operator -(const Vector2D& v1, const Vector4D& v2); Returns the difference of the vectors v1 and v2. The z and w components of v1 are assumed to be 0.
Vector4D operator *(const Vector4D& v, float t); Returns the product of the vector v and the scalar t.
Vector4D operator *(float t, const Vector4D& v); Returns the product of the vector v and the scalar t.
Vector4D operator /(const Vector4D& v, float t); Returns the product of the vector v and the inverse of the scalar t.
float operator *(const Vector4D& v1, const Vector4D& v2); Returns the four-dimensional dot product of the vectors v1 and v2.
float operator *(const Vector4D& v1, const Vector3D& v2); Returns the dot product of the vectors v1 and v2. The w component of v2 is assumed to be 0.
float operator *(const Vector3D& v1, const Vector4D& v2); Returns the dot product of the vectors v1 and v2. The w component of v1 is assumed to be 0.
float operator *(const Vector4D& v, const Point3D& p); Returns the dot product of the vector v and the point p. The w component of p is assumed to be 1. (This gives the distance from a plane (with unit length normal) represented by a Vector4D object to the point p.)
float operator *(const Point3D& p, const Vector4D& v); Returns the dot product of the point p and the vector v. The w component of p is assumed to be 1.
float operator *(const Vector4D& v1, const Vector2D& v2); Returns the dot product with the vector v. The z and w components of v are assumed to be 0.
float operator *(const Vector2D& v1, const Vector4D& v2); Returns the dot product of the vectors v1 and v2. The z and w components of v1 is assumed to be 0.
float operator *(const Vector4D& v, const Point2D& p); Returns the dot product of the vector v and the point p. The z component of p is assumed to be 0, and the w component of p is assumed to be 1.
float operator *(const Point2D& p, const Vector4D& v); Returns the dot product of the point p and the vector v. The z component of p is assumed to be 0, and the w component of p is assumed to be 1.
Vector3D operator %(const Vector4D& v1, const Vector3D& v2); Returns the cross product of the vectors v1 and v2. The w component is ignored.
Vector4D operator &(const Vector4D& v1, const Vector4D& v2); Returns the componentwise product of the vectors v1 and v2.
bool operator ==(const Vector4D& v1, const Vector4D& v2); Returns a boolean value indicating the equality of the two vectors v1 and v2.
bool operator !=(const Vector4D& v1, const Vector4D& v2); Returns a boolean value indicating the inequality of the two vectors v1 and v2
float Dot(const Vector4D& v1, const Vector4D& v2); Returns the dot product between v1 and v2.
Vector4D ProjectOnto(const Vector4D& v1, const Vector4D& v2); Returns the projection of v1 onto v2 scaled by the squared magnitude of v2.
float Magnitude(const Vector4D& v); Returns the magnitude of the vector v.
float InverseMag(const Vector4D& v); Returns the inverse magnitude of the vector v.
float SquaredMag(const Vector4D& v); Returns the squared magnitude of the vector v.
See Also

Vector3D

Point3D

Vector2D

Point2D