added: quat::op+=(quat) and quat::op*=(quat)
This commit is contained in:
parent
137b296556
commit
e299af614f
@ -106,6 +106,8 @@ namespace detail
|
|||||||
GLM_FUNC_DECL T const & operator[](int i) const;
|
GLM_FUNC_DECL T const & operator[](int i) const;
|
||||||
|
|
||||||
// Operators
|
// 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);
|
||||||
GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
|
GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
|
||||||
};
|
};
|
||||||
|
@ -182,6 +182,34 @@ namespace detail
|
|||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// tquat<valType> operators
|
// 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>
|
template <typename T, precision P>
|
||||||
GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
|
GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
|
||||||
(
|
(
|
||||||
@ -227,11 +255,7 @@ namespace detail
|
|||||||
detail::tquat<T, P> const & p
|
detail::tquat<T, P> const & p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T, P>(
|
return detail::tquat<T, P>(q) += p;
|
||||||
q.w + p.w,
|
|
||||||
q.x + p.x,
|
|
||||||
q.y + p.y,
|
|
||||||
q.z + p.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, precision P>
|
template <typename T, precision P>
|
||||||
@ -241,11 +265,7 @@ namespace detail
|
|||||||
detail::tquat<T, P> const & p
|
detail::tquat<T, P> const & p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T, P>(
|
return detail::tquat<T, P>(q) *= 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transformation
|
// Transformation
|
||||||
|
@ -210,6 +210,15 @@ int test_quat_mul()
|
|||||||
glm::quat temp5 = glm::normalize(temp1 * temp2);
|
glm::quat temp5 = glm::normalize(temp1 * temp2);
|
||||||
glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5);
|
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;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user