 C4 Engine API Documentation

## class Vector4D

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

`class Vector4D : public Vec4D<TypeVector4D>`

Member Functions
 `Vector4D::Set` Sets all four components of a vector. `Vector4D::Normalize` Normalizes a 4D vector. `Vector4D::Unitize` Unitizes the weight of a 4D vector. `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.
Constructor

`Vector4D();`

`Vector4D(float a, float b, float c, float d);`

`template <typename type> explicit Vector4D(const Vec4D<type>& v);`

`Vector4D(const Vector3D& v, float d);`

`Vector4D(const Vector3D& v);`

`Vector4D(const Point3D& p);`

`Vector4D(const Vector2D& v);`

`Vector4D(const Point2D& p);`

Parameters
 `a` The value of the x coordinate. `b` The value of the y coordinate. `c` The value of the z coordinate. `d` The value of the w coordinate. `v` (Template constructor) Another 4D vector, possibly with a different component type, that is converted to a `Vector4D`. `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.
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 `a`, `b`, `c`, and `d` are supplied, then they are assigned to the x, y, z, and w coordinates 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.
 `float& operator [](machine k);` Returns a reference to the `k`-th scalar component of a vector. The value of `k` must be 0, 1, 2, or 3. `const float& operator [](machine k) const;` Returns a constant reference to the `k`-th scalar 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 coordinates of `v`, and assigns a value of 0 to the w coordinate. `Vector4D& operator =(const Point3D& p);` Copies the x, y, and z coordinates of `p`, and assigns a value of 1 to the w coordinate. `Vector4D& operator =(const Vector2D& v);` Copies the x and y coordinates of `v`, assigns a value of 0 to the z coordinate, and assigns a value of 0 to the w coordinate. `Vector4D& operator =(const Point2D& p);` Copies the x and y coordinates of `p`, assigns a value of 0 to the z coordinate, and assigns a value of 1 to the w coordinate. `Vector4D& operator +=(const Vector4D& v);` Adds the vector `v`. `Vector4D& operator -=(const Vector4D& v);` Subtracts the vector `v`. `Vector4D& operator *=(const Vector4D& v);` Calculates the componentwise product with the vector `v`. `Vector4D& operator *=(float n);` Multiplies by the scalar `n`. `Vector4D& operator /=(float n);` Multiplies by the inverse of the scalar `n`.
Nonmember Operations
 `bool operator ==(const Vector4D& v1, const Vector4D& v2) const;` Returns a boolean value indicating whether the two vectors `v1` and `v2` are equal. `bool operator !=(const Vector4D& v1, const Vector4D& v2) const;` Returns a boolean value indicating whether the two vectors `v1` and `v2` are not equal. `Vector4D operator ~(const Vector4D& v);` Returns the antireverse of the vector `v`. `Vector4D operator -(const Vector4D& v);` Returns the negation of the vector `v`. `Vector4D operator +(const Vector4D& a, const Vector4D& b);` Returns the sum of the vectors `a` and `b`. `Vector4D operator +(const Vector4D& a, const Vector3D& b);` Returns the sum of the vectors `a` and `b`. The w coordinate of `b` is assumed to be 0. `Vector4D operator +(const Vector3D& a, const Vector4D& b);` Returns the sum of the vectors `a` and `b`. The w coordinate of `a` is assumed to be 0. `Vector4D operator +(const Vector4D& a, const Vector2D& b);` Returns the sum of the vectors `a` and `b`. The z and w coordinates of `b` are assumed to be 0. `Vector4D operator +(const Vector2D& a, const Vector4D& b);` Returns the sum of the vectors `a` and `b`. The z and w coordinates of `a` are assumed to be 0. `Vector4D operator -(const Vector4D& a, const Vector4D& b);` Returns the difference of the vectors `a` and `b`. `Vector4D operator -(const Vector4D& a, const Vector3D& b);` Returns the difference of the vectors `a` and `b`. The w coordinate of `b` is assumed to be 0. `Vector4D operator -(const Vector3D& a, const Vector4D& b);` Returns the difference of the vectors `a` and `b`. The w coordinate of `a` is assumed to be 0. `Vector4D operator -(const Vector4D& a, const Vector2D& b);` Returns the difference of the vectors `a` and `b`. The z and w coordinates of `b` are assumed to be 0. `Vector4D operator -(const Vector2D& a, const Vector4D& b);` Returns the difference of the vectors `a` and `b`. The z and w coordinates of `a` are assumed to be 0. `Vector4D operator *(const Vector4D& v, float n);` Returns the product of the vector `v` and the scalar `n`. `Vector4D operator *(float n, const Vector4D& v);` Returns the product of the vector `v` and the scalar `n`. `Vector4D operator /(const Vector4D& v, float n);` Returns the product of the vector `v` and the inverse of the scalar `n`. `Vector4D operator *(const Vector4D& a, const Vector4D& b);` Returns the componentwise product of the vectors `a` and `b`. `float BulkNorm(const Vector4D& v);` Returns the bulk norm of the vector `v`. `float WeightNorm(const Vector4D& v);` Returns the weight norm of the vector `v`. `Point3D Unitize(const Vector4D& v);` Returns the 3D point represented by the vector `v` after unitization. `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`. `float Dot(const Vector4D& a, const Vector4D& b);` Returns the four-dimensional dot product between `a` and `b`. `float Dot(const Vector4D& a, const Vector3D& b);` Returns the dot product of the vectors `a` and `b`. The w coordinate of `b` is assumed to be 0. `float Dot(const Vector3D& a, const Vector4D& b);` Returns the dot product of the vectors `a` and `b`. The w coordinate of `a` is assumed to be 0. `float Dot(const Vector4D& v, const Point3D& p);` Returns the dot product of the vector `v` and the point `p`. The w coordinate of `p` is assumed to be 1. `float Dot(const Point3D& p, const Vector4D& v);` Returns the dot product of the point `p` and the vector `v`. The w coordinate of `p` is assumed to be 1. `float Dot(const Vector4D& a, const Vector2D& b);` Returns the dot product with the vector `v`. The z and w coordinates of `b` are assumed to be 0. `float Dot(const Vector2D& a, const Vector4D& b);` Returns the dot product of the vectors `a` and `b`. The z and w coordinates of `a` is assumed to be 0. `float Dot(const Vector4D& v, const Point2D& p);` Returns the dot product of the vector `v` and the point `p`. The z coordinate of `p` is assumed to be 0, and the w coordinate of `p` is assumed to be 1. `float Dot(const Point2D& p, const Vector4D& v);` Returns the dot product of the point `p` and the vector `v`. The z coordinate of `p` is assumed to be 0, and the w coordinate of `p` is assumed to be 1. `Vector4D Project(const Vector4D& a, const Vector4D& b);` Returns (a ⋅ b)b, which is the projection of `a` onto `b` under the assumption that the magnitude of `b` is one. `Vector3D Reject(const Vector3D& a, const Vector3D& b);` Returns a − (a ⋅ b)b, which is the rejection of `a` from `b` under the assumption that the magnitude of `b` is one.
Base Classes
 `Vec4D` Vectors use a generic base class to store their components.
`Vector3D`
`Point3D`
`Plane3D`
`Vector2D`
`Point2D`