C4 Engine API Documentation

## class Quaternion

Defined in:  `TSQuaternion.h`
The `Quaternion` class encapsulates a quaternion.
Definition

`class Quaternion`

Member Functions
 `Quaternion::Set` Sets all four components of a quaternion. `Quaternion::Normalize` Normalizes a quaternion. `Quaternion::MakeRotationX` Returns a quaternion that represents a rotation about the x axis. `Quaternion::MakeRotationY` Returns a quaternion that represents a rotation about the y axis. `Quaternion::MakeRotationZ` Returns a quaternion that represents a rotation about the z axis. `Quaternion::MakeRotation` Returns a quaternion that represents a rotation about a given axis. `Quaternion::GetRotationMatrix` Converts a quaternion to a 3 × 3 matrix. `Quaternion::SetRotationMatrix` Converts a 3 × 3 matrix to a quaternion.
Data Members
 `Component                 x;` The x coordinate of the bivector part. `Component                 y;` The y coordinate of the bivector part. `Component                 z;` The z coordinate of the bivector part. `Component                 w;` The w coordinate, which is the scalar part. `Subvec3D      xyz;` The x, y, and z coordinates together as a single bivector.
Constructor

`Quaternion();`

`Quaternion(float a, float b, float c, float s);`

`Quaternion(const Vector3D& v, float s);`

`explicit Quaternion(const Vector3D& v);`

`explicit Quaternion(float s);`

Description
The `Quaternion` class encapsulates a Hamiltonian quaternion having the form xi + yj + zk + w.

The default constructor leaves the components of the quaternion undefined. If the values `a`, `b`, `c`, and `s` are supplied, then they are assigned to the x, y, z, and w coordinates of the quaternion, respectively. The components of `v` are assigned to the imaginary components x, y, and z of the quaternion, and the scalar `s` is assigned to the real component w. If a quaternion is constructed with only the `Vector3D` object `v`, then the real coordinate w is set to 0. If a quaternion is constructed with only the scalar `s`, then the imaginary components x, y, and z are set to 0.

When performing arithmetic with quaternions, 3D vectors are always treated as quaternions with w = 0, and scalars are always treated as quaternions with x,y,z = 0.
 `Quaternion& operator =(const Vector3D& v);` Assigns the of `v` to the imaginary components x, y, and z of the quaternion. The real component w is set to 0. `Quaternion& operator =(float s);` Sets the real component w of the quaternion to `s`, and sets the imaginary components x, y, and z to 0. `Quaternion& operator +=(const Quaternion& q);` Adds the quaternion `q`. `Quaternion& operator +=(const Vector3D& v);` Adds the vector `v`. `Quaternion& operator +=(float s);` Adds the scalar `s`. `Quaternion& operator -=(const Quaternion& q);` Subtracts the quaternion `q`. `Quaternion& operator -=(const Vector3D& v);` Subtracts the vector `v`. `Quaternion& operator -=(float s);` Subtracts the scalar `s`. `Quaternion& operator *=(const Quaternion& q);` Multiplies by the quaternion `q`. `Quaternion& operator *=(const Vector3D& v);` Multiplies by the vector `v`. `Quaternion& operator *=(float s);` Multiplies by the scalar `s`. `Quaternion& operator /=(const Quaternion& q);` Multiplies by the inverse of the quaternion `q`. `Quaternion& operator /=(const Vector3D& v);` Multiplies by the inverse of the vector `v`. `Quaternion& operator /=(float s);` Multiplies by the inverse of the scalar `s`.
 `bool operator ==(const Quaternion& q1, const Quaternion& q2);` Returns a boolean value indicating whether the two quaternions `q1` and `q2` are equal. `bool operator ==(const Quaternion& q, const Vector3D& v);` Returns a boolean value indicating whether the quaternion `q` and the vector `v` are equal. `bool operator ==(const Vector3D& v, const Quaternion& q);` Returns a boolean value indicating whether the vector `v` and the quaternion `q` are equal. `bool operator ==(const Quaternion& q, float s);` Returns a boolean value indicating whether the quaternion `q` and the scalar `s` are equal. `bool operator ==(float s, const Quaternion& q);` Returns a boolean value indicating whether the scalar `a` and the quaternion `q` are equal. `bool operator !=(const Quaternion& q1, const Quaternion& q2);` Returns a boolean value indicating whether the two quaternions `q1` and `q2` are not equal. `bool operator !=(const Quaternion& q, const Vector3D& v);` Returns a boolean value indicating whether the quaternion `q` and the vector `v` are not equal. `bool operator !=(const Vector3D& v, const Quaternion& q);` Returns a boolean value indicating whether the vector `v` and the quaternion `q` are not equal. `bool operator !=(const Quaternion& q, float s);` Returns a boolean value indicating whether the quaternion `q` and the scalar `s` are not equal. `bool operator !=(float s, const Quaternion& q);` Returns a boolean value indicating whether the scalar `s` and the quaternion `q` are not equal. `Quaternion operator -(const Quaternion& q);` Returns the negation of the quaternion `q`. `Quaternion operator +(const Quaternion& q1, const Quaternion& q2);` Returns the sum of the quaternions `q1` and `q2`. `Quaternion operator +(const Quaternion& q, const Vector3D& v);` Returns the sum of the quaternion `q` and the vector `v`. `Quaternion operator +(const Vector3D& v, const Quaternion& q);` Returns the sum of the vector `v` and the quaternion `q`. `Quaternion operator +(const Quaternion& q, float s);` Returns the sum of the quaternion `q` and the scalar `s`. `Quaternion operator +(float s, const Quaternion& q);` Returns the sum of the scalar `s` and the quaternion `q`. `Quaternion operator -(const Quaternion& q1, const Quaternion& q2);` Returns the difference of the quaternions `q1` and `q2`. `Quaternion operator -(const Quaternion& q, const Vector3D& v);` Returns the difference of the quaternion `q` and the vector `v`. `Quaternion operator -(const Vector3D& v, const Quaternion& q);` Returns the difference of the vector `v` and the quaternion `q`. `Quaternion operator -(const Quaternion& q, float s);` Returns the difference of the quaternion `q` and the scalar `s`. `Quaternion operator -(float s, const Quaternion& q);` Returns the difference of the scalar `s` and the quaternion `q`. `Quaternion operator *(const Quaternion& q1, const Quaternion& q2);` Returns the product of the quaternions `q1` and `q2`. `Quaternion operator *(const Quaternion& q, const Vector3D& v);` Returns the product of the quaternion `q` and the vector `v`. `Quaternion operator *(const Vector3D& v, const Quaternion& q);` Returns the product of the vector `v` and the quaternion `q`. `Quaternion operator *(const Quaternion& q, float s);` Returns the product of the quaternion `q` and the scalar `s`. `Quaternion operator *(float s, const Quaternion& q);` Returns the product of the scalar `s` and the quaternion `q`. `Quaternion operator /(const Quaternion& q1, const Quaternion& q2);` Returns the quotient of the quaternions `q1` and `q2`. `Quaternion operator /(const Quaternion& q, const Vector3D& v);` Returns the quotient of the quaternion `q` and of the vector `v`. `Quaternion operator /(const Vector3D& v, const Quaternion& q);` Returns the quotient of the vector `v` and the quaternion `q`. `Quaternion operator /(const Quaternion& q, float s);` Returns the quotient of the quaternion `q` and the scalar `s`. `Quaternion operator /(float s, const Quaternion& q);` Returns the quotient of the scalar `s` and the quaternion `q`. `float Magnitude(const Quaternion& q);` Returns the magnitude of a quaternion. `float SquaredMag(const Quaternion& q);` Returns the squared magnitude of a quaternion. `Quaternion Reverse(const Quaternion& q);` Returns the reverse of a quaternion. `Quaternion Inverse(const Quaternion& q);` Returns the inverse of a quaternion. `Vector3D Transform(const Vector3D& v, const Quaternion& q);` Transforms the vector `v` with the quaternion `q`.
`Vector3D`
`Matrix3D`
`Motor3D`