# Changeset 240Tweet

Ignore:
Timestamp:
Jan 19, 2011, 9:33:51 PM (10 years ago)
Message:

Various vector operators including casts and scalar-vector operations.

File:
1 edited

Unmodified
Removed
• ## trunk/src/matrix.h

 r239 #define VECTOR_OP(elems, op) \ inline Vec##elems operator op(Vec##elems const &val) const \ template \ inline Vec##elems operator op(Vec##elems const &val) const \ { \ Vec##elems ret; \ #define OPERATORS(elems) \ T& operator[](int n) { return *(&x + n); } \ T const& operator[](int n) const { return *(&x + n); } \ inline T& operator[](int n) { return *(&x + n); } \ inline T const& operator[](int n) const { return *(&x + n); } \ \ VECTOR_OP(elems, -) \ SCALAR_OP(elems, /) \ \ template \ inline operator Vec##elems() const \ { \ Vec##elems ret; \ for (int n = 0; n < elems; n++) \ ret[n] = static_cast((*this)[n]); \ return ret; \ } \ \ inline float len() const \ { \ template struct Vec2 { Vec2() { x = y = 0; } Vec2(T _x, T _y) { x = _x; y = _y; } inline Vec2() { x = y = 0; } inline Vec2(T val) { x = y = val; } inline Vec2(T _x, T _y) { x = _x; y = _y; } OPERATORS(2) template struct Vec3 { Vec3() { x = y = z = 0; } Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } inline Vec3() { x = y = z = 0; } inline Vec3(T val) { x = y = z = val; } inline Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } OPERATORS(3) typedef Vec3 Int3; #define SCALAR_GLOBAL(elems, op, U) \ template \ static inline Vec##elems operator op(U const &val, \ Vec##elems const &that) \ { \ Vec##elems ret; \ for (int n = 0; n < elems; n++) \ ret[n] = val op that[n]; \ return ret; \ } #define SCALAR_GLOBAL2(elems, op) \ SCALAR_GLOBAL(elems, op, int) \ SCALAR_GLOBAL(elems, op, float) #define GLOBALS(elems) \ SCALAR_GLOBAL2(elems, -) \ SCALAR_GLOBAL2(elems, +) \ SCALAR_GLOBAL2(elems, *) \ SCALAR_GLOBAL2(elems, /) GLOBALS(2) GLOBALS(3) #endif // __DH_MATRIX_H__
Note: See TracChangeset for help on using the changeset viewer.