MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / vec4

Class vec4

jni/venus/vec4.h:14–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 */
13template <typename T>
14class vec4
15{
16public:
17// https://msdn.microsoft.com/en-us/library/2c8f766e.aspx
18#ifdef _WIN32
19# pragma warning(push)
20# pragma warning(disable: 4201) // warning C4201: nonstandard extension used: nameless struct/union
21#endif
22
23 union
24 {
25 T _data[4];
26 struct {T x, y, z, w;}; // 4D homogeneous coordinate
27 struct {T r, g, b, a;}; // color
28 struct {T s, t, p, q;}; // texture
29 };
30
31#ifdef _WIN32
32# pragma warning(pop)
33#endif
34
35 typedef T value_type;
36
37public:
38 vec4() = default;
39 ~vec4() = default;
40
41 explicit vec4(const T *array): x(array[0]), y(array[1]), z(array[2]), w(array[3]) { }
42 explicit vec4(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) { }
43 vec4(T x, T y, T z, T w): x(x), y(y), z(z), w(w) { }
44
45 vec4(const vec4<T>& v): x(v.x), y(v.y), z(v.z), w(v.w) { }
46 vec4<T>& operator =(const vec4<T>& rhs)
47 {
48 if(this != &rhs)
49 {
50 x = rhs.x;
51 y = rhs.y;
52 z = rhs.z;
53 w = rhs.w;
54 }
55 return *this;
56 }
57
58 T& operator[] (std::size_t i) { return _data[i]; }
59 const T& operator[] (std::size_t i) const { return _data[i]; }
60
61 // assignment operators
62 vec4<T>& operator +=(const vec4<T>& rhs) { x += rhs.x; y += rhs.y; z += rhs.z; w += rhs.w; return *this; }
63 vec4<T>& operator -=(const vec4<T>& rhs) { x -= rhs.x; y -= rhs.y; z -= rhs.z; w -= rhs.w; return *this; }
64 vec4<T>& operator *=(T value) { x *= value; y *= value; z *= value; w *= value; return *this; }
65 vec4<T>& operator /=(T value) { x /= value; y /= value; z /= value; w /= value; return *this; }
66
67 // unary operators
68 vec4<T> operator +() const { return vec4<T>(+x, +y, +z, +w); }
69 vec4<T> operator -() const { return vec4<T>(-x, -y, -z, -w); }
70
71 // binary operators, multiply and divide operations for scalar

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected