Changeset 240
 Timestamp:
 Jan 19, 2011, 9:33:51 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/matrix.h
r239 r240 20 20 21 21 #define VECTOR_OP(elems, op) \ 22 inline Vec##elems<T> operator op(Vec##elems<T> const &val) const \ 22 template<typename U> \ 23 inline Vec##elems<T> operator op(Vec##elems<U> const &val) const \ 23 24 { \ 24 25 Vec##elems<T> ret; \ … … 38 39 39 40 #define OPERATORS(elems) \ 40 T& operator[](int n) { return *(&x + n); } \41 T const& operator[](int n) const { return *(&x + n); } \41 inline T& operator[](int n) { return *(&x + n); } \ 42 inline T const& operator[](int n) const { return *(&x + n); } \ 42 43 \ 43 44 VECTOR_OP(elems, ) \ … … 51 52 SCALAR_OP(elems, /) \ 52 53 \ 54 template<typename U> \ 55 inline operator Vec##elems<U>() const \ 56 { \ 57 Vec##elems<U> ret; \ 58 for (int n = 0; n < elems; n++) \ 59 ret[n] = static_cast<U>((*this)[n]); \ 60 return ret; \ 61 } \ 62 \ 53 63 inline float len() const \ 54 64 { \ … … 61 71 template <typename T> struct Vec2 62 72 { 63 Vec2() { x = y = 0; } 64 Vec2(T _x, T _y) { x = _x; y = _y; } 73 inline Vec2() { x = y = 0; } 74 inline Vec2(T val) { x = y = val; } 75 inline Vec2(T _x, T _y) { x = _x; y = _y; } 65 76 66 77 OPERATORS(2) … … 75 86 template <typename T> struct Vec3 76 87 { 77 Vec3() { x = y = z = 0; } 78 Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } 88 inline Vec3() { x = y = z = 0; } 89 inline Vec3(T val) { x = y = z = val; } 90 inline Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } 79 91 80 92 OPERATORS(3) … … 88 100 typedef Vec3<int> Int3; 89 101 102 #define SCALAR_GLOBAL(elems, op, U) \ 103 template<typename T> \ 104 static inline Vec##elems<U> operator op(U const &val, \ 105 Vec##elems<T> const &that) \ 106 { \ 107 Vec##elems<U> ret; \ 108 for (int n = 0; n < elems; n++) \ 109 ret[n] = val op that[n]; \ 110 return ret; \ 111 } 112 113 #define SCALAR_GLOBAL2(elems, op) \ 114 SCALAR_GLOBAL(elems, op, int) \ 115 SCALAR_GLOBAL(elems, op, float) 116 117 #define GLOBALS(elems) \ 118 SCALAR_GLOBAL2(elems, ) \ 119 SCALAR_GLOBAL2(elems, +) \ 120 SCALAR_GLOBAL2(elems, *) \ 121 SCALAR_GLOBAL2(elems, /) 122 123 GLOBALS(2) 124 GLOBALS(3) 125 90 126 #endif // __DH_MATRIX_H__ 91 127
Note: See TracChangeset
for help on using the changeset viewer.