added: quat::op+=(quat) and quat::op*=(quat)

This commit is contained in:
jan p springer 2013-11-22 21:46:30 +00:00
parent 137b296556
commit e299af614f
3 changed files with 42 additions and 11 deletions

View File

@ -106,6 +106,8 @@ namespace detail
GLM_FUNC_DECL T const & operator[](int i) const;
// Operators
GLM_FUNC_DECL tquat<T, P> & operator+=(tquat<T, P> const & q);
GLM_FUNC_DECL tquat<T, P> & operator*=(tquat<T, P> const & q);
GLM_FUNC_DECL tquat<T, P> & operator*=(T const & s);
GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
};

View File

@ -182,6 +182,34 @@ namespace detail
//////////////////////////////////////////////////////////////
// tquat<valType> operators
template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator +=
(
tquat<T, P> const & q
)
{
this->w += q.w;
this->x += q.x;
this->y += q.y;
this->z += q.z;
return *this;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
(
tquat<T, P> const & q
)
{
tquat<T, P> 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 <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
(
@ -227,11 +255,7 @@ namespace detail
detail::tquat<T, P> const & p
)
{
return detail::tquat<T, P>(
q.w + p.w,
q.x + p.x,
q.y + p.y,
q.z + p.z);
return detail::tquat<T, P>(q) += p;
}
template <typename T, precision P>
@ -241,11 +265,7 @@ namespace detail
detail::tquat<T, P> const & p
)
{
return detail::tquat<T, P>(
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<T, P>(q) *= p;
}
// Transformation

View File

@ -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;
}