From 91451eaf70ebae1a91ad89274728d6407d71dc9d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 25 Dec 2014 15:59:30 +0000 Subject: [PATCH] math: add explicit casts between matrices of same size but different types. --- src/lol/math/matrix.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index 4c75b418..cba7271a 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -49,6 +49,14 @@ struct mat_t m_data[i][j] = i == j ? val : zero; } + /* Explicit constructor for type conversion */ + template + explicit inline mat_t(mat_t const &m) + { + for (int i = 0; i < COLS; ++i) + m_data[i] = (vec_t)m[i]; + } + inline vec_t& operator[](size_t n) { return m_data[n]; } inline vec_t const& operator[](size_t n) const { return m_data[n]; } @@ -92,6 +100,15 @@ struct mat_t : m_v0(m[0].xy), m_v1(m[1].xy) {} #endif + /* Explicit constructor for type conversion */ + template + explicit inline mat_t(mat_t const &m) +#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS + : m_data{ (element)m[0], (element)m[1] } {} +#else + : m_v0((element)m[0]), m_v1((element)m[1]) {} +#endif + #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS inline vec_t& operator[](size_t n) { return m_data[n]; } inline vec_t const& operator[](size_t n) const { return m_data[n]; } @@ -180,6 +197,15 @@ struct mat_t : m_v0(m[0].xyz), m_v1(m[1].xyz), m_v2(m[2].xyz) {} #endif + /* Explicit constructor for type conversion */ + template + explicit inline mat_t(mat_t const &m) +#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS + : m_data{ (element)m[0], (element)m[1], (element)m[2] } {} +#else + : m_v0((element)m[0]), m_v1((element)m[1], m_v2((element)m[2]) {} +#endif + explicit mat_t(quat_t const &q); #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS @@ -311,6 +337,17 @@ struct mat_t m_v3((T)0, (T)0, (T)0, val) {} #endif + /* Explicit constructor for type conversion */ + template + explicit inline mat_t(mat_t const &m) +#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS + : m_data{ (element)m[0], (element)m[1], + (element)m[2], (element)m[3] } {} +#else + : m_v0((element)m[0]), m_v1((element)m[1], + m_v2((element)m[2]), m_v3((element)m[3]) {} +#endif + explicit mat_t(quat_t const &q); #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS