diff --git a/src/input.cpp b/src/input.cpp index 1f2a40dc..25d4a5a0 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -57,10 +57,7 @@ float2 Input::GetAxis(int axis) f.x += left; f.y += up; if (left && up) - { - f.x *= invsqrt2; - f.y *= invsqrt2; - } + f = f * invsqrt2; return f; } diff --git a/src/matrix.h b/src/matrix.h index 0e0c91de..b5128930 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -46,6 +46,15 @@ return ret; \ } +#define CAST_OP(elems, dest) \ + inline operator Vec##dest() const \ + { \ + Vec##dest ret; \ + for (int n = 0; n < elems && n < dest; n++) \ + ret[n] = (*this)[n]; \ + return ret; \ + } + #define OPERATORS(elems) \ inline T& operator[](int n) { return *(&x + n); } \ inline T const& operator[](int n) const { return *(&x + n); } \ @@ -63,6 +72,10 @@ SCALAR_OP(elems, *) \ SCALAR_OP(elems, /) \ \ + CAST_OP(elems, 2) \ + CAST_OP(elems, 3) \ + CAST_OP(elems, 4) \ + \ template \ inline operator Vec##elems() const \ { \ @@ -85,6 +98,10 @@ return sqrtf((float)sqlen()); \ } +template struct Vec2; +template struct Vec3; +template struct Vec4; + template struct Vec2 { inline Vec2() { x = y = 0; }