From 3f9d449f58af7cb29fcea80fe6b8423bfbffc5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 27 May 2013 16:14:54 +0200 Subject: [PATCH] Math: fix compilation with Clang. It seems that with Clang you cannot split declaration and definition of `constexpr` function. These should be as short as possible anyway, thus it is non-issue. --- src/Math/Matrix3.h | 36 ++++++++++-------------- src/Math/Matrix4.h | 68 ++++++++++++++++++++-------------------------- 2 files changed, 44 insertions(+), 60 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 39413b874..ae49a62b9 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -53,7 +53,11 @@ template class Matrix3: public Matrix<3, T> { * Matrix4::translation(const Vector3&), Vector2::xAxis(), * Vector2::yAxis() */ - constexpr static Matrix3 translation(const Vector2& vector); + constexpr static Matrix3 translation(const Vector2& vector) { + return {{ T(1), T(0), T(0)}, + { T(0), T(1), T(0)}, + {vector.x(), vector.y(), T(1)}}; + } /** * @brief 2D scaling matrix @@ -62,7 +66,11 @@ template class Matrix3: public Matrix<3, T> { * @see rotationScaling() const, Matrix4::scaling(const Vector3&), * Vector2::xScale(), Vector2::yScale() */ - constexpr static Matrix3 scaling(const Vector2& vector); + constexpr static Matrix3 scaling(const Vector2& vector) { + return {{vector.x(), T(0), T(0)}, + { T(0), vector.y(), T(0)}, + { T(0), T(0), T(1)}}; + } /** * @brief 2D rotation matrix @@ -122,7 +130,11 @@ template class Matrix3: public Matrix<3, T> { * @p value allows you to specify value on diagonal. * @todo Use constexpr implementation in Matrix, when done */ - constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)); + constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( + Vector<3, T>(value, T(0), T(0)), + Vector<3, T>( T(0), value, T(0)), + Vector<3, T>( T(0), T(0), value) + ) {} /** @brief %Matrix from column vectors */ constexpr /*implicit*/ Matrix3(const Vector3& first, const Vector3& second, const Vector3& third): Matrix<3, T>(first, second, third) {} @@ -250,24 +262,6 @@ template inline Corrade::Utility::Debug operator<<(Corrade::Utility::De return debug << static_cast&>(value); } -template constexpr Matrix3::Matrix3(typename Matrix<3, T>::IdentityType, const T value): Matrix<3, T>( - Vector<3, T>(value, T(0), T(0)), - Vector<3, T>( T(0), value, T(0)), - Vector<3, T>( T(0), T(0), value) -) {} - -template constexpr Matrix3 Matrix3::translation(const Vector2& vector) { - return {{ T(1), T(0), T(0)}, - { T(0), T(1), T(0)}, - {vector.x(), vector.y(), T(1)}}; -} - -template constexpr Matrix3 Matrix3::scaling(const Vector2< T >& vector) { - return {{vector.x(), T(0), T(0)}, - { T(0), vector.y(), T(0)}, - { T(0), T(0), T(1)}}; -} - template Matrix3 Matrix3::rotation(const Rad angle) { const T sine = std::sin(T(angle)); const T cosine = std::cos(T(angle)); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index f1f366bf9..23028357d 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -58,7 +58,12 @@ template class Matrix4: public Matrix<4, T> { * Matrix3::translation(const Vector2&), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis() */ - constexpr static Matrix4 translation(const Vector3& vector); + constexpr static Matrix4 translation(const Vector3& vector) { + return {{ T(1), T(0), T(0), T(0)}, + { T(0), T(1), T(0), T(0)}, + { T(0), T(0), T(1), T(0)}, + {vector.x(), vector.y(), vector.z(), T(1)}}; + } /** * @brief 3D scaling @@ -67,7 +72,12 @@ template class Matrix4: public Matrix<4, T> { * @see rotationScaling() const, Matrix3::scaling(const Vector2&), * Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ - constexpr static Matrix4 scaling(const Vector3& vector); + constexpr static Matrix4 scaling(const Vector3& vector) { + return {{vector.x(), T(0), T(0), T(0)}, + { T(0), vector.y(), T(0), T(0)}, + { T(0), T(0), vector.z(), T(0)}, + { T(0), T(0), T(0), T(1)}}; + } /** * @brief 3D rotation around arbitrary axis @@ -164,7 +174,12 @@ template class Matrix4: public Matrix<4, T> { * * @see rotationScaling() const, translation() const */ - constexpr static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation); + constexpr static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { + return {{rotationScaling[0], T(0)}, + {rotationScaling[1], T(0)}, + {rotationScaling[2], T(0)}, + { translation, T(1)}}; + } /** @copydoc Matrix::Matrix(ZeroType) */ constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} @@ -177,7 +192,12 @@ template class Matrix4: public Matrix<4, T> { * @p value allows you to specify value on diagonal. * @todo Use constexpr implementation in Matrix, when done */ - constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)); + constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( + Vector<4, T>(value, T(0), T(0), T(0)), + Vector<4, T>( T(0), value, T(0), T(0)), + Vector<4, T>( T(0), T(0), value, T(0)), + Vector<4, T>( T(0), T(0), T(0), value) + ) {} /** @brief %Matrix from column vectors */ constexpr /*implicit*/ Matrix4(const Vector4& first, const Vector4& second, const Vector4& third, const Vector4& fourth): Matrix<4, T>(first, second, third, fourth) {} @@ -211,7 +231,11 @@ template class Matrix4: public Matrix<4, T> { * @todo extract rotation with assert for no scaling */ /* Not Matrix3, because it is for affine 2D transformations */ - constexpr Matrix<3, T> rotationScaling() const; + constexpr Matrix<3, T> rotationScaling() const { + return {(*this)[0].xyz(), + (*this)[1].xyz(), + (*this)[2].xyz()}; + } /** * @brief 3D rotation part of the matrix @@ -311,20 +335,6 @@ template inline Corrade::Utility::Debug operator<<(Corrade::Utility::De return debug << static_cast&>(value); } -template constexpr Matrix4 Matrix4::translation(const Vector3& vector) { - return {{ T(1), T(0), T(0), T(0)}, - { T(0), T(1), T(0), T(0)}, - { T(0), T(0), T(1), T(0)}, - {vector.x(), vector.y(), vector.z(), T(1)}}; -} - -template constexpr Matrix4 Matrix4::scaling(const Vector3& vector) { - return {{vector.x(), T(0), T(0), T(0)}, - { T(0), vector.y(), T(0), T(0)}, - { T(0), T(0), vector.z(), T(0)}, - { T(0), T(0), T(0), T(1)}}; -} - template Matrix4 Matrix4::rotation(const Rad angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(normalizedAxis.isNormalized(), "Math::Matrix4::rotation(): axis must be normalized", {}); @@ -413,26 +423,6 @@ template Matrix4 Matrix4::perspectiveProjection(const Vector2& { T(0), T(0), T(2)*far*near*zScale, T(0)}}; } -template constexpr Matrix4 Matrix4::from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { - return {{rotationScaling[0], T(0)}, - {rotationScaling[1], T(0)}, - {rotationScaling[2], T(0)}, - { translation, T(1)}}; -} - -template constexpr Matrix4::Matrix4(typename Matrix<4, T>::IdentityType, const T value): Matrix<4, T>( - Vector<4, T>(value, T(0), T(0), T(0)), - Vector<4, T>( T(0), value, T(0), T(0)), - Vector<4, T>( T(0), T(0), value, T(0)), - Vector<4, T>( T(0), T(0), T(0), value) -) {} - -template constexpr Matrix<3, T> Matrix4::rotationScaling() const { - return {(*this)[0].xyz(), - (*this)[1].xyz(), - (*this)[2].xyz()}; -} - template inline Matrix<3, T> Matrix4::rotation() const { return {(*this)[0].xyz().normalized(), (*this)[1].xyz().normalized(),