Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------------------------------------
- // 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
- Vector4() {}
- // Constructor; 2D Vector promotion with explicite z and w
- 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
- 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
- Vector4(T x, T y, Vector2<T> &v) : x(x), y(y), z(v.x), w(v.y) {}
- // Constructor; Two 2D Vectors merging
- 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
- Vector4(Vector3<T> &v, T w) : x(v.x), y(v.y), z(v.z), w(w) {}
- // Constructor; 3D Vector promotion with explicite x
- Vector4(T x, Vector3<T> &v) : x(x), y(v.x), z(v.y), w(v.z) {}
- // Constructor; Directly initialize each value
- 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 convertion to 32-bit floating-point components
- operator Vector4<Float>() const { return Vector4<Float>(x, y, z, w); };
- };
Advertisement
Add Comment
Please, Sign In to add comment