# Changeset 237 for trunk/src/matrix.hTweet

Ignore:
Timestamp:
Jan 19, 2011, 9:33:13 PM (11 years ago)
Message:

Implement simple + and - operators for Int2, Float2 etc.

File:
1 edited

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

 r235 #define __DH_MATRIX_H__ template struct Vector2 #define OPERATORS(elems) \ inline Vec##elems operator+(Vec##elems const &op) const \ { \ Vec##elems ret; \ for (int n = 0; n < elems; n++) \ ret[n] = (*this)[n] + op[n]; \ return ret; \ } \ \ inline Vec##elems operator-(Vec##elems const &op) const \ { \ Vec##elems ret; \ for (int n = 0; n < elems; n++) \ ret[n] = (*this)[n] - op[n]; \ return ret; \ } template struct Vec2 { Vector2() { x = y = 0; } Vector2(T _x, T _y) { x = _x; y = _y; } Vec2() { x = y = 0; } Vec2(T _x, T _y) { x = _x; y = _y; } T& operator[](int n) { return *(&x + n); } T const& operator[](int n) const { return *(&x + n); } OPERATORS(2) union { T x; T a; T i; }; }; typedef Vector2 Float2; typedef Vector2 Int2; typedef Vec2 Float2; typedef Vec2 Int2; template struct Vector3 template struct Vec3 { Vector3() { x = y = z = 0; } Vector3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } Vec3() { x = y = z = 0; } Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; } T& operator[](int n) { return *(&x + n); } OPERATORS(3) union { T x; T a; T i; }; }; typedef Vector3 Float3; typedef Vector3 Int3; typedef Vec3 Float3; typedef Vec3 Int3; #endif // __DH_MATRIX_H__
Note: See TracChangeset for help on using the changeset viewer.