mirror of
https://github.com/g-truc/glm.git
synced 2024-11-27 02:34:35 +00:00
Fixed space character
This commit is contained in:
parent
bfec0e2388
commit
669ace8067
@ -79,7 +79,7 @@ namespace detail
|
|||||||
|
|
||||||
// Convertions
|
// Convertions
|
||||||
|
|
||||||
//! Build a quaternion from euler angles (pitch, yaw, roll), in radians.
|
/// Build a quaternion from euler angles (pitch, yaw, roll), in radians.
|
||||||
explicit tquat(
|
explicit tquat(
|
||||||
tvec3<T> const & eulerAngles);
|
tvec3<T> const & eulerAngles);
|
||||||
explicit tquat(
|
explicit tquat(
|
||||||
|
@ -31,48 +31,48 @@
|
|||||||
namespace glm{
|
namespace glm{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER typename tquat<T>::size_type tquat<T>::length() const
|
GLM_FUNC_QUALIFIER typename tquat<T>::size_type tquat<T>::length() const
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T>::tquat() :
|
GLM_FUNC_QUALIFIER tquat<T>::tquat() :
|
||||||
x(0),
|
x(0),
|
||||||
y(0),
|
y(0),
|
||||||
z(0),
|
z(0),
|
||||||
w(1)
|
w(1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
||||||
(
|
(
|
||||||
value_type const & s,
|
value_type const & s,
|
||||||
tvec3<T> const & v
|
tvec3<T> const & v
|
||||||
) :
|
) :
|
||||||
x(v.x),
|
x(v.x),
|
||||||
y(v.y),
|
y(v.y),
|
||||||
z(v.z),
|
z(v.z),
|
||||||
w(s)
|
w(s)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
||||||
(
|
(
|
||||||
value_type const & w,
|
value_type const & w,
|
||||||
value_type const & x,
|
value_type const & x,
|
||||||
value_type const & y,
|
value_type const & y,
|
||||||
value_type const & z
|
value_type const & z
|
||||||
) :
|
) :
|
||||||
x(x),
|
x(x),
|
||||||
y(y),
|
y(y),
|
||||||
z(z),
|
z(z),
|
||||||
w(w)
|
w(w)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// tquat conversions
|
// tquat conversions
|
||||||
|
|
||||||
//template <typename valType>
|
//template <typename valType>
|
||||||
//GLM_FUNC_QUALIFIER tquat<valType>::tquat
|
//GLM_FUNC_QUALIFIER tquat<valType>::tquat
|
||||||
@ -107,70 +107,70 @@ namespace detail
|
|||||||
this->z = c.x * c.y * s.z - s.x * s.y * c.z;
|
this->z = c.x * c.y * s.z - s.x * s.y * c.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
||||||
(
|
(
|
||||||
tmat3x3<T> const & m
|
tmat3x3<T> const & m
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
*this = quat_cast(m);
|
*this = quat_cast(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
GLM_FUNC_QUALIFIER tquat<T>::tquat
|
||||||
(
|
(
|
||||||
tmat4x4<T> const & m
|
tmat4x4<T> const & m
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
*this = quat_cast(m);
|
*this = quat_cast(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// tquat<T> accesses
|
// tquat<T> accesses
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER typename tquat<T>::value_type & tquat<T>::operator [] (int i)
|
GLM_FUNC_QUALIFIER typename tquat<T>::value_type & tquat<T>::operator [] (int i)
|
||||||
{
|
{
|
||||||
return (&x)[i];
|
return (&x)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER typename tquat<T>::value_type const & tquat<T>::operator [] (int i) const
|
GLM_FUNC_QUALIFIER typename tquat<T>::value_type const & tquat<T>::operator [] (int i) const
|
||||||
{
|
{
|
||||||
return (&x)[i];
|
return (&x)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// tquat<valType> operators
|
// tquat<valType> operators
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T> & tquat<T>::operator *=
|
GLM_FUNC_QUALIFIER tquat<T> & tquat<T>::operator *=
|
||||||
(
|
(
|
||||||
value_type const & s
|
value_type const & s
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this->w *= s;
|
this->w *= s;
|
||||||
this->x *= s;
|
this->x *= s;
|
||||||
this->y *= s;
|
this->y *= s;
|
||||||
this->z *= s;
|
this->z *= s;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER tquat<T> & tquat<T>::operator /=
|
GLM_FUNC_QUALIFIER tquat<T> & tquat<T>::operator /=
|
||||||
(
|
(
|
||||||
value_type const & s
|
value_type const & s
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this->w /= s;
|
this->w /= s;
|
||||||
this->x /= s;
|
this->x /= s;
|
||||||
this->y /= s;
|
this->y /= s;
|
||||||
this->z /= s;
|
this->z /= s;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// tquat<valType> external operators
|
// tquat<valType> external operators
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> operator-
|
GLM_FUNC_QUALIFIER detail::tquat<T> operator-
|
||||||
@ -188,11 +188,11 @@ namespace detail
|
|||||||
detail::tquat<T> const & p
|
detail::tquat<T> const & p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T>(
|
return detail::tquat<T>(
|
||||||
q.w + p.w,
|
q.w + p.w,
|
||||||
q.x + p.x,
|
q.x + p.x,
|
||||||
q.y + p.y,
|
q.y + p.y,
|
||||||
q.z + p.z);
|
q.z + p.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -202,11 +202,11 @@ namespace detail
|
|||||||
detail::tquat<T> const & p
|
detail::tquat<T> const & p
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T>(
|
return detail::tquat<T>(
|
||||||
q.w * p.w - q.x * p.x - q.y * p.y - q.z * p.z,
|
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.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.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);
|
q.w * p.z + q.z * p.w + q.x * p.y - q.y * p.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transformation
|
// Transformation
|
||||||
@ -317,108 +317,108 @@ namespace detail
|
|||||||
}//namespace detail
|
}//namespace detail
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER T length
|
GLM_FUNC_QUALIFIER T length
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return glm::sqrt(dot(q, q));
|
return glm::sqrt(dot(q, q));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> normalize
|
GLM_FUNC_QUALIFIER detail::tquat<T> normalize
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
typename detail::tquat<T>::value_type len = length(q);
|
typename detail::tquat<T>::value_type len = length(q);
|
||||||
if(len <= typename detail::tquat<T>::value_type(0)) // Problem
|
if(len <= typename detail::tquat<T>::value_type(0)) // Problem
|
||||||
return detail::tquat<T>(1, 0, 0, 0);
|
return detail::tquat<T>(1, 0, 0, 0);
|
||||||
typename detail::tquat<T>::value_type oneOverLen = typename detail::tquat<T>::value_type(1) / len;
|
typename detail::tquat<T>::value_type oneOverLen = typename detail::tquat<T>::value_type(1) / len;
|
||||||
return detail::tquat<T>(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen);
|
return detail::tquat<T>(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER T dot
|
GLM_FUNC_QUALIFIER T dot
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q1,
|
detail::tquat<T> const & q1,
|
||||||
detail::tquat<T> const & q2
|
detail::tquat<T> const & q2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
|
return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> cross
|
GLM_FUNC_QUALIFIER detail::tquat<T> cross
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q1,
|
detail::tquat<T> const & q1,
|
||||||
detail::tquat<T> const & q2
|
detail::tquat<T> const & q2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T>(
|
return detail::tquat<T>(
|
||||||
q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z,
|
q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z,
|
||||||
q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y,
|
q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y,
|
||||||
q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z,
|
q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z,
|
||||||
q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x);
|
q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
// (x * sin(1 - a) * angle / sin(angle)) + (y * sin(a) * angle / sin(angle))
|
// (x * sin(1 - a) * angle / sin(angle)) + (y * sin(a) * angle / sin(angle))
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> mix
|
GLM_FUNC_QUALIFIER detail::tquat<T> mix
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & x,
|
detail::tquat<T> const & x,
|
||||||
detail::tquat<T> const & y,
|
detail::tquat<T> const & y,
|
||||||
typename detail::tquat<T>::value_type const & a
|
typename detail::tquat<T>::value_type const & a
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if(a <= typename detail::tquat<T>::value_type(0)) return x;
|
if(a <= typename detail::tquat<T>::value_type(0)) return x;
|
||||||
if(a >= typename detail::tquat<T>::value_type(1)) return y;
|
if(a >= typename detail::tquat<T>::value_type(1)) return y;
|
||||||
|
|
||||||
float fCos = dot(x, y);
|
float fCos = dot(x, y);
|
||||||
detail::tquat<T> y2(y); //BUG!!! tquat<T> y2;
|
detail::tquat<T> y2(y); //BUG!!! tquat<T> y2;
|
||||||
if(fCos < typename detail::tquat<T>::value_type(0))
|
if(fCos < typename detail::tquat<T>::value_type(0))
|
||||||
{
|
{
|
||||||
y2 = -y;
|
y2 = -y;
|
||||||
fCos = -fCos;
|
fCos = -fCos;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(fCos > 1.0f) // problem
|
//if(fCos > 1.0f) // problem
|
||||||
float k0, k1;
|
float k0, k1;
|
||||||
if(fCos > typename detail::tquat<T>::value_type(0.9999))
|
if(fCos > typename detail::tquat<T>::value_type(0.9999))
|
||||||
{
|
{
|
||||||
k0 = typename detail::tquat<T>::value_type(1) - a;
|
k0 = typename detail::tquat<T>::value_type(1) - a;
|
||||||
k1 = typename detail::tquat<T>::value_type(0) + a; //BUG!!! 1.0f + a;
|
k1 = typename detail::tquat<T>::value_type(0) + a; //BUG!!! 1.0f + a;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
typename detail::tquat<T>::value_type fSin = sqrt(T(1) - fCos * fCos);
|
typename detail::tquat<T>::value_type fSin = sqrt(T(1) - fCos * fCos);
|
||||||
typename detail::tquat<T>::value_type fAngle = atan(fSin, fCos);
|
typename detail::tquat<T>::value_type fAngle = atan(fSin, fCos);
|
||||||
typename detail::tquat<T>::value_type fOneOverSin = T(1) / fSin;
|
typename detail::tquat<T>::value_type fOneOverSin = T(1) / fSin;
|
||||||
k0 = sin((typename detail::tquat<T>::value_type(1) - a) * fAngle) * fOneOverSin;
|
k0 = sin((typename detail::tquat<T>::value_type(1) - a) * fAngle) * fOneOverSin;
|
||||||
k1 = sin((typename detail::tquat<T>::value_type(0) + a) * fAngle) * fOneOverSin;
|
k1 = sin((typename detail::tquat<T>::value_type(0) + a) * fAngle) * fOneOverSin;
|
||||||
}
|
}
|
||||||
|
|
||||||
return detail::tquat<T>(
|
return detail::tquat<T>(
|
||||||
k0 * x.w + k1 * y2.w,
|
k0 * x.w + k1 * y2.w,
|
||||||
k0 * x.x + k1 * y2.x,
|
k0 * x.x + k1 * y2.x,
|
||||||
k0 * x.y + k1 * y2.y,
|
k0 * x.y + k1 * y2.y,
|
||||||
k0 * x.z + k1 * y2.z);
|
k0 * x.z + k1 * y2.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> mix2
|
GLM_FUNC_QUALIFIER detail::tquat<T> mix2
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & x,
|
detail::tquat<T> const & x,
|
||||||
detail::tquat<T> const & y,
|
detail::tquat<T> const & y,
|
||||||
T const & a
|
T const & a
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
bool flip = false;
|
bool flip = false;
|
||||||
if(a <= T(0)) return x;
|
if(a <= T(0)) return x;
|
||||||
if(a >= T(1)) return y;
|
if(a >= T(1)) return y;
|
||||||
|
|
||||||
T cos_t = dot(x, y);
|
T cos_t = dot(x, y);
|
||||||
if(cos_t < T(0))
|
if(cos_t < T(0))
|
||||||
{
|
{
|
||||||
cos_t = -cos_t;
|
cos_t = -cos_t;
|
||||||
@ -440,180 +440,180 @@ namespace detail
|
|||||||
if(flip)
|
if(flip)
|
||||||
alpha = -alpha;
|
alpha = -alpha;
|
||||||
|
|
||||||
return normalize(beta * x + alpha * y);
|
return normalize(beta * x + alpha * y);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> mix
|
GLM_FUNC_QUALIFIER detail::tquat<T> mix
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & x,
|
detail::tquat<T> const & x,
|
||||||
detail::tquat<T> const & y,
|
detail::tquat<T> const & y,
|
||||||
T const & a
|
T const & a
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
T angle = acos(dot(x, y));
|
T angle = acos(dot(x, y));
|
||||||
return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle);
|
return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> conjugate
|
GLM_FUNC_QUALIFIER detail::tquat<T> conjugate
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tquat<T>(q.w, -q.x, -q.y, -q.z);
|
return detail::tquat<T>(q.w, -q.x, -q.y, -q.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> inverse
|
GLM_FUNC_QUALIFIER detail::tquat<T> inverse
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return conjugate(q) / dot(q, q);
|
return conjugate(q) / dot(q, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> rotate
|
GLM_FUNC_QUALIFIER detail::tquat<T> rotate
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q,
|
detail::tquat<T> const & q,
|
||||||
typename detail::tquat<T>::value_type const & angle,
|
typename detail::tquat<T>::value_type const & angle,
|
||||||
detail::tvec3<T> const & v
|
detail::tvec3<T> const & v
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
detail::tvec3<T> Tmp = v;
|
detail::tvec3<T> Tmp = v;
|
||||||
|
|
||||||
// Axis of rotation must be normalised
|
// Axis of rotation must be normalised
|
||||||
typename detail::tquat<T>::value_type len = glm::length(Tmp);
|
typename detail::tquat<T>::value_type len = glm::length(Tmp);
|
||||||
if(abs(len - T(1)) > T(0.001))
|
if(abs(len - T(1)) > T(0.001))
|
||||||
{
|
{
|
||||||
T oneOverLen = T(1) / len;
|
T oneOverLen = T(1) / len;
|
||||||
Tmp.x *= oneOverLen;
|
Tmp.x *= oneOverLen;
|
||||||
Tmp.y *= oneOverLen;
|
Tmp.y *= oneOverLen;
|
||||||
Tmp.z *= oneOverLen;
|
Tmp.z *= oneOverLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GLM_FORCE_RADIANS
|
#ifdef GLM_FORCE_RADIANS
|
||||||
typename detail::tquat<T>::value_type const AngleRad(angle);
|
typename detail::tquat<T>::value_type const AngleRad(angle);
|
||||||
#else
|
#else
|
||||||
typename detail::tquat<T>::value_type const AngleRad = radians(angle);
|
typename detail::tquat<T>::value_type const AngleRad = radians(angle);
|
||||||
#endif
|
#endif
|
||||||
typename detail::tquat<T>::value_type const Sin = sin(AngleRad * T(0.5));
|
typename detail::tquat<T>::value_type const Sin = sin(AngleRad * T(0.5));
|
||||||
|
|
||||||
return q * detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
|
return q * detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
|
||||||
//return gtc::quaternion::cross(q, detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
|
//return gtc::quaternion::cross(q, detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tvec3<T> eulerAngles
|
GLM_FUNC_QUALIFIER detail::tvec3<T> eulerAngles
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & x
|
detail::tquat<T> const & x
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec3<T>(pitch(x), yaw(x), roll(x));
|
return detail::tvec3<T>(pitch(x), yaw(x), roll(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tmat3x3<T> mat3_cast
|
GLM_FUNC_QUALIFIER detail::tmat3x3<T> mat3_cast
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
detail::tmat3x3<T> Result(T(1));
|
detail::tmat3x3<T> Result(T(1));
|
||||||
Result[0][0] = 1 - 2 * q.y * q.y - 2 * q.z * q.z;
|
Result[0][0] = 1 - 2 * q.y * q.y - 2 * q.z * q.z;
|
||||||
Result[0][1] = 2 * q.x * q.y + 2 * q.w * q.z;
|
Result[0][1] = 2 * q.x * q.y + 2 * q.w * q.z;
|
||||||
Result[0][2] = 2 * q.x * q.z - 2 * q.w * q.y;
|
Result[0][2] = 2 * q.x * q.z - 2 * q.w * q.y;
|
||||||
|
|
||||||
Result[1][0] = 2 * q.x * q.y - 2 * q.w * q.z;
|
Result[1][0] = 2 * q.x * q.y - 2 * q.w * q.z;
|
||||||
Result[1][1] = 1 - 2 * q.x * q.x - 2 * q.z * q.z;
|
Result[1][1] = 1 - 2 * q.x * q.x - 2 * q.z * q.z;
|
||||||
Result[1][2] = 2 * q.y * q.z + 2 * q.w * q.x;
|
Result[1][2] = 2 * q.y * q.z + 2 * q.w * q.x;
|
||||||
|
|
||||||
Result[2][0] = 2 * q.x * q.z + 2 * q.w * q.y;
|
Result[2][0] = 2 * q.x * q.z + 2 * q.w * q.y;
|
||||||
Result[2][1] = 2 * q.y * q.z - 2 * q.w * q.x;
|
Result[2][1] = 2 * q.y * q.z - 2 * q.w * q.x;
|
||||||
Result[2][2] = 1 - 2 * q.x * q.x - 2 * q.y * q.y;
|
Result[2][2] = 1 - 2 * q.x * q.x - 2 * q.y * q.y;
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T> mat4_cast
|
GLM_FUNC_QUALIFIER detail::tmat4x4<T> mat4_cast
|
||||||
(
|
(
|
||||||
detail::tquat<T> const & q
|
detail::tquat<T> const & q
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tmat4x4<T>(mat3_cast(q));
|
return detail::tmat4x4<T>(mat3_cast(q));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> quat_cast
|
GLM_FUNC_QUALIFIER detail::tquat<T> quat_cast
|
||||||
(
|
(
|
||||||
detail::tmat3x3<T> const & m
|
detail::tmat3x3<T> const & m
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
typename detail::tquat<T>::value_type fourXSquaredMinus1 = m[0][0] - m[1][1] - m[2][2];
|
typename detail::tquat<T>::value_type fourXSquaredMinus1 = m[0][0] - m[1][1] - m[2][2];
|
||||||
typename detail::tquat<T>::value_type fourYSquaredMinus1 = m[1][1] - m[0][0] - m[2][2];
|
typename detail::tquat<T>::value_type fourYSquaredMinus1 = m[1][1] - m[0][0] - m[2][2];
|
||||||
typename detail::tquat<T>::value_type fourZSquaredMinus1 = m[2][2] - m[0][0] - m[1][1];
|
typename detail::tquat<T>::value_type fourZSquaredMinus1 = m[2][2] - m[0][0] - m[1][1];
|
||||||
typename detail::tquat<T>::value_type fourWSquaredMinus1 = m[0][0] + m[1][1] + m[2][2];
|
typename detail::tquat<T>::value_type fourWSquaredMinus1 = m[0][0] + m[1][1] + m[2][2];
|
||||||
|
|
||||||
int biggestIndex = 0;
|
int biggestIndex = 0;
|
||||||
typename detail::tquat<T>::value_type fourBiggestSquaredMinus1 = fourWSquaredMinus1;
|
typename detail::tquat<T>::value_type fourBiggestSquaredMinus1 = fourWSquaredMinus1;
|
||||||
if(fourXSquaredMinus1 > fourBiggestSquaredMinus1)
|
if(fourXSquaredMinus1 > fourBiggestSquaredMinus1)
|
||||||
{
|
{
|
||||||
fourBiggestSquaredMinus1 = fourXSquaredMinus1;
|
fourBiggestSquaredMinus1 = fourXSquaredMinus1;
|
||||||
biggestIndex = 1;
|
biggestIndex = 1;
|
||||||
}
|
}
|
||||||
if(fourYSquaredMinus1 > fourBiggestSquaredMinus1)
|
if(fourYSquaredMinus1 > fourBiggestSquaredMinus1)
|
||||||
{
|
{
|
||||||
fourBiggestSquaredMinus1 = fourYSquaredMinus1;
|
fourBiggestSquaredMinus1 = fourYSquaredMinus1;
|
||||||
biggestIndex = 2;
|
biggestIndex = 2;
|
||||||
}
|
}
|
||||||
if(fourZSquaredMinus1 > fourBiggestSquaredMinus1)
|
if(fourZSquaredMinus1 > fourBiggestSquaredMinus1)
|
||||||
{
|
{
|
||||||
fourBiggestSquaredMinus1 = fourZSquaredMinus1;
|
fourBiggestSquaredMinus1 = fourZSquaredMinus1;
|
||||||
biggestIndex = 3;
|
biggestIndex = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
typename detail::tquat<T>::value_type biggestVal = sqrt(fourBiggestSquaredMinus1 + T(1)) * T(0.5);
|
typename detail::tquat<T>::value_type biggestVal = sqrt(fourBiggestSquaredMinus1 + T(1)) * T(0.5);
|
||||||
typename detail::tquat<T>::value_type mult = T(0.25) / biggestVal;
|
typename detail::tquat<T>::value_type mult = T(0.25) / biggestVal;
|
||||||
|
|
||||||
detail::tquat<T> Result;
|
detail::tquat<T> Result;
|
||||||
switch(biggestIndex)
|
switch(biggestIndex)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
Result.w = biggestVal;
|
Result.w = biggestVal;
|
||||||
Result.x = (m[1][2] - m[2][1]) * mult;
|
Result.x = (m[1][2] - m[2][1]) * mult;
|
||||||
Result.y = (m[2][0] - m[0][2]) * mult;
|
Result.y = (m[2][0] - m[0][2]) * mult;
|
||||||
Result.z = (m[0][1] - m[1][0]) * mult;
|
Result.z = (m[0][1] - m[1][0]) * mult;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Result.w = (m[1][2] - m[2][1]) * mult;
|
Result.w = (m[1][2] - m[2][1]) * mult;
|
||||||
Result.x = biggestVal;
|
Result.x = biggestVal;
|
||||||
Result.y = (m[0][1] + m[1][0]) * mult;
|
Result.y = (m[0][1] + m[1][0]) * mult;
|
||||||
Result.z = (m[2][0] + m[0][2]) * mult;
|
Result.z = (m[2][0] + m[0][2]) * mult;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Result.w = (m[2][0] - m[0][2]) * mult;
|
Result.w = (m[2][0] - m[0][2]) * mult;
|
||||||
Result.x = (m[0][1] + m[1][0]) * mult;
|
Result.x = (m[0][1] + m[1][0]) * mult;
|
||||||
Result.y = biggestVal;
|
Result.y = biggestVal;
|
||||||
Result.z = (m[1][2] + m[2][1]) * mult;
|
Result.z = (m[1][2] + m[2][1]) * mult;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Result.w = (m[0][1] - m[1][0]) * mult;
|
Result.w = (m[0][1] - m[1][0]) * mult;
|
||||||
Result.x = (m[2][0] + m[0][2]) * mult;
|
Result.x = (m[2][0] + m[0][2]) * mult;
|
||||||
Result.y = (m[1][2] + m[2][1]) * mult;
|
Result.y = (m[1][2] + m[2][1]) * mult;
|
||||||
Result.z = biggestVal;
|
Result.z = biggestVal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER detail::tquat<T> quat_cast
|
GLM_FUNC_QUALIFIER detail::tquat<T> quat_cast
|
||||||
(
|
(
|
||||||
detail::tmat4x4<T> const & m4
|
detail::tmat4x4<T> const & m4
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return quat_cast(detail::tmat3x3<T>(m4));
|
return quat_cast(detail::tmat3x3<T>(m4));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER T angle
|
GLM_FUNC_QUALIFIER T angle
|
||||||
|
Loading…
Reference in New Issue
Block a user