diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 982d8e5d..cc3c76ad 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -106,6 +106,8 @@ namespace detail GLM_FUNC_DECL T const & operator[](int i) const; // Operators + GLM_FUNC_DECL tquat & operator+=(tquat const & q); + GLM_FUNC_DECL tquat & operator*=(tquat const & q); GLM_FUNC_DECL tquat & operator*=(T const & s); GLM_FUNC_DECL tquat & operator/=(T const & s); }; diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index ab503cdb..e8aa037b 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -182,6 +182,34 @@ namespace detail ////////////////////////////////////////////////////////////// // tquat operators + template + GLM_FUNC_QUALIFIER tquat & tquat::operator += + ( + tquat const & q + ) + { + this->w += q.w; + this->x += q.x; + this->y += q.y; + this->z += q.z; + return *this; + } + + template + GLM_FUNC_QUALIFIER tquat & tquat::operator *= + ( + tquat const & q + ) + { + tquat const p(*this); + + this->w = p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z; + this->x = p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y; + this->y = p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z; + this->z = p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x; + return *this; + } + template GLM_FUNC_QUALIFIER tquat & tquat::operator *= ( @@ -194,7 +222,7 @@ namespace detail this->z *= s; return *this; } - + template GLM_FUNC_QUALIFIER tquat & tquat::operator /= ( @@ -227,11 +255,7 @@ namespace detail detail::tquat const & p ) { - return detail::tquat( - q.w + p.w, - q.x + p.x, - q.y + p.y, - q.z + p.z); + return detail::tquat(q) += p; } template @@ -241,11 +265,7 @@ namespace detail detail::tquat const & p ) { - return detail::tquat( - q.w * p.w - q.x * p.x - q.y * p.y - q.z * p.z, - q.w * p.x + q.x * p.w + q.y * p.z - q.z * p.y, - q.w * p.y + q.y * p.w + q.z * p.x - q.x * p.z, - q.w * p.z + q.z * p.w + q.x * p.y - q.y * p.x); + return detail::tquat(q) *= p; } // Transformation diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index be1638f7..079dbe7f 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -210,6 +210,15 @@ int test_quat_mul() glm::quat temp5 = glm::normalize(temp1 * temp2); glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5); + { + glm::quat temp7; + + temp7 *= temp5; + temp7 *= glm::inverse(temp5); + + Error += temp7 != glm::quat(); + } + return Error; }