///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 – 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the “Software”), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_quaternion
/// @file glm/gtx/quaternion.inl
/// @date 2005-12-21 / 2011-06-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include
namespace glm
{
template
GLM_FUNC_QUALIFIER tvec3
(
tvec3
tquat
)
{
return inverse(q) * v;
}
template
GLM_FUNC_QUALIFIER tvec3
(
tquat
tvec3
)
{
return q * v;
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
tquat
tquat
tquat
T const & h)
{
return mix(mix(q1, q2, h), mix(s1, s2, h), static_cast
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
tquat
tquat
)
{
tquat
return exp((log(next + invQuat) + log(prev + invQuat)) / static_cast
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
)
{
tvec3
T Angle = glm::length(u);
if (Angle < epsilon
return tquat
tvec3
return tquat
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
)
{
tvec3
T Vec3Len = length(u);
if (Vec3Len < epsilon
{
if(q.w > static_cast
return tquat
else if(q.w < static_cast
return tquat
else
return tquat
}
else
{
T QuatLen = sqrt(Vec3Len * Vec3Len + q.w * q.w);
T t = atan(Vec3Len, T(q.w)) / Vec3Len;
return tquat
}
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
T const & y
)
{
if(abs(x.w) > (static_cast
return x;
T Angle = acos(y);
T NewAngle = Angle * y;
T Div = sin(NewAngle) / sin(Angle);
return tquat
cos(NewAngle),
x.x * Div,
x.y * Div,
x.z * Div);
}
//template
//GLM_FUNC_QUALIFIER tquat
//(
// tquat
//)
//{
// T q0 = static_cast
// return T(2) * (T(1) + q0) * q;
//}
template
GLM_FUNC_QUALIFIER tvec3
(
tquat
tvec3
)
{
return q * v;
}
template
GLM_FUNC_QUALIFIER tvec4
(
tquat
tvec4
)
{
return q * v;
}
template
GLM_FUNC_QUALIFIER T extractRealComponent
(
tquat
)
{
T w = static_cast
if(w < T(0))
return T(0);
else
return -sqrt(w);
}
template
GLM_FUNC_QUALIFIER T length2
(
tquat
)
{
return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
tquat
T const & a
)
{
if(a <= static_cast
if(a >= static_cast
T fCos = dot(x, y);
tquat
if(fCos < static_cast
{
y2 = -y;
fCos = -fCos;
}
//if(fCos > 1.0f) // problem
T k0, k1;
if(fCos > (static_cast
{
k0 = static_cast
k1 = static_cast
}
else
{
T fSin = sqrt(T(1) – fCos * fCos);
T fAngle = atan(fSin, fCos);
T fOneOverSin = static_cast
k0 = sin((static_cast
k1 = sin((static_cast
}
return tquat
k0 * x.w + k1 * y2.w,
k0 * x.x + k1 * y2.x,
k0 * x.y + k1 * y2.y,
k0 * x.z + k1 * y2.z);
}
template
GLM_FUNC_QUALIFIER tquat
(
tquat
tquat
T const & a
)
{
return glm::normalize(x * (static_cast
}
template
GLM_FUNC_QUALIFIER tquat
(
tvec3
tvec3
)
{
T cosTheta = dot(orig, dest);
tvec3
if(cosTheta < static_cast
{
// special case when vectors in opposite directions :
// there is no “ideal” rotation axis
// So guess one; any will do as long as it’s perpendicular to start
// This implementation favors a rotation around the Up axis (Y),
// since it’s often what you want to do.
rotationAxis = cross(tvec3
if(length2(rotationAxis) < epsilon
rotationAxis = cross(tvec3
rotationAxis = normalize(rotationAxis);
return angleAxis(pi
}
// Implementation from Stan Melax’s Game Programming Gems 1 article
rotationAxis = cross(orig, dest);
T s = sqrt((T(1) + cosTheta) * static_cast
T invs = static_cast
return tquat
s * static_cast
rotationAxis.x * invs,
rotationAxis.y * invs,
rotationAxis.z * invs);
}
}//namespace glm