Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------------------------------------
- // 2D Vector; Templated components
- template <typename T> struct Vector2
- {
- // Members
- union
- {
- // A single component of the
- struct { T x, y; };
- };
- // Constructor; Empty initalization
- explicit Vector2() {}
- // Constructor; Directly initialize each value
- explicit Vector2(T x, T y) : x(x), y(y) {}
- // Constructor; Initialize values from an array
- explicit Vector2(In(2) const T* array) : x(array[0]), y(array[1]) {}
- // Vector assignment
- Vector2<T>& operator = (const Vector2<T> &other) { x = other.x; y = other.y; return *this; }
- };
- //-------------------------------------------------------------------------------------
- // 3D Vector; Templated components
- template <typename T> struct Vector3
- {
- // Members
- union
- {
- // Swizzle; Lower two values of the vector
- struct { T x; Vector2<T> yz; };
- // Swizzle; Upper two values of the vector
- struct { Vector2<T> xy; T z; };
- // A single component of the vector
- struct { T x, y, z; };
- };
- //--------------------------------------------------------------------------------
- // Constructor; Empty initialization
- explicit Vector3() {}
- // Constructor; 2D Vector promotion with explicite z
- explicit Vector3(Vector2<T> &v, T z) : x(v.x), y(v.y), z(z) {}
- // Constructor; 2D Vector promotion with explicite x
- explicit Vector3(T x, Vector2<T> &v) : x(x), y(v.x), z(v.y) {}
- // Constructor; Directly initialize each value
- explicit Vector3(T x, T y, T z) : x(x), y(y), z(z) {}
- // Constructor; Initialize values from an array
- explicit Vector3(In(3) const T *array) : x(array[0]), y(array[1]), z(array[2]) {}
- // Vector assignment
- Vector3<T>& operator = (const Vector3<T> &other) { x = other.x; y = other.y; z = other.z; return *this; }
- };
- //-------------------------------------------------------------------------------------
- // 4D Vector; Templated components
- template <typename T> struct Vector4
- {
- // Members
- union
- {
- // Swizzle; Lower three values of the vector
- struct { T x; Vector3<T>ywz; };
- // Swizzle; Upper three values of the vector
- struct { Vector3<T> xyz; T w; };
- // Swizzle; Middle two values of the vector
- struct { T x; Vector2<T> yz; T w; };
- // Swizzle; Upper or Lower two values of the vector
- struct { Vector2<T> xy; Vector2<T> zw; };
- // A single component of the vector
- struct { T x, y, z, w; };
- };
- //--------------------------------------------------------------------------------
- // Constructor; Empty intialization
- explicit Vector4() {}
- // Constructor; 2D Vector promotion with explicite z and w
- explicit Vector4(Vector2<T> &v, T z, T w) : x(v.x), y(v.y), z(z), w(w) {}
- // Constructor; 2D Vector promotion with explicite x and w
- explicit Vector4(T x, Vector2<T> &v, T w) : x(x), y(v.x), z(v.y), w(w) {}
- // Constructor; 2D Vector promotion with explicite x and y
- explicit Vector4(T x, T y, Vector2<T> &v) : x(x), y(y), z(v.x), w(v.y) {}
- // Constructor; Two 2D Vectors merging
- explicit Vector4(Vector2<T> &v1, Vector2<T> &v2) : x(v1.x), y(v1.y), z(v2.x), w(v2.y) {}
- // Constructor; 3D Vector promotion with explicite w
- explicit Vector4(Vector3<T> &v, T w) : x(v.x), y(v.y), z(v.z), w(w) {}
- // Constructor; 3D Vector promotion with explicite x
- explicit Vector4(T x, Vector3<T> &v) : x(x), y(v.x), z(v.y), w(v.z) {}
- // Constructor; Directly initialize each value
- explicit Vector4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
- // Constructor; Initialize values from an array
- explicit Vector4(In(4) const T *array) : x(array[0]), y(array[1]), z(array[2]), w(array[3]) {}
- // Vector assignment
- Vector4<T>& operator = (const Vector4<T> &other) { x = other.x; y = other.y; z = other.z; w = other.w; return *this; }
- // Vector conversion to 32-bit floating-point components
- operator Vector4<Float>() const { return Vector4<Float>(x, y, z, w); };
- };
- //-------------------------------------------------------------------------------------
- // 2D Vector; 8-bit signed integer components
- typedef Vector2<Byte> Byte2;
- // 3D Vector; 8-bit signed integer components
- typedef Vector3<Byte> Byte3;
- // 4D Vector; 8-bit signed integer components
- typedef Vector4<Byte> Byte4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 8-bit unsigned integer components
- typedef Vector2<UByte> UByte2;
- // 3D Vector; 8-bit unsigned integer components
- typedef Vector3<UByte> UByte3;
- // 4D Vector; 8-bit unsigned integer components
- typedef Vector4<UByte> UByte4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 16-bit signed integer components
- typedef Vector2<Short> Short2;
- // 3D Vector; 16-bit signed integer components
- typedef Vector3<Short> Short3;
- // 4D Vector; 16-bit signed integer components
- typedef Vector4<Short> Short4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 16-bit unsigned integer components
- typedef Vector2<UShort> UShort2;
- // 3D Vector; 16-bit unsigned integer components
- typedef Vector3<UShort> UShort3;
- // 4D Vector; 16-bit unsigned integer components
- typedef Vector4<UShort> UShort4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 32-bit signed integer components
- typedef Vector2<Int> Int2;
- // 3D Vector; 32-bit signed integer components
- typedef Vector3<Int> Int3;
- // 4D Vector; 32-bit signed integer components
- typedef Vector4<Int> Int4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 32-bit unsigned integer components
- typedef Vector2<UInt> UInt2;
- // 3D Vector; 32-bit unsigned integer components
- typedef Vector3<UInt> UInt3;
- // 4D Vector; 32-bit unsigned integer components
- typedef Vector4<UInt> UInt4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 16-bit floating-point components
- typedef Vector2<Half> Half2;
- // 3D Vector; 16-bit floating-point components
- typedef Vector3<Half> Half3;
- // 4D Vector; 16-bit floating-point components
- typedef Vector4<Half> Half4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 32-bit floating-point components
- typedef Vector2<Float> Float2;
- // 3D Vector; 32-bit floating-point components
- typedef Vector3<Float> Float3;
- // 4D Vector; 32-bit floating-point components
- typedef Vector4<Float> Float4;
- //-------------------------------------------------------------------------------------
- // 2D Vector; 32-bit floating-point components aligned to a 16-byte boundary
- typedef Align(16) Vector2<Float> Float2A;
- // 3D Vector; 32-bit floating-point components aligned to a 16-byte boundary
- typedef Align(16) Vector3<Float> Float3A;
- // 4D Vector; 32-bit floating-point components aligned to a 16-byte boundary
- typedef Align(16) Vector4<Float> Float4A;
Advertisement
Add Comment
Please, Sign In to add comment