From 03474adceb423f73ebce4feb0d81da15c41bda5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Wed, 19 Feb 2014 02:38:59 +0000 Subject: [PATCH] Added custom vector constants for more usefulness --- src/lol/math/vector.h | 77 +++++++++++++++++++++++++++++++-- src/math/constants.cpp | 98 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 154 insertions(+), 21 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 0937ef46..ac5ea0d3 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -251,11 +251,23 @@ template struct Vec2 : BVec2 LOL_MEMBER_OPS(Vec2, x) - static const Vec2 mone; + //Constants: n post-fix is negative values + static const Vec2 onen; static const Vec2 one; static const Vec2 zero; static const Vec2 axis_x; static const Vec2 axis_y; + static const Vec2 axis_xn; + static const Vec2 axis_yn; + //Pos values + static const Vec2 v11; + static const Vec2 v00; + static const Vec2 v01; + static const Vec2 v10; + //Neg values + static const Vec2 v00n; + static const Vec2 v01n; + static const Vec2 v10n; template friend std::ostream &operator<<(std::ostream &stream, Vec2 const &v); @@ -526,12 +538,33 @@ template struct Vec3 : BVec3 LOL_MEMBER_OPS(Vec3, x) - static const Vec3 mone; + //Constants: n post-fix is negative values + static const Vec3 onen; static const Vec3 one; static const Vec3 zero; static const Vec3 axis_x; static const Vec3 axis_y; static const Vec3 axis_z; + static const Vec3 axis_xn; + static const Vec3 axis_yn; + static const Vec3 axis_zn; + //Pos values + static const Vec3 v111; + static const Vec3 v000; + static const Vec3 v100; + static const Vec3 v010; + static const Vec3 v001; + static const Vec3 v110; + static const Vec3 v101; + static const Vec3 v011; + //Neg values + static const Vec3 v000n; + static const Vec3 v100n; + static const Vec3 v010n; + static const Vec3 v001n; + static const Vec3 v110n; + static const Vec3 v101n; + static const Vec3 v011n; template friend std::ostream &operator<<(std::ostream &stream, Vec3 const &v); @@ -950,13 +983,51 @@ template struct Vec4 : BVec4 LOL_MEMBER_OPS(Vec4, x) - static const Vec4 mone; + //Constants: n post-fix is negative values + static const Vec4 onen; static const Vec4 one; static const Vec4 zero; static const Vec4 axis_x; static const Vec4 axis_y; static const Vec4 axis_z; static const Vec4 axis_w; + static const Vec4 axis_xn; + static const Vec4 axis_yn; + static const Vec4 axis_zn; + static const Vec4 axis_wn; + //Pos values + static const Vec4 v1111; //( 1, 1, 1, 1) + static const Vec4 v0000; //( 0, 0, 0, 0) + static const Vec4 v1000; //( 1, 0, 0, 0) + static const Vec4 v0100; //( 0, 1, 0, 0) + static const Vec4 v0010; //( 0, 0, 1, 0) + static const Vec4 v0001; //( 0, 0, 0, 1) + static const Vec4 v1100; //( 1, 1, 0, 0) + static const Vec4 v0110; //( 0, 1, 1, 0) + static const Vec4 v0011; //( 0, 0, 1, 1) + static const Vec4 v1010; //( 1, 0, 1, 0) + static const Vec4 v0101; //( 0, 1, 0, 1) + static const Vec4 v1001; //( 1, 0, 0, 1) + static const Vec4 v0111; //( 0, 1, 1, 1) + static const Vec4 v1011; //( 1, 0, 1, 1) + static const Vec4 v1101; //( 1, 1, 0, 1) + static const Vec4 v1110; //( 1, 1, 1, 0) + //Neg values + static const Vec4 v0000n;//(-1,-1,-1,-1) + static const Vec4 v1000n;//( 1,-1,-1,-1) + static const Vec4 v0100n;//(-1, 1,-1,-1) + static const Vec4 v0010n;//(-1,-1, 1,-1) + static const Vec4 v0001n;//(-1,-1,-1, 1) + static const Vec4 v1100n;//( 1, 1,-1,-1) + static const Vec4 v0110n;//(-1, 1, 1,-1) + static const Vec4 v0011n;//(-1,-1, 1, 1) + static const Vec4 v1010n;//( 1,-1, 1,-1) + static const Vec4 v0101n;//(-1, 1,-1, 1) + static const Vec4 v1001n;//( 1,-1,-1, 1) + static const Vec4 v0111n;//(-1, 1, 1, 1) + static const Vec4 v1011n;//( 1,-1, 1, 1) + static const Vec4 v1101n;//( 1, 1,-1, 1) + static const Vec4 v1110n;//( 1, 1, 1,-1) template friend std::ostream &operator<<(std::ostream &stream, Vec4 const &v); diff --git a/src/math/constants.cpp b/src/math/constants.cpp index 80b847d6..aecdac0c 100644 --- a/src/math/constants.cpp +++ b/src/math/constants.cpp @@ -39,26 +39,88 @@ namespace lol { Mat4 const Mat4::name = Mat4((type)a); #define LOL_ALL_CONST_INNER(type) \ - LOL_VEC_2_CONST(type, one, 1, 1) \ - LOL_VEC_2_CONST(type, mone,-1,-1) \ - LOL_VEC_2_CONST(type, zero, 0, 0) \ - LOL_VEC_2_CONST(type, axis_x, 1, 0) \ - LOL_VEC_2_CONST(type, axis_y, 0, 1) \ + LOL_VEC_2_CONST(type, one, 1, 1) \ + LOL_VEC_2_CONST(type, onen, -1,-1) \ + LOL_VEC_2_CONST(type, zero, 0, 0) \ + LOL_VEC_2_CONST(type, axis_x, 1, 0) \ + LOL_VEC_2_CONST(type, axis_y, 0, 1) \ + LOL_VEC_2_CONST(type, axis_xn, 1,-1) \ + LOL_VEC_2_CONST(type, axis_yn, -1, 1) \ + LOL_VEC_2_CONST(type, v11, 1, 1) \ + LOL_VEC_2_CONST(type, v00, 0, 0) \ + LOL_VEC_2_CONST(type, v01, 0, 1) \ + LOL_VEC_2_CONST(type, v10, 1, 0) \ + LOL_VEC_2_CONST(type, v00n, -1,-1) \ + LOL_VEC_2_CONST(type, v01n, -1, 1) \ + LOL_VEC_2_CONST(type, v10n, 1,-1) \ \ - LOL_VEC_3_CONST(type, one, 1, 1, 1) \ - LOL_VEC_3_CONST(type, mone,-1,-1,-1) \ - LOL_VEC_3_CONST(type, zero, 0, 0, 0) \ - LOL_VEC_3_CONST(type, axis_x, 1, 0, 0) \ - LOL_VEC_3_CONST(type, axis_y, 0, 1, 0) \ - LOL_VEC_3_CONST(type, axis_z, 0, 0, 1) \ + LOL_VEC_3_CONST(type, one, 1, 1, 1) \ + LOL_VEC_3_CONST(type, onen, -1,-1,-1) \ + LOL_VEC_3_CONST(type, zero, 0, 0, 0) \ + LOL_VEC_3_CONST(type, axis_x, 1, 0, 0) \ + LOL_VEC_3_CONST(type, axis_y, 0, 1, 0) \ + LOL_VEC_3_CONST(type, axis_z, 0, 0, 1) \ + LOL_VEC_3_CONST(type, axis_xn, -1, 0, 0) \ + LOL_VEC_3_CONST(type, axis_yn, 0,-1, 0) \ + LOL_VEC_3_CONST(type, axis_zn, 0, 0,-1) \ + LOL_VEC_3_CONST(type, v111, 1, 1, 1) \ + LOL_VEC_3_CONST(type, v000, 0, 0, 0) \ + LOL_VEC_3_CONST(type, v100, 1, 0, 0) \ + LOL_VEC_3_CONST(type, v010, 0, 1, 0) \ + LOL_VEC_3_CONST(type, v001, 0, 0, 1) \ + LOL_VEC_3_CONST(type, v110, 1, 1, 0) \ + LOL_VEC_3_CONST(type, v101, 1, 0, 1) \ + LOL_VEC_3_CONST(type, v011, 0, 1, 1) \ + LOL_VEC_3_CONST(type, v000n, -1,-1,-1) \ + LOL_VEC_3_CONST(type, v100n, 1,-1,-1) \ + LOL_VEC_3_CONST(type, v010n, -1, 1,-1) \ + LOL_VEC_3_CONST(type, v001n, -1,-1, 1) \ + LOL_VEC_3_CONST(type, v110n, 1, 1,-1) \ + LOL_VEC_3_CONST(type, v101n, 1,-1, 1) \ + LOL_VEC_3_CONST(type, v011n, -1, 1, 1) \ \ - LOL_VEC_4_CONST(type, one, 1, 1, 1, 1) \ - LOL_VEC_4_CONST(type, mone,-1,-1,-1,-1) \ - LOL_VEC_4_CONST(type, zero, 0, 0, 0, 0) \ - LOL_VEC_4_CONST(type, axis_x, 1, 0, 0, 0) \ - LOL_VEC_4_CONST(type, axis_y, 0, 1, 0, 0) \ - LOL_VEC_4_CONST(type, axis_z, 0, 0, 1, 0) \ - LOL_VEC_4_CONST(type, axis_w, 0, 0, 0, 1) \ + LOL_VEC_4_CONST(type, one, 1, 1, 1, 1) \ + LOL_VEC_4_CONST(type, onen, -1,-1,-1,-1) \ + LOL_VEC_4_CONST(type, zero, 0, 0, 0, 0) \ + LOL_VEC_4_CONST(type, axis_x, 1, 0, 0, 0) \ + LOL_VEC_4_CONST(type, axis_y, 0, 1, 0, 0) \ + LOL_VEC_4_CONST(type, axis_z, 0, 0, 1, 0) \ + LOL_VEC_4_CONST(type, axis_w, 0, 0, 0, 1) \ + LOL_VEC_4_CONST(type, axis_xn, -1, 0, 0, 0) \ + LOL_VEC_4_CONST(type, axis_yn, 0,-1, 0, 0) \ + LOL_VEC_4_CONST(type, axis_zn, 0, 0,-1, 0) \ + LOL_VEC_4_CONST(type, axis_wn, 0, 0, 0,-1) \ + LOL_VEC_4_CONST(type, v1111, 1, 1, 1, 1) \ + LOL_VEC_4_CONST(type, v0000, 0, 0, 0, 0) \ + LOL_VEC_4_CONST(type, v1000, 1, 0, 0, 0) \ + LOL_VEC_4_CONST(type, v0100, 0, 1, 0, 0) \ + LOL_VEC_4_CONST(type, v0010, 0, 0, 1, 0) \ + LOL_VEC_4_CONST(type, v0001, 0, 0, 0, 1) \ + LOL_VEC_4_CONST(type, v1100, 1, 1, 0, 0) \ + LOL_VEC_4_CONST(type, v0110, 0, 1, 1, 0) \ + LOL_VEC_4_CONST(type, v0011, 0, 0, 1, 1) \ + LOL_VEC_4_CONST(type, v1010, 1, 0, 1, 0) \ + LOL_VEC_4_CONST(type, v0101, 0, 1, 0, 1) \ + LOL_VEC_4_CONST(type, v1001, 1, 0, 0, 1) \ + LOL_VEC_4_CONST(type, v0111, 0, 1, 1, 1) \ + LOL_VEC_4_CONST(type, v1011, 1, 0, 1, 1) \ + LOL_VEC_4_CONST(type, v1101, 1, 1, 0, 1) \ + LOL_VEC_4_CONST(type, v1110, 1, 1, 1, 0) \ + LOL_VEC_4_CONST(type, v0000n, -1,-1,-1,-1) \ + LOL_VEC_4_CONST(type, v1000n, 1,-1,-1,-1) \ + LOL_VEC_4_CONST(type, v0100n, -1, 1,-1,-1) \ + LOL_VEC_4_CONST(type, v0010n, -1,-1, 1,-1) \ + LOL_VEC_4_CONST(type, v0001n, -1,-1,-1, 1) \ + LOL_VEC_4_CONST(type, v1100n, 1, 1,-1,-1) \ + LOL_VEC_4_CONST(type, v0110n, -1, 1, 1,-1) \ + LOL_VEC_4_CONST(type, v0011n, -1,-1, 1, 1) \ + LOL_VEC_4_CONST(type, v1010n, 1,-1, 1,-1) \ + LOL_VEC_4_CONST(type, v0101n, -1, 1,-1, 1) \ + LOL_VEC_4_CONST(type, v1001n, 1,-1,-1, 1) \ + LOL_VEC_4_CONST(type, v0111n, -1, 1, 1, 1) \ + LOL_VEC_4_CONST(type, v1011n, 1,-1, 1, 1) \ + LOL_VEC_4_CONST(type, v1101n, 1, 1,-1, 1) \ + LOL_VEC_4_CONST(type, v1110n, 1, 1, 1,-1) \ \ LOL_MAT_CONST(type, identity, 1)