diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 0c8feb59..c47f7803 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -135,6 +135,16 @@ struct vec_t m_data[i] = (T)v[i]; } + /* Factory for base axis vectors, e.g. [1,0,0,…,0] */ + static inline vec_t axis(int i) + { + ASSERT(i >= 0); + ASSERT(i < N); + vec_t ret((T)0); + ret[i] = (T)1; + return ret; + } + /* Constructor for initializer_list. We need these ugly * loops until C++ lets us initialize m_data directly. */ inline vec_t(std::initializer_list const &list) @@ -235,6 +245,14 @@ struct vec_t explicit inline constexpr vec_t(T X) : x(X), y(X) {} + /* Factory for base axis vectors, e.g. [1,0,0,…,0] */ + static inline vec_t axis(int i) + { + ASSERT(i >= 0); + ASSERT(i < 2); + return vec_t((T)(i == 0), (T)(i == 1)); + } + LOL_COMMON_MEMBER_OPS(x) static const vec_t zero; @@ -346,6 +364,14 @@ struct vec_t explicit inline constexpr vec_t(T X, vec_t YZ) : x(X), y(YZ.x), z(YZ.y) {} + /* Factory for base axis vectors, e.g. [1,0,0,…,0] */ + static inline vec_t axis(int i) + { + ASSERT(i >= 0); + ASSERT(i < 3); + return vec_t((T)(i == 0), (T)(i == 1), (T)(i == 2)); + } + LOL_COMMON_MEMBER_OPS(x) static vec_t toeuler_xyx(quat_t const &q); @@ -592,6 +618,14 @@ struct vec_t explicit inline constexpr vec_t(T X, vec_t YZW) : x(X), y(YZW.x), z(YZW.y), w(YZW.z) {} + /* Factory for base axis vectors, e.g. [1,0,0,…,0] */ + static inline vec_t axis(int i) + { + ASSERT(i >= 0); + ASSERT(i < 4); + return vec_t((T)(i == 0), (T)(i == 1), (T)(i == 2), (T)(i == 3)); + } + LOL_COMMON_MEMBER_OPS(x) static const vec_t zero;