From 502deb759762ab1eac511955cd7e1064569f1dba Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 26 Jan 2011 16:48:40 +0000 Subject: [PATCH] Fix a few warnings here and there, and try to use the vector classes. --- src/input.cpp | 5 +---- src/matrix.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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; }