This template represents 4D vector.
You can find more information in comments below.
template<class TYPE>
union TVec4
{
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;
};
struct // As elements
{
TYPE _1;
TYPE _2;
TYPE _3;
TYPE _4;
};
TYPE Data[4]; // Array of elements
TMatrix<TYPE, 1, 4> M; // As matrix
TYPE operator[](const size_t index) const; // Return element by index. Only 0, 1, 2 and 3 are accepted as indices. Used only when TVec4 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
explicit operator TQuaternion<TYPE>() const; // Convert to TQuaternion
};
Additionally following operators exists.
template<class TYPE>
bool operator==(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Check whether vectors are equal. Can be used for non-float data types only
template<class TYPE>
bool operator!=(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Check whether vectors aren't equal. Can be used for non-float data types only
template<class TYPE>
TVec4<TYPE> operator+(const TVec4<TYPE> &v, const TYPE val); // Add vector and scalar
template<class TYPE>
TVec4<TYPE> operator-(const TVec4<TYPE> &v, const TYPE val); // Subtract vector and scalar
template<class TYPE>
TVec4<TYPE> operator*(const TVec4<TYPE> &v, const TYPE val); // Multiply vector and scalar
template<class TYPE>
TVec4<TYPE> operator/(const TVec4<TYPE> &v, const TYPE val); // Divide vector and scalar
template<class TYPE>
TVec4<TYPE> operator+(const TYPE val, const TVec4<TYPE> &v); // Add scalar and vector
template<class TYPE>
TVec4<TYPE> operator-(const TYPE val, const TVec4<TYPE> &v); // Subtract scalar and vector
template<class TYPE>
TVec4<TYPE> operator*(const TYPE val, const TVec4<TYPE> &v); // Multiply scalar and vector
template<class TYPE>
TVec4<TYPE> operator/(const TYPE val, const TVec4<TYPE> &v); // Divide scalar and vector
template<class TYPE>
TVec4<TYPE> &operator+=(TVec4<TYPE> &v, const TYPE val); // Add scalar to vector
template<class TYPE>
TVec4<TYPE> &operator-=(TVec4<TYPE> &v, const TYPE val); // Subtract scalar from vector
template<class TYPE>
TVec4<TYPE> &operator*=(TVec4<TYPE> &v, const TYPE val); // Multiply vector by scalar
template<class TYPE>
TVec4<TYPE> &operator/=(TVec4<TYPE> &v, const TYPE val); // Divide vector by scalar
template<class TYPE>
TVec4<TYPE> operator+(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Add vectors
template<class TYPE>
TVec4<TYPE> operator-(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Subtract vectors
template<class TYPE>
TYPE operator*(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Multiply vectors(dot product)
template<class TYPE>
TVec4<TYPE> operator/(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Divide vectors
template<class TYPE>
TVec4<TYPE> operator^(const TVec4<TYPE> &a, const TVec4<TYPE> &b); // Multiply vectors(cross product)
template<class TYPE>
TVec4<TYPE> &operator+=(TVec4<TYPE> &a, const TVec4<TYPE> &b); // Add vector to vector
template<class TYPE>
TVec4<TYPE> &operator-=(TVec4<TYPE> &a, const TVec4<TYPE> &b); // Subtract vector from vector
template<class TYPE>
TVec4<TYPE> &operator/=(TVec4<TYPE> &a, const TVec4<TYPE> &b); // Divide vector by vector
template<class TYPE>
TVec4<TYPE> &operator^=(TVec4<TYPE> &a, const TVec4<TYPE> &b); // Store cross product in the first vector
template<class TYPE>
TVec4<TYPE> operator-(const TVec4<TYPE> &v); // Return inversed vector
Also there are some functions which can be used with TVec4 template. Here they are.
Namespace: | ntl |
Include: | NTL/Core/Vec4.h |