| 9 | |
| 10 | template <typename T> |
| 11 | class vec3 |
| 12 | { |
| 13 | public: |
| 14 | // https://msdn.microsoft.com/en-us/library/2c8f766e.aspx |
| 15 | #ifdef _WIN32 |
| 16 | # pragma warning(push) |
| 17 | # pragma warning(disable: 4201) // warning C4201: nonstandard extension used: nameless struct/union |
| 18 | #endif |
| 19 | |
| 20 | union |
| 21 | { |
| 22 | T _data[3]; |
| 23 | struct { T x, y, z; }; // vertex |
| 24 | struct { T r, g, b; }; // color |
| 25 | struct { T u, v, w; }; // texture |
| 26 | struct { T s, t, p; }; // texture |
| 27 | struct { T i, j, k; }; // index |
| 28 | struct { T start, step, stop; }; // arithmetic progression |
| 29 | struct { T pitch, roll, yaw; }; |
| 30 | struct { T rho, theta, phi; }; // polar coordinate |
| 31 | struct { T constant, linear, quadratic; }; // attenuation |
| 32 | }; |
| 33 | |
| 34 | #ifdef _WIN32 |
| 35 | # pragma warning(pop) |
| 36 | #endif |
| 37 | |
| 38 | typedef T value_type; |
| 39 | |
| 40 | public: |
| 41 | vec3() = default; |
| 42 | ~vec3() = default; |
| 43 | |
| 44 | explicit vec3(const T *array): x(array[0]), y(array[1]), z(array[2]) { } |
| 45 | explicit vec3(T scalar): x(scalar), y(scalar), z(scalar) { } |
| 46 | vec3(T x, T y, T z): x(x), y(y), z(z) { } |
| 47 | |
| 48 | vec3(const vec3<T>& v): x(v.x), y(v.y), z(v.z) { } |
| 49 | vec3<T>& operator =(const vec3<T>& rhs) |
| 50 | { |
| 51 | if(this != &rhs) |
| 52 | { |
| 53 | x = rhs.x; |
| 54 | y = rhs.y; |
| 55 | z = rhs.z; |
| 56 | } |
| 57 | return *this; |
| 58 | } |
| 59 | |
| 60 | vec3<T>& operator =(const vec3<T>&& rhs) |
| 61 | { |
| 62 | x = rhs.x; |
| 63 | y = rhs.y; |
| 64 | z = rhs.z; |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | T& operator[] (std::size_t i) { return _data[i]; } |
nothing calls this directly
no outgoing calls
no test coverage detected