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

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/matrix.h
r235 r237 17 17 #define __DH_MATRIX_H__ 18 18 19 template <typename T> struct Vector2 19 #define OPERATORS(elems) \ 20 inline Vec##elems<T> operator+(Vec##elems<T> const &op) const \ 21 { \ 22 Vec##elems<T> ret; \ 23 for (int n = 0; n < elems; n++) \ 24 ret[n] = (*this)[n] + op[n]; \ 25 return ret; \ 26 } \ 27 \ 28 inline Vec##elems<T> operator(Vec##elems<T> const &op) const \ 29 { \ 30 Vec##elems<T> ret; \ 31 for (int n = 0; n < elems; n++) \ 32 ret[n] = (*this)[n]  op[n]; \ 33 return ret; \ 34 } 35 36 template <typename T> struct Vec2 20 37 { 21 Vec tor2() { x = y = 0; }22 Vec tor2(T _x, T _y) { x = _x; y = _y; }38 Vec2() { x = y = 0; } 39 Vec2(T _x, T _y) { x = _x; y = _y; } 23 40 T& operator[](int n) { return *(&x + n); } 41 T const& operator[](int n) const { return *(&x + n); } 42 43 OPERATORS(2) 24 44 25 45 union { T x; T a; T i; }; … … 27 47 }; 28 48 29 typedef Vec tor2<float> Float2;30 typedef Vec tor2<int> Int2;49 typedef Vec2<float> Float2; 50 typedef Vec2<int> Int2; 31 51 32 template <typename T> struct Vec tor352 template <typename T> struct Vec3 33 53 { 34 Vec tor3() { x = y = z = 0; }35 Vec tor3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; }54 Vec3() { x = y = z = 0; } 55 Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } 36 56 T& operator[](int n) { return *(&x + n); } 57 58 OPERATORS(3) 37 59 38 60 union { T x; T a; T i; }; … … 41 63 }; 42 64 43 typedef Vec tor3<float> Float3;44 typedef Vec tor3<int> Int3;65 typedef Vec3<float> Float3; 66 typedef Vec3<int> Int3; 45 67 46 68 #endif // __DH_MATRIX_H__
Note: See TracChangeset
for help on using the changeset viewer.