summaryrefslogtreecommitdiffstats
path: root/external/include/glm/gtc/quaternion.inl
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 17:40:38 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 17:40:38 +0200
commit2877f4eda3d1b0c7431039e3142ecf1a282a34b1 (patch)
tree58ad35e27ab2a3b8955f5adbf28f296670681ffc /external/include/glm/gtc/quaternion.inl
parentSmooth sun movement (diff)
downloadAltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.gz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.bz2
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.lz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.xz
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.zst
AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.zip
Diffstat (limited to 'external/include/glm/gtc/quaternion.inl')
-rw-r--r--external/include/glm/gtc/quaternion.inl533
1 files changed, 273 insertions, 260 deletions
diff --git a/external/include/glm/gtc/quaternion.inl b/external/include/glm/gtc/quaternion.inl
index c9b2af7..df4a5f7 100644
--- a/external/include/glm/gtc/quaternion.inl
+++ b/external/include/glm/gtc/quaternion.inl
@@ -4,78 +4,80 @@
#include "../trigonometric.hpp"
#include "../geometric.hpp"
#include "../exponential.hpp"
+#include "../detail/compute_vector_relational.hpp"
+#include "epsilon.hpp"
#include <limits>
namespace glm{
namespace detail
{
- template <typename T, precision P, bool Aligned>
- struct compute_dot<tquat, T, P, Aligned>
+ template<typename T, qualifier Q, bool Aligned>
+ struct compute_dot<tquat<T, Q>, T, Aligned>
{
- static GLM_FUNC_QUALIFIER T call(tquat<T, P> const& x, tquat<T, P> const& y)
+ static GLM_FUNC_QUALIFIER T call(tquat<T, Q> const& a, tquat<T, Q> const& b)
{
- tvec4<T, P> tmp(x.x * y.x, x.y * y.y, x.z * y.z, x.w * y.w);
+ vec<4, T, Q> tmp(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
return (tmp.x + tmp.y) + (tmp.z + tmp.w);
}
};
- template <typename T, precision P, bool Aligned>
+ template<typename T, qualifier Q, bool Aligned>
struct compute_quat_add
{
- static tquat<T, P> call(tquat<T, P> const& q, tquat<T, P> const& p)
+ static tquat<T, Q> call(tquat<T, Q> const& q, tquat<T, Q> const& p)
{
- return tquat<T, P>(q.w + p.w, q.x + p.x, q.y + p.y, q.z + p.z);
+ return tquat<T, Q>(q.w + p.w, q.x + p.x, q.y + p.y, q.z + p.z);
}
};
- template <typename T, precision P, bool Aligned>
+ template<typename T, qualifier Q, bool Aligned>
struct compute_quat_sub
{
- static tquat<T, P> call(tquat<T, P> const& q, tquat<T, P> const& p)
+ static tquat<T, Q> call(tquat<T, Q> const& q, tquat<T, Q> const& p)
{
- return tquat<T, P>(q.w - p.w, q.x - p.x, q.y - p.y, q.z - p.z);
+ return tquat<T, Q>(q.w - p.w, q.x - p.x, q.y - p.y, q.z - p.z);
}
};
- template <typename T, precision P, bool Aligned>
+ template<typename T, qualifier Q, bool Aligned>
struct compute_quat_mul_scalar
{
- static tquat<T, P> call(tquat<T, P> const& q, T s)
+ static tquat<T, Q> call(tquat<T, Q> const& q, T s)
{
- return tquat<T, P>(q.w * s, q.x * s, q.y * s, q.z * s);
+ return tquat<T, Q>(q.w * s, q.x * s, q.y * s, q.z * s);
}
};
- template <typename T, precision P, bool Aligned>
+ template<typename T, qualifier Q, bool Aligned>
struct compute_quat_div_scalar
{
- static tquat<T, P> call(tquat<T, P> const& q, T s)
+ static tquat<T, Q> call(tquat<T, Q> const& q, T s)
{
- return tquat<T, P>(q.w / s, q.x / s, q.y / s, q.z / s);
+ return tquat<T, Q>(q.w / s, q.x / s, q.y / s, q.z / s);
}
};
- template <typename T, precision P, bool Aligned>
+ template<typename T, qualifier Q, bool Aligned>
struct compute_quat_mul_vec4
{
- static tvec4<T, P> call(tquat<T, P> const & q, tvec4<T, P> const & v)
+ static vec<4, T, Q> call(tquat<T, Q> const& q, vec<4, T, Q> const& v)
{
- return tvec4<T, P>(q * tvec3<T, P>(v), v.w);
+ return vec<4, T, Q>(q * vec<3, T, Q>(v), v.w);
}
};
}//namespace detail
// -- Component accesses --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T & tquat<T, P>::operator[](typename tquat<T, P>::length_type i)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T & tquat<T, Q>::operator[](typename tquat<T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
return (&x)[i];
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T const & tquat<T, P>::operator[](typename tquat<T, P>::length_type i) const
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T const& tquat<T, Q>::operator[](typename tquat<T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
return (&x)[i];
@@ -83,129 +85,139 @@ namespace detail
// -- Implicit basic constructors --
-# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat()
-# ifndef GLM_FORCE_NO_CTOR_INIT
- : x(0), y(0), z(0), w(1)
+# if !GLM_HAS_DEFAULTED_FUNCTIONS || defined(GLM_FORCE_CTOR_INIT)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat()
+# ifdef GLM_FORCE_CTOR_INIT
+ : x(0), y(0), z(0), w(1)
# endif
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat(tquat<T, Q> const& q)
: x(q.x), y(q.y), z(q.z), w(q.w)
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
- template <typename T, precision P>
- template <precision Q>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat(tquat<T, Q> const & q)
+ template<typename T, qualifier Q>
+ template<qualifier P>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat(tquat<T, P> const& q)
: x(q.x), y(q.y), z(q.z), w(q.w)
{}
// -- Explicit basic constructors --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tquat<T, P>::tquat(ctor)
- {}
-
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat(T const & s, tvec3<T, P> const & v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat(T s, vec<3, T, Q> const& v)
: x(v.x), y(v.y), z(v.z), w(s)
{}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat(T const & w, T const & x, T const & y, T const & z)
- : x(x), y(y), z(z), w(w)
+ template <typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat(T _w, T _x, T _y, T _z)
+ : x(_x), y(_y), z(_z), w(_w)
{}
// -- Conversion constructors --
- template <typename T, precision P>
- template <typename U, precision Q>
- GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat(tquat<U, Q> const & q)
+ template<typename T, qualifier Q>
+ template<typename U, qualifier P>
+ GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, Q>::tquat(tquat<U, P> const& q)
: x(static_cast<T>(q.x))
, y(static_cast<T>(q.y))
, z(static_cast<T>(q.z))
, w(static_cast<T>(q.w))
{}
- //template <typename valType>
+ //template<typename valType>
//GLM_FUNC_QUALIFIER tquat<valType>::tquat
//(
- // valType const & pitch,
- // valType const & yaw,
- // valType const & roll
+ // valType const& pitch,
+ // valType const& yaw,
+ // valType const& roll
//)
//{
- // tvec3<valType> eulerAngle(pitch * valType(0.5), yaw * valType(0.5), roll * valType(0.5));
- // tvec3<valType> c = glm::cos(eulerAngle * valType(0.5));
- // tvec3<valType> s = glm::sin(eulerAngle * valType(0.5));
- //
+ // vec<3, valType> eulerAngle(pitch * valType(0.5), yaw * valType(0.5), roll * valType(0.5));
+ // vec<3, valType> c = glm::cos(eulerAngle * valType(0.5));
+ // vec<3, valType> s = glm::sin(eulerAngle * valType(0.5));
+ //
// this->w = c.x * c.y * c.z + s.x * s.y * s.z;
// this->x = s.x * c.y * c.z - c.x * s.y * s.z;
// this->y = c.x * s.y * c.z + s.x * c.y * s.z;
// this->z = c.x * c.y * s.z - s.x * s.y * c.z;
//}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tvec3<T, P> const & u, tvec3<T, P> const & v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::tquat(vec<3, T, Q> const& u, vec<3, T, Q> const& v)
{
- tvec3<T, P> const LocalW(cross(u, v));
- T Dot = detail::compute_dot<tvec3, T, P, detail::is_aligned<P>::value>::call(u, v);
- tquat<T, P> q(T(1) + Dot, LocalW.x, LocalW.y, LocalW.z);
+ T norm_u_norm_v = sqrt(dot(u, u) * dot(v, v));
+ T real_part = norm_u_norm_v + dot(u, v);
+ vec<3, T, Q> t;
+
+ if(real_part < static_cast<T>(1.e-6f) * norm_u_norm_v)
+ {
+ // If u and v are exactly opposite, rotate 180 degrees
+ // around an arbitrary orthogonal axis. Axis normalisation
+ // can happen later, when we normalise the quaternion.
+ real_part = static_cast<T>(0);
+ t = abs(u.x) > abs(u.z) ? vec<3, T, Q>(-u.y, u.x, static_cast<T>(0)) : vec<3, T, Q>(static_cast<T>(0), -u.z, u.y);
+ }
+ else
+ {
+ // Otherwise, build quaternion the standard way.
+ t = cross(u, v);
+ }
- *this = normalize(q);
+ *this = normalize(tquat<T, Q>(real_part, t.x, t.y, t.z));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tvec3<T, P> const & eulerAngle)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::tquat(vec<3, T, Q> const& eulerAngle)
{
- tvec3<T, P> c = glm::cos(eulerAngle * T(0.5));
- tvec3<T, P> s = glm::sin(eulerAngle * T(0.5));
-
+ vec<3, T, Q> c = glm::cos(eulerAngle * T(0.5));
+ vec<3, T, Q> s = glm::sin(eulerAngle * T(0.5));
+
this->w = c.x * c.y * c.z + s.x * s.y * s.z;
this->x = s.x * c.y * c.z - c.x * s.y * s.z;
this->y = c.x * s.y * c.z + s.x * c.y * s.z;
this->z = c.x * c.y * s.z - s.x * s.y * c.z;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tmat3x3<T, P> const & m)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::tquat(mat<3, 3, T, Q> const& m)
{
*this = quat_cast(m);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tmat4x4<T, P> const & m)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::tquat(mat<4, 4, T, Q> const& m)
{
*this = quat_cast(m);
}
# if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::operator tmat3x3<T, P>()
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::operator mat<3, 3, T, Q>()
{
return mat3_cast(*this);
}
-
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P>::operator tmat4x4<T, P>()
+
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q>::operator mat<4, 4, T, Q>()
{
return mat4_cast(*this);
}
# endif//GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> conjugate(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> conjugate(tquat<T, Q> const& q)
{
- return tquat<T, P>(q.w, -q.x, -q.y, -q.z);
+ return tquat<T, Q>(q.w, -q.x, -q.y, -q.z);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> inverse(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> inverse(tquat<T, Q> const& q)
{
return conjugate(q) / dot(q, q);
}
@@ -213,8 +225,8 @@ namespace detail
// -- Unary arithmetic operators --
# if !GLM_HAS_DEFAULTED_FUNCTIONS
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator=(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator=(tquat<T, Q> const& q)
{
this->w = q.w;
this->x = q.x;
@@ -224,9 +236,9 @@ namespace detail
}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator=(tquat<U, P> const & q)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator=(tquat<U, Q> const& q)
{
this->w = static_cast<T>(q.w);
this->x = static_cast<T>(q.x);
@@ -235,26 +247,26 @@ namespace detail
return *this;
}
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator+=(tquat<U, P> const& q)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator+=(tquat<U, Q> const& q)
{
- return (*this = detail::compute_quat_add<T, P, detail::is_aligned<P>::value>::call(*this, tquat<T, P>(q)));
+ return (*this = detail::compute_quat_add<T, Q, detail::is_aligned<Q>::value>::call(*this, tquat<T, Q>(q)));
}
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator-=(tquat<U, P> const& q)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator-=(tquat<U, Q> const& q)
{
- return (*this = detail::compute_quat_sub<T, P, detail::is_aligned<P>::value>::call(*this, tquat<T, P>(q)));
+ return (*this = detail::compute_quat_sub<T, Q, detail::is_aligned<Q>::value>::call(*this, tquat<T, Q>(q)));
}
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator*=(tquat<U, P> const & r)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator*=(tquat<U, Q> const& r)
{
- tquat<T, P> const p(*this);
- tquat<T, P> const q(r);
+ tquat<T, Q> const p(*this);
+ tquat<T, Q> const q(r);
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;
@@ -263,132 +275,145 @@ namespace detail
return *this;
}
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator*=(U s)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator*=(U s)
{
- return (*this = detail::compute_quat_mul_scalar<T, P, detail::is_aligned<P>::value>::call(*this, static_cast<U>(s)));
+ return (*this = detail::compute_quat_mul_scalar<T, Q, detail::is_aligned<Q>::value>::call(*this, static_cast<U>(s)));
}
- template <typename T, precision P>
- template <typename U>
- GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator/=(U s)
+ template<typename T, qualifier Q>
+ template<typename U>
+ GLM_FUNC_QUALIFIER tquat<T, Q> & tquat<T, Q>::operator/=(U s)
{
- return (*this = detail::compute_quat_div_scalar<T, P, detail::is_aligned<P>::value>::call(*this, static_cast<U>(s)));
+ return (*this = detail::compute_quat_div_scalar<T, Q, detail::is_aligned<Q>::value>::call(*this, static_cast<U>(s)));
}
// -- Unary bit operators --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator+(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator+(tquat<T, Q> const& q)
{
return q;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator-(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator-(tquat<T, Q> const& q)
{
- return tquat<T, P>(-q.w, -q.x, -q.y, -q.z);
+ return tquat<T, Q>(-q.w, -q.x, -q.y, -q.z);
}
// -- Binary operators --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator+(tquat<T, P> const & q, tquat<T, P> const & p)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator+(tquat<T, Q> const& q, tquat<T, Q> const& p)
{
- return tquat<T, P>(q) += p;
+ return tquat<T, Q>(q) += p;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator*(tquat<T, P> const & q, tquat<T, P> const & p)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator-(tquat<T, Q> const& q, tquat<T, Q> const& p)
{
- return tquat<T, P>(q) *= p;
+ return tquat<T, Q>(q) -= p;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec3<T, P> operator*(tquat<T, P> const & q, tvec3<T, P> const & v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator*(tquat<T, Q> const& q, tquat<T, Q> const& p)
{
- tvec3<T, P> const QuatVector(q.x, q.y, q.z);
- tvec3<T, P> const uv(glm::cross(QuatVector, v));
- tvec3<T, P> const uuv(glm::cross(QuatVector, uv));
+ return tquat<T, Q>(q) *= p;
+ }
+
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<3, T, Q> operator*(tquat<T, Q> const& q, vec<3, T, Q> const& v)
+ {
+ vec<3, T, Q> const QuatVector(q.x, q.y, q.z);
+ vec<3, T, Q> const uv(glm::cross(QuatVector, v));
+ vec<3, T, Q> const uuv(glm::cross(QuatVector, uv));
return v + ((uv * q.w) + uuv) * static_cast<T>(2);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec3<T, P> operator*(tvec3<T, P> const & v, tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<3, T, Q> operator*(vec<3, T, Q> const& v, tquat<T, Q> const& q)
{
return glm::inverse(q) * v;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tquat<T, P> const& q, tvec4<T, P> const& v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, T, Q> operator*(tquat<T, Q> const& q, vec<4, T, Q> const& v)
{
- return detail::compute_quat_mul_vec4<T, P, detail::is_aligned<P>::value>::call(q, v);
+ return detail::compute_quat_mul_vec4<T, Q, detail::is_aligned<Q>::value>::call(q, v);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<T, P> operator*(tvec4<T, P> const & v, tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, T, Q> operator*(vec<4, T, Q> const& v, tquat<T, Q> const& q)
{
return glm::inverse(q) * v;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator*(tquat<T, P> const & q, T const & s)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator*(tquat<T, Q> const& q, T const& s)
{
- return tquat<T, P>(
+ return tquat<T, Q>(
q.w * s, q.x * s, q.y * s, q.z * s);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator*(T const & s, tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator*(T const& s, tquat<T, Q> const& q)
{
return q * s;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> operator/(tquat<T, P> const & q, T const & s)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> operator/(tquat<T, Q> const& q, T const& s)
{
- return tquat<T, P>(
+ return tquat<T, Q>(
q.w / s, q.x / s, q.y / s, q.z / s);
}
// -- Boolean operators --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER bool operator==(tquat<T, P> const & q1, tquat<T, P> const & q2)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER bool operator==(tquat<T, Q> const& q1, tquat<T, Q> const& q2)
{
- return (q1.x == q2.x) && (q1.y == q2.y) && (q1.z == q2.z) && (q1.w == q2.w);
+ return all(epsilonEqual(q1, q2, epsilon<T>()));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER bool operator!=(tquat<T, P> const & q1, tquat<T, P> const & q2)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER bool operator!=(tquat<T, Q> const& q1, tquat<T, Q> const& q2)
{
- return (q1.x != q2.x) || (q1.y != q2.y) || (q1.z != q2.z) || (q1.w != q2.w);
+ return any(epsilonNotEqual(q1, q2, epsilon<T>()));
}
// -- Operations --
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T length(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T dot(tquat<T, Q> const& x, tquat<T, Q> const& y)
+ {
+ GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs");
+ return detail::compute_dot<tquat<T, Q>, T, detail::is_aligned<Q>::value>::call(x, y);
+ }
+
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T length(tquat<T, Q> const& q)
{
return glm::sqrt(dot(q, q));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> normalize(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> normalize(tquat<T, Q> const& q)
{
T len = length(q);
if(len <= T(0)) // Problem
- return tquat<T, P>(1, 0, 0, 0);
+ return tquat<T, Q>(static_cast<T>(1), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0));
T oneOverLen = T(1) / len;
- return tquat<T, P>(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen);
+ return tquat<T, Q>(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> cross(tquat<T, P> const & q1, tquat<T, P> const & q2)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> cross(tquat<T, Q> const& q1, tquat<T, Q> const& q2)
{
- return tquat<T, P>(
+ return tquat<T, Q>(
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.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z,
@@ -396,14 +421,14 @@ namespace detail
}
/*
// (x * sin(1 - a) * angle / sin(angle)) + (y * sin(a) * angle / sin(angle))
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> mix(tquat<T, P> const & x, tquat<T, P> const & y, T const & a)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> mix(tquat<T, Q> const& x, tquat<T, Q> const& y, T const& a)
{
if(a <= T(0)) return x;
if(a >= T(1)) return y;
float fCos = dot(x, y);
- tquat<T, P> y2(y); //BUG!!! tquat<T, P> y2;
+ tquat<T, Q> y2(y); //BUG!!! tquat<T, Q> y2;
if(fCos < T(0))
{
y2 = -y;
@@ -426,19 +451,19 @@ namespace detail
k1 = sin((T(0) + a) * fAngle) * fOneOverSin;
}
- return tquat<T, P>(
+ return tquat<T, Q>(
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 <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> mix2
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> mix2
(
- tquat<T, P> const & x,
- tquat<T, P> const & y,
- T const & a
+ tquat<T, Q> const& x,
+ tquat<T, Q> const& y,
+ T const& a
)
{
bool flip = false;
@@ -466,13 +491,13 @@ namespace detail
if(flip)
alpha = -alpha;
-
+
return normalize(beta * x + alpha * y);
}
*/
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> mix(tquat<T, P> const & x, tquat<T, P> const & y, T a)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> mix(tquat<T, Q> const& x, tquat<T, Q> const& y, T a)
{
T cosTheta = dot(x, y);
@@ -480,7 +505,7 @@ namespace detail
if(cosTheta > T(1) - epsilon<T>())
{
// Linear interpolation
- return tquat<T, P>(
+ return tquat<T, Q>(
mix(x.w, y.w, a),
mix(x.x, y.x, a),
mix(x.y, y.y, a),
@@ -494,8 +519,8 @@ namespace detail
}
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> lerp(tquat<T, P> const & x, tquat<T, P> const & y, T a)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> lerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a)
{
// Lerp is only defined in [0, 1]
assert(a >= static_cast<T>(0));
@@ -504,14 +529,14 @@ namespace detail
return x * (T(1) - a) + (y * a);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> slerp(tquat<T, P> const & x, tquat<T, P> const & y, T a)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> slerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a)
{
- tquat<T, P> z = y;
+ tquat<T, Q> z = y;
T cosTheta = dot(x, y);
- // If cosTheta < 0, the interpolation will take the long way around the sphere.
+ // If cosTheta < 0, the interpolation will take the long way around the sphere.
// To fix this, one quat must be negated.
if (cosTheta < T(0))
{
@@ -523,7 +548,7 @@ namespace detail
if(cosTheta > T(1) - epsilon<T>())
{
// Linear interpolation
- return tquat<T, P>(
+ return tquat<T, Q>(
mix(x.w, z.w, a),
mix(x.x, z.x, a),
mix(x.y, z.y, a),
@@ -537,10 +562,10 @@ namespace detail
}
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> rotate(tquat<T, P> const & q, T const & angle, tvec3<T, P> const & v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> rotate(tquat<T, Q> const& q, T const& angle, vec<3, T, Q> const& v)
{
- tvec3<T, P> Tmp = v;
+ vec<3, T, Q> Tmp = v;
// Axis of rotation must be normalised
T len = glm::length(Tmp);
@@ -555,38 +580,45 @@ namespace detail
T const AngleRad(angle);
T const Sin = sin(AngleRad * T(0.5));
- return q * tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
- //return gtc::quaternion::cross(q, tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
+ return q * tquat<T, Q>(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
+ //return gtc::quaternion::cross(q, tquat<T, Q>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec3<T, P> eulerAngles(tquat<T, P> const & x)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<3, T, Q> eulerAngles(tquat<T, Q> const& x)
{
- return tvec3<T, P>(pitch(x), yaw(x), roll(x));
+ return vec<3, T, Q>(pitch(x), yaw(x), roll(x));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T roll(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T roll(tquat<T, Q> const& q)
{
- return T(atan(T(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
+ return static_cast<T>(atan(static_cast<T>(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T pitch(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T pitch(tquat<T, Q> const& q)
{
- return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
+ //return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
+ const T y = static_cast<T>(2) * (q.y * q.z + q.w * q.x);
+ const T x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
+
+ if(detail::compute_equal<T>::call(y, static_cast<T>(0)) && detail::compute_equal<T>::call(x, static_cast<T>(0))) //avoid atan2(0,0) - handle singularity - Matiis
+ return static_cast<T>(static_cast<T>(2) * atan(q.x,q.w));
+
+ return static_cast<T>(atan(y,x));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T yaw(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T yaw(tquat<T, Q> const& q)
{
- return asin(clamp(T(-2) * (q.x * q.z - q.w * q.y), T(-1), T(1)));
+ return asin(clamp(static_cast<T>(-2) * (q.x * q.z - q.w * q.y), static_cast<T>(-1), static_cast<T>(1)));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tmat3x3<T, P> mat3_cast(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER mat<3, 3, T, Q> mat3_cast(tquat<T, Q> const& q)
{
- tmat3x3<T, P> Result(T(1));
+ mat<3, 3, T, Q> Result(T(1));
T qxx(q.x * q.x);
T qyy(q.y * q.y);
T qzz(q.z * q.z);
@@ -611,14 +643,14 @@ namespace detail
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tmat4x4<T, P> mat4_cast(tquat<T, P> const & q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER mat<4, 4, T, Q> mat4_cast(tquat<T, Q> const& q)
{
- return tmat4x4<T, P>(mat3_cast(q));
+ return mat<4, 4, T, Q>(mat3_cast(q));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> quat_cast(tmat3x3<T, P> const & m)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> quat_cast(mat<3, 3, T, Q> const& m)
{
T fourXSquaredMinus1 = m[0][0] - m[1][1] - m[2][2];
T fourYSquaredMinus1 = m[1][1] - m[0][0] - m[2][2];
@@ -643,70 +675,51 @@ namespace detail
biggestIndex = 3;
}
- T biggestVal = sqrt(fourBiggestSquaredMinus1 + T(1)) * T(0.5);
+ T biggestVal = sqrt(fourBiggestSquaredMinus1 + static_cast<T>(1)) * static_cast<T>(0.5);
T mult = static_cast<T>(0.25) / biggestVal;
- tquat<T, P> Result(uninitialize);
switch(biggestIndex)
{
case 0:
- Result.w = biggestVal;
- Result.x = (m[1][2] - m[2][1]) * mult;
- Result.y = (m[2][0] - m[0][2]) * mult;
- Result.z = (m[0][1] - m[1][0]) * mult;
- break;
+ return tquat<T, Q>(biggestVal, (m[1][2] - m[2][1]) * mult, (m[2][0] - m[0][2]) * mult, (m[0][1] - m[1][0]) * mult);
case 1:
- Result.w = (m[1][2] - m[2][1]) * mult;
- Result.x = biggestVal;
- Result.y = (m[0][1] + m[1][0]) * mult;
- Result.z = (m[2][0] + m[0][2]) * mult;
- break;
+ return tquat<T, Q>((m[1][2] - m[2][1]) * mult, biggestVal, (m[0][1] + m[1][0]) * mult, (m[2][0] + m[0][2]) * mult);
case 2:
- Result.w = (m[2][0] - m[0][2]) * mult;
- Result.x = (m[0][1] + m[1][0]) * mult;
- Result.y = biggestVal;
- Result.z = (m[1][2] + m[2][1]) * mult;
- break;
+ return tquat<T, Q>((m[2][0] - m[0][2]) * mult, (m[0][1] + m[1][0]) * mult, biggestVal, (m[1][2] + m[2][1]) * mult);
case 3:
- Result.w = (m[0][1] - m[1][0]) * mult;
- Result.x = (m[2][0] + m[0][2]) * mult;
- Result.y = (m[1][2] + m[2][1]) * mult;
- Result.z = biggestVal;
- break;
-
- default: // Silence a -Wswitch-default warning in GCC. Should never actually get here. Assert is just for sanity.
+ return tquat<T, Q>((m[0][1] - m[1][0]) * mult, (m[2][0] + m[0][2]) * mult, (m[1][2] + m[2][1]) * mult, biggestVal);
+ default: // Silence a -Wswitch-default warning in GCC. Should never actually get here. Assert is just for sanity.
assert(false);
- break;
+ return tquat<T, Q>(1, 0, 0, 0);
}
- return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> quat_cast(tmat4x4<T, P> const & m4)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> quat_cast(mat<4, 4, T, Q> const& m4)
{
- return quat_cast(tmat3x3<T, P>(m4));
+ return quat_cast(mat<3, 3, T, Q>(m4));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER T angle(tquat<T, P> const & x)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER T angle(tquat<T, Q> const& x)
{
- return acos(x.w) * T(2);
+ return acos(x.w) * static_cast<T>(2);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec3<T, P> axis(tquat<T, P> const & x)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<3, T, Q> axis(tquat<T, Q> const& x)
{
T tmp1 = static_cast<T>(1) - x.w * x.w;
if(tmp1 <= static_cast<T>(0))
- return tvec3<T, P>(0, 0, 1);
+ return vec<3, T, Q>(0, 0, 1);
T tmp2 = static_cast<T>(1) / sqrt(tmp1);
- return tvec3<T, P>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
+ return vec<3, T, Q>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tquat<T, P> angleAxis(T const & angle, tvec3<T, P> const & v)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER tquat<T, Q> angleAxis(T const& angle, vec<3, T, Q> const& v)
{
- tquat<T, P> Result(uninitialize);
+ tquat<T, Q> Result;
T const a(angle);
T const s = glm::sin(a * static_cast<T>(0.5));
@@ -718,74 +731,74 @@ namespace detail
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> lessThan(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThan(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
Result[i] = x[i] < y[i];
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> lessThanEqual(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
Result[i] = x[i] <= y[i];
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> greaterThan(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThan(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
Result[i] = x[i] > y[i];
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> greaterThanEqual(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
Result[i] = x[i] >= y[i];
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> equal(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
- Result[i] = x[i] == y[i];
+ Result[i] = detail::compute_equal<T>::call(x[i], y[i]);
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> notEqual(tquat<T, P> const & x, tquat<T, P> const & y)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(tquat<T, Q> const& x, tquat<T, Q> const& y)
{
- tvec4<bool, P> Result(uninitialize);
+ vec<4, bool, Q> Result;
for(length_t i = 0; i < x.length(); ++i)
- Result[i] = x[i] != y[i];
+ Result[i] = !detail::compute_equal<T>::call(x[i], y[i]);
return Result;
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> isnan(tquat<T, P> const& q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> isnan(tquat<T, Q> const& q)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
- return tvec4<bool, P>(isnan(q.x), isnan(q.y), isnan(q.z), isnan(q.w));
+ return vec<4, bool, Q>(isnan(q.x), isnan(q.y), isnan(q.z), isnan(q.w));
}
- template <typename T, precision P>
- GLM_FUNC_QUALIFIER tvec4<bool, P> isinf(tquat<T, P> const& q)
+ template<typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<4, bool, Q> isinf(tquat<T, Q> const& q)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isinf' only accept floating-point inputs");
- return tvec4<bool, P>(isinf(q.x), isinf(q.y), isinf(q.z), isinf(q.w));
+ return vec<4, bool, Q>(isinf(q.x), isinf(q.y), isinf(q.z), isinf(q.w));
}
}//namespace glm