From 3da0e18de723fb3e9df662ed2d888836e34765f4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 6 Nov 2019 15:03:32 +0100 Subject: [PATCH] Added missing quat constexpr #955 --- glm/detail/type_quat.hpp | 40 +++++++++++++++---------------- glm/detail/type_quat.inl | 52 ++++++++++++++++++++-------------------- glm/gtx/quaternion.hpp | 4 ++-- glm/gtx/quaternion.inl | 4 ++-- readme.md | 1 + 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/glm/detail/type_quat.hpp b/glm/detail/type_quat.hpp index 49436d95..4d082fd7 100644 --- a/glm/detail/type_quat.hpp +++ b/glm/detail/type_quat.hpp @@ -102,67 +102,67 @@ namespace glm GLM_FUNC_DECL qua(vec<3, T, Q> const& u, vec<3, T, Q> const& v); /// Build a quaternion from euler angles (pitch, yaw, roll), in radians. - GLM_FUNC_DECL GLM_EXPLICIT qua(vec<3, T, Q> const& eulerAngles); + GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT qua(vec<3, T, Q> const& eulerAngles); GLM_FUNC_DECL GLM_EXPLICIT qua(mat<3, 3, T, Q> const& q); GLM_FUNC_DECL GLM_EXPLICIT qua(mat<4, 4, T, Q> const& q); // -- Unary arithmetic operators -- - GLM_FUNC_DECL qua& operator=(qua const& q) GLM_DEFAULT; + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator=(qua const& q) GLM_DEFAULT; template - GLM_FUNC_DECL qua& operator=(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator=(qua const& q); template - GLM_FUNC_DECL qua& operator+=(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator+=(qua const& q); template - GLM_FUNC_DECL qua& operator-=(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator-=(qua const& q); template - GLM_FUNC_DECL qua& operator*=(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator*=(qua const& q); template - GLM_FUNC_DECL qua& operator*=(U s); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator*=(U s); template - GLM_FUNC_DECL qua& operator/=(U s); + GLM_FUNC_DECL GLM_CONSTEXPR qua& operator/=(U s); }; // -- Unary bit operators -- template - GLM_FUNC_DECL qua operator+(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator+(qua const& q); template - GLM_FUNC_DECL qua operator-(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator-(qua const& q); // -- Binary operators -- template - GLM_FUNC_DECL qua operator+(qua const& q, qua const& p); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator+(qua const& q, qua const& p); template - GLM_FUNC_DECL qua operator-(qua const& q, qua const& p); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator-(qua const& q, qua const& p); template - GLM_FUNC_DECL qua operator*(qua const& q, qua const& p); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator*(qua const& q, qua const& p); template - GLM_FUNC_DECL vec<3, T, Q> operator*(qua const& q, vec<3, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<3, T, Q> operator*(qua const& q, vec<3, T, Q> const& v); template - GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua const& q); template - GLM_FUNC_DECL vec<4, T, Q> operator*(qua const& q, vec<4, T, Q> const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec<4, T, Q> operator*(qua const& q, vec<4, T, Q> const& v); template - GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR vec<4, T, Q> operator*(vec<4, T, Q> const& v, qua const& q); template - GLM_FUNC_DECL qua operator*(qua const& q, T const& s); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator*(qua const& q, T const& s); template - GLM_FUNC_DECL qua operator*(T const& s, qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator*(T const& s, qua const& q); template - GLM_FUNC_DECL qua operator/(qua const& q, T const& s); + GLM_FUNC_DECL GLM_CONSTEXPR qua operator/(qua const& q, T const& s); // -- Boolean operators -- diff --git a/glm/detail/type_quat.inl b/glm/detail/type_quat.inl index d44f494e..c1824e0c 100644 --- a/glm/detail/type_quat.inl +++ b/glm/detail/type_quat.inl @@ -15,7 +15,7 @@ namespace detail template struct compute_dot, T, Aligned> { - static GLM_FUNC_QUALIFIER T call(qua const& a, qua const& b) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static T call(qua const& a, qua const& b) { vec<4, T, Q> tmp(a.w * b.w, a.x * b.x, a.y * b.y, a.z * b.z); return (tmp.x + tmp.y) + (tmp.z + tmp.w); @@ -25,7 +25,7 @@ namespace detail template struct compute_quat_add { - static qua call(qua const& q, qua const& p) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static qua call(qua const& q, qua const& p) { return qua(q.w + p.w, q.x + p.x, q.y + p.y, q.z + p.z); } @@ -34,7 +34,7 @@ namespace detail template struct compute_quat_sub { - static qua call(qua const& q, qua const& p) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static qua call(qua const& q, qua const& p) { return qua(q.w - p.w, q.x - p.x, q.y - p.y, q.z - p.z); } @@ -43,7 +43,7 @@ namespace detail template struct compute_quat_mul_scalar { - static qua call(qua const& q, T s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static qua call(qua const& q, T s) { return qua(q.w * s, q.x * s, q.y * s, q.z * s); } @@ -52,7 +52,7 @@ namespace detail template struct compute_quat_div_scalar { - static qua call(qua const& q, T s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static qua call(qua const& q, T s) { return qua(q.w / s, q.x / s, q.y / s, q.z / s); } @@ -61,7 +61,7 @@ namespace detail template struct compute_quat_mul_vec4 { - static vec<4, T, Q> call(qua const& q, vec<4, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<4, T, Q> call(qua const& q, vec<4, T, Q> const& v) { return vec<4, T, Q>(q * vec<3, T, Q>(v), v.w); } @@ -172,7 +172,7 @@ namespace detail } template - GLM_FUNC_QUALIFIER qua::qua(vec<3, T, Q> const& eulerAngle) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua::qua(vec<3, T, Q> const& eulerAngle) { vec<3, T, Q> c = glm::cos(eulerAngle * T(0.5)); vec<3, T, Q> s = glm::sin(eulerAngle * T(0.5)); @@ -213,7 +213,7 @@ namespace detail # if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE template - GLM_FUNC_QUALIFIER qua & qua::operator=(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator=(qua const& q) { this->w = q.w; this->x = q.x; @@ -225,7 +225,7 @@ namespace detail template template - GLM_FUNC_QUALIFIER qua & qua::operator=(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator=(qua const& q) { this->w = static_cast(q.w); this->x = static_cast(q.x); @@ -236,21 +236,21 @@ namespace detail template template - GLM_FUNC_QUALIFIER qua & qua::operator+=(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator+=(qua const& q) { return (*this = detail::compute_quat_add::value>::call(*this, qua(q))); } template template - GLM_FUNC_QUALIFIER qua & qua::operator-=(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator-=(qua const& q) { return (*this = detail::compute_quat_sub::value>::call(*this, qua(q))); } template template - GLM_FUNC_QUALIFIER qua & qua::operator*=(qua const& r) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator*=(qua const& r) { qua const p(*this); qua const q(r); @@ -264,14 +264,14 @@ namespace detail template template - GLM_FUNC_QUALIFIER qua & qua::operator*=(U s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator*=(U s) { return (*this = detail::compute_quat_mul_scalar::value>::call(*this, static_cast(s))); } template template - GLM_FUNC_QUALIFIER qua & qua::operator/=(U s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua & qua::operator/=(U s) { return (*this = detail::compute_quat_div_scalar::value>::call(*this, static_cast(s))); } @@ -279,13 +279,13 @@ namespace detail // -- Unary bit operators -- template - GLM_FUNC_QUALIFIER qua operator+(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator+(qua const& q) { return q; } template - GLM_FUNC_QUALIFIER qua operator-(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator-(qua const& q) { return qua(-q.w, -q.x, -q.y, -q.z); } @@ -293,25 +293,25 @@ namespace detail // -- Binary operators -- template - GLM_FUNC_QUALIFIER qua operator+(qua const& q, qua const& p) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator+(qua const& q, qua const& p) { return qua(q) += p; } template - GLM_FUNC_QUALIFIER qua operator-(qua const& q, qua const& p) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator-(qua const& q, qua const& p) { return qua(q) -= p; } template - GLM_FUNC_QUALIFIER qua operator*(qua const& q, qua const& p) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator*(qua const& q, qua const& p) { return qua(q) *= p; } template - GLM_FUNC_QUALIFIER vec<3, T, Q> operator*(qua const& q, vec<3, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<3, T, Q> operator*(qua const& q, vec<3, T, Q> const& v) { vec<3, T, Q> const QuatVector(q.x, q.y, q.z); vec<3, T, Q> const uv(glm::cross(QuatVector, v)); @@ -321,38 +321,38 @@ namespace detail } template - GLM_FUNC_QUALIFIER vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua const& q) { return glm::inverse(q) * v; } template - GLM_FUNC_QUALIFIER vec<4, T, Q> operator*(qua const& q, vec<4, T, Q> const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, T, Q> operator*(qua const& q, vec<4, T, Q> const& v) { return detail::compute_quat_mul_vec4::value>::call(q, v); } template - GLM_FUNC_QUALIFIER vec<4, T, Q> operator*(vec<4, T, Q> const& v, qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, T, Q> operator*(vec<4, T, Q> const& v, qua const& q) { return glm::inverse(q) * v; } template - GLM_FUNC_QUALIFIER qua operator*(qua const& q, T const& s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator*(qua const& q, T const& s) { return qua( q.w * s, q.x * s, q.y * s, q.z * s); } template - GLM_FUNC_QUALIFIER qua operator*(T const& s, qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator*(T const& s, qua const& q) { return q * s; } template - GLM_FUNC_QUALIFIER qua operator/(qua const& q, T const& s) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua operator/(qua const& q, T const& s) { return qua( q.w / s, q.x / s, q.y / s, q.z / s); diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 3ce0b886..5c2b5ad0 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -37,7 +37,7 @@ namespace glm /// /// @see gtx_quaternion template - GLM_FUNC_DECL qua quat_identity(); + GLM_FUNC_DECL GLM_CONSTEXPR qua quat_identity(); /// Compute a cross product between a quaternion and a vector. /// @@ -166,7 +166,7 @@ namespace glm /// /// @see gtx_quaternion template - GLM_FUNC_DECL T length2(qua const& q); + GLM_FUNC_DECL GLM_CONSTEXPR T length2(qua const& q); /// @} }//namespace glm diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 679b39f1..d125bccc 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -6,7 +6,7 @@ namespace glm { template - GLM_FUNC_QUALIFIER qua quat_identity() + GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua quat_identity() { return qua(static_cast(1), static_cast(0), static_cast(0), static_cast(0)); } @@ -70,7 +70,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER T length2(qua const& q) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR T length2(qua const& q) { return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w; } diff --git a/readme.md b/readme.md index f038fad2..547602ef 100644 --- a/readme.md +++ b/readme.md @@ -58,6 +58,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) - Improved Neon support with more functions optimized #950 - Added CMake GLM interface #963 - Added fma implementation based on std::fma #969 +- Added missing quat constexpr #955 #### Fixes: - Fixed equal ULP variation when using negative sign #965