Changeset 1148
- Timestamp:
- Feb 25, 2012, 9:20:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lol/math/vector.h
r1146 r1148 23 23 #endif 24 24 25 #include "half.h" 26 #include "lol/math/real.h" 27 25 28 namespace lol 26 29 { 27 28 class half;29 class real;30 30 31 31 #define DECLARE_VECTOR_TYPEDEFS(tname, suffix) \ … … 41 41 typedef tname<uint32_t> u##suffix; \ 42 42 typedef tname<int64_t> i64##suffix; \ 43 typedef tname<uint64_t> u64##suffix; 43 typedef tname<uint64_t> u64##suffix; \ 44 typedef tname<real> r##suffix; \ 44 45 45 46 DECLARE_VECTOR_TYPEDEFS(Vec2, vec2) … … 91 92 92 93 #define DECLARE_MEMBER_OPS(tname) \ 93 inline T& operator[](int n) { return *(& x + n); } \94 inline T const& operator[](int n) const { return *(& x + n); } \94 inline T& operator[](int n) { return *(&this->x + n); } \ 95 inline T const& operator[](int n) const { return *(&this->x + n); } \ 95 96 \ 96 97 void printf() const; \ … … 109 110 */ 110 111 111 template <typename T> struct Vec2 112 { 113 inline Vec2() {} 114 inline Vec2(T X, T Y) : x(X), y(Y) {} 115 116 explicit inline Vec2(T X) : x(X), y(X) {} 117 118 template<int N> 119 inline Vec2(XVec2<T, N> const &v) 120 : x(v.ptr[v.I]), y(v.ptr[v.J]) {} 121 122 template<typename U, int N> 123 explicit inline Vec2(XVec2<U, N> const &v) 124 : x(v.ptr[v.I]), y(v.ptr[v.J]) {} 125 126 DECLARE_MEMBER_OPS(Vec2) 127 128 #if !defined __ANDROID__ 129 template<typename U> 130 friend std::ostream &operator<<(std::ostream &stream, Vec2<U> const &v); 131 #endif 112 template <typename T> struct BVec2 113 { 114 explicit inline BVec2() {} 115 explicit inline BVec2(T X, T Y) : x(X), y(Y) {} 132 116 133 117 union … … 170 154 }; 171 155 156 template <> struct BVec2<half> 157 { 158 explicit inline BVec2() {} 159 explicit inline BVec2(half X, half Y) : x(X), y(Y) {} 160 161 half x, y; 162 }; 163 164 template <> struct BVec2<real> 165 { 166 explicit inline BVec2() {} 167 explicit inline BVec2(real X, real Y) : x(X), y(Y) {} 168 169 real x, y; 170 }; 171 172 template <typename T> struct Vec2 : BVec2<T> 173 { 174 inline Vec2() {} 175 inline Vec2(T X, T Y) : BVec2<T>(X, Y) {} 176 177 explicit inline Vec2(T X) : BVec2<T>(X, X) {} 178 179 template<int N> 180 inline Vec2(XVec2<T, N> const &v) 181 : BVec2<T>(v.ptr[v.I], v.ptr[v.J]) {} 182 183 template<typename U, int N> 184 explicit inline Vec2(XVec2<U, N> const &v) 185 : BVec2<T>(v.ptr[v.I], v.ptr[v.J]) {} 186 187 DECLARE_MEMBER_OPS(Vec2) 188 189 #if !defined __ANDROID__ 190 template<typename U> 191 friend std::ostream &operator<<(std::ostream &stream, Vec2<U> const &v); 192 #endif 193 }; 194 172 195 /* 173 196 * 2-element complexes … … 246 269 */ 247 270 248 template <typename T> struct Vec3 249 { 250 inline Vec3() {} 251 inline Vec3(T X, T Y, T Z) : x(X), y(Y), z(Z) {} 252 inline Vec3(Vec2<T> XY, T Z) : x(XY.x), y(XY.y), z(Z) {} 253 inline Vec3(T X, Vec2<T> YZ) : x(X), y(YZ.x), z(YZ.y) {} 254 255 explicit inline Vec3(T X) : x(X), y(X), z(X) {} 256 257 template<int N> 258 inline Vec3(XVec3<T, N> const &v) 259 : x(v.ptr[v.I]), y(v.ptr[v.J]), z(v.ptr[v.K]) {} 260 261 template<typename U, int N> 262 explicit inline Vec3(XVec3<U, N> const &v) 263 : x(v.ptr[v.I]), y(v.ptr[v.J]), z(v.ptr[v.K]) {} 264 265 DECLARE_MEMBER_OPS(Vec3) 266 267 template<typename U> 268 friend Vec3<U> cross(Vec3<U>, Vec3<U>); 269 270 #if !defined __ANDROID__ 271 template<typename U> 272 friend std::ostream &operator<<(std::ostream &stream, Vec3<U> const &v); 273 #endif 271 template <typename T> struct BVec3 272 { 273 explicit inline BVec3() {} 274 explicit inline BVec3(T X, T Y, T Z) : x(X), y(Y), z(Z) {} 274 275 275 276 union … … 401 402 }; 402 403 404 template <> struct BVec3<half> 405 { 406 explicit inline BVec3() {} 407 explicit inline BVec3(half X, half Y, half Z) : x(X), y(Y), z(Z) {} 408 409 half x, y, z; 410 }; 411 412 template <> struct BVec3<real> 413 { 414 explicit inline BVec3() {} 415 explicit inline BVec3(real X, real Y, real Z) : x(X), y(Y), z(Z) {} 416 417 real x, y, z; 418 }; 419 420 template <typename T> struct Vec3 : BVec3<T> 421 { 422 inline Vec3() {} 423 inline Vec3(T X, T Y, T Z) : BVec3<T>(X, Y, Z) {} 424 inline Vec3(Vec2<T> XY, T Z) : BVec3<T>(XY.x, XY.y, Z) {} 425 inline Vec3(T X, Vec2<T> YZ) : BVec3<T>(X, YZ.x, YZ.y) {} 426 427 explicit inline Vec3(T X) : BVec3<T>(X, X, X) {} 428 429 template<int N> 430 inline Vec3(XVec3<T, N> const &v) 431 : BVec3<T>(v.ptr[v.I], v.ptr[v.J], v.ptr[v.K]) {} 432 433 template<typename U, int N> 434 explicit inline Vec3(XVec3<U, N> const &v) 435 : BVec3<T>(v.ptr[v.I], v.ptr[v.J], v.ptr[v.K]) {} 436 437 DECLARE_MEMBER_OPS(Vec3) 438 439 template<typename U> 440 friend Vec3<U> cross(Vec3<U>, Vec3<U>); 441 442 #if !defined __ANDROID__ 443 template<typename U> 444 friend std::ostream &operator<<(std::ostream &stream, Vec3<U> const &v); 445 #endif 446 }; 447 403 448 /* 404 449 * 4-element vectors 405 450 */ 406 451 407 template <typename T> struct Vec4 408 { 409 inline Vec4() {} 410 inline Vec4(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {} 411 inline Vec4(Vec2<T> XY, T Z, T W) : x(XY.x), y(XY.y), z(Z), w(W) {} 412 inline Vec4(T X, Vec2<T> YZ, T W) : x(X), y(YZ.x), z(YZ.y), w(W) {} 413 inline Vec4(T X, T Y, Vec2<T> ZW) : x(X), y(Y), z(ZW.x), w(ZW.y) {} 414 inline Vec4(Vec2<T> XY, Vec2<T> ZW) : x(XY.x), y(XY.y), z(ZW.x), w(ZW.y) {} 415 inline Vec4(Vec3<T> XYZ, T W) : x(XYZ.x), y(XYZ.y), z(XYZ.z), w(W) {} 416 inline Vec4(T X, Vec3<T> YZW) : x(X), y(YZW.x), z(YZW.y), w(YZW.z) {} 417 418 explicit inline Vec4(T X) : x(X), y(X), z(X), w(X) {} 419 420 template<int N> 421 inline Vec4(XVec4<T, N> const &v) 422 : x(v.ptr[v.I]), y(v.ptr[v.J]), z(v.ptr[v.K]), w(v.ptr[v.L]) {} 423 424 template<typename U, int N> 425 explicit inline Vec4(XVec4<U, N> const &v) 426 : x(v.ptr[v.I]), y(v.ptr[v.J]), z(v.ptr[v.K]), w(v.ptr[v.L]) {} 427 428 DECLARE_MEMBER_OPS(Vec4) 429 430 #if !defined __ANDROID__ 431 template<typename U> 432 friend std::ostream &operator<<(std::ostream &stream, Vec4<U> const &v); 433 #endif 452 template <typename T> struct BVec4 453 { 454 explicit inline BVec4() {} 455 explicit inline BVec4(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {} 434 456 435 457 union … … 780 802 }; 781 803 804 template <> struct BVec4<half> 805 { 806 explicit inline BVec4() {} 807 explicit inline BVec4(half X, half Y, half Z, half W) 808 : x(X), y(Y), z(Z), w(W) {} 809 810 half x, y, z, w; 811 }; 812 813 template <> struct BVec4<real> 814 { 815 explicit inline BVec4() {} 816 explicit inline BVec4(real X, real Y, real Z, real W) 817 : x(X), y(Y), z(Z), w(W) {} 818 819 real x, y, z, w; 820 }; 821 822 template <typename T> struct Vec4 : BVec4<T> 823 { 824 inline Vec4() {} 825 inline Vec4(T X, T Y, T Z, T W) : BVec4<T>(X, Y, Z, W) {} 826 inline Vec4(Vec2<T> XY, T Z, T W) : BVec4<T>(XY.x, XY.y, Z, W) {} 827 inline Vec4(T X, Vec2<T> YZ, T W) : BVec4<T>(X, YZ.x, YZ.y, W) {} 828 inline Vec4(T X, T Y, Vec2<T> ZW) : BVec4<T>(X, Y, ZW.x, ZW.y) {} 829 inline Vec4(Vec2<T> XY, Vec2<T> ZW) : BVec4<T>(XY.x, XY.y, ZW.x, ZW.y) {} 830 inline Vec4(Vec3<T> XYZ, T W) : BVec4<T>(XYZ.x, XYZ.y, XYZ.z, W) {} 831 inline Vec4(T X, Vec3<T> YZW) : BVec4<T>(X, YZW.x, YZW.y, YZW.z) {} 832 833 explicit inline Vec4(T X) : BVec4<T>(X, X, X, X) {} 834 835 template<int N> 836 inline Vec4(XVec4<T, N> const &v) 837 : BVec4<T>(v.ptr[v.I], v.ptr[v.J], v.ptr[v.K], v.ptr[v.L]) {} 838 839 template<typename U, int N> 840 explicit inline Vec4(XVec4<U, N> const &v) 841 : BVec4<T>(v.ptr[v.I], v.ptr[v.J], v.ptr[v.K], v.ptr[v.L]) {} 842 843 DECLARE_MEMBER_OPS(Vec4) 844 845 #if !defined __ANDROID__ 846 template<typename U> 847 friend std::ostream &operator<<(std::ostream &stream, Vec4<U> const &v); 848 #endif 849 }; 850 782 851 /* 783 852 * 4-element quaternions
Note: See TracChangeset
for help on using the changeset viewer.