This template represents quaternion.
You can find more information in comments below.
template<class TYPE>
union TQuaternion
{
struct // As coordinates
{
union
{
struct
{
union
{
struct
{
union
{
TYPE X;
TVec1<TYPE> V1;
};
TYPE Y;
};
TVec2<TYPE> V2;
};
TYPE Z;
};
TVec3<TYPE> V3;
};
TYPE W;
};
TYPE Data[4]; // Array of elements
TMatrix<TYPE, 1, 4> M; // As matrix
TVec4<TYPE> V4; // As TVec4
TQuaternion() = default;
TQuaternion(const TQuaternion &other) = default;
TQuaternion(TQuaternion &&other) = default;
TQuaternion(const TYPE x, const TYPE y, const TYPE z, const TYPE w); // Create with specified coordinates
TQuaternion(const TQuaternion &axis, const TYPE angle); // Create rotatation quaternion around specified axis by specified angle(in radians)
TQuaternion &operator=(const TQuaternion &other) = default;
TQuaternion &operator=(TQuaternion &&other) = default;
TYPE operator[](const size_t index) const; // Return element by index. Only 0, 1, 2 and 3 are accepted as indices. Used only when TQuaternion object is a constant object
TYPE &operator[](const size_t index); // Return element by index. Only 0, 1, 2 and 3 are accepted as indices
explicit operator TPoint<TYPE>() const; // Convert to TPoint
explicit operator TRect<TYPE>() const; // Convert to TRect
};
Additionally following operators exists.
template<class TYPE>
bool operator==(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Check whether quaternions are equal. Can be used for non-float data types only
template<class TYPE>
bool operator!=(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Check whether quaternions aren't equal. Can be used for non-float data types only
template<class TYPE>
TQuaternion<TYPE> operator+(const TQuaternion<TYPE> &q, const TYPE val); // Add quaternion and scalar
template<class TYPE>
TQuaternion<TYPE> operator-(const TQuaternion<TYPE> &q, const TYPE val); // Subtract quaternion and scalar
template<class TYPE>
TQuaternion<TYPE> operator*(const TQuaternion<TYPE> &q, const TYPE val); // Multiply quaternion and scalar
template<class TYPE>
TQuaternion<TYPE> operator/(const TQuaternion<TYPE> &q, const TYPE val); // Divide quaternion and scalar
template<class TYPE>
TQuaternion<TYPE> operator+(const TYPE val, const TQuaternion<TYPE> &q); // Add scalar and quaternion
template<class TYPE>
TQuaternion<TYPE> operator-(const TYPE val, const TQuaternion<TYPE> &q); // Subtract scalar and quaternion
template<class TYPE>
TQuaternion<TYPE> operator*(const TYPE val, const TQuaternion<TYPE> &q); // Multiply scalar and quaternion
template<class TYPE>
TQuaternion<TYPE> operator/(const TYPE val, const TQuaternion<TYPE> &q); // Divide scalar and quaternion
template<class TYPE>
TQuaternion<TYPE> &operator+=(TQuaternion<TYPE> &q, const TYPE val); // Add scalar to quaternion
template<class TYPE>
TQuaternion<TYPE> &operator-=(TQuaternion<TYPE> &q, const TYPE val); // Subtract scalar form quaternion
template<class TYPE>
TQuaternion<TYPE> &operator*=(TQuaternion<TYPE> &q, const TYPE val); // Multiply quaternion by scalar
template<class TYPE>
TQuaternion<TYPE> &operator/=(TQuaternion<TYPE> &q, const TYPE val); // Divide quaternion by scalar
template<class TYPE>
TQuaternion<TYPE> operator+(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Add quaternions
template<class TYPE>
TQuaternion<TYPE> operator-(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Subtract quaternions
template<class TYPE>
TYPE operator*(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Multiply quaternions(dot product)
template<class TYPE>
TQuaternion<TYPE> operator^(const TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Multiply quaternions(cross product)
template<class TYPE>
TQuaternion<TYPE> &operator+=(TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Add second quaternion to the first one
template<class TYPE>
TQuaternion<TYPE> &operator-=(TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Subtract second quaternion from the first one
template<class TYPE>
TQuaternion<TYPE> &operator^=(TQuaternion<TYPE> &a, const TQuaternion<TYPE> &b); // Store cross product of quaternions in the first one
template<class TYPE>
TQuaternion<TYPE> operator-(const TQuaternion<TYPE> &v); // Return quaternion with elements having same value but inversed sign
Also there are some functions which can be used with TQuaternion template. Here they are.
Namespace: | ntl |
Include: | NTL/Core/Quaternion.h |