13 #ifndef OGLPLUS_MATH_QUATERNION_1310291021_HPP
14 #define OGLPLUS_MATH_QUATERNION_1310291021_HPP
28 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_FLOAT)
37 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_DOUBLE)
96 T At(std::size_t index)
const
99 if(index == 0)
return _a;
100 if(index == 1)
return _x;
101 if(index == 2)
return _y;
102 if(index == 3)
return _z;
106 #if OGLPLUS_DOCUMENTATION_ONLY
112 return q1._a*q2._a + q1._x*q2._x + q1._y*q2._y + q1._z*q2._z;
118 return std::sqrt(DotProduct(*
this, *
this));
128 return std::abs(DotProduct(*
this, *
this) -
T(1)) <= eps;
144 return DotProduct(*
this, *
this) <= eps;
167 return (q1._a == q2._a) &&
176 for(std::size_t i=0; i!=4; ++i)
181 bool ca = d <= std::abs(u)*eps;
182 bool cb = d <= std::abs(v)*eps;
183 if(!ca && !cb)
return false;
191 return Equal(q1, q2);
197 return !
Equal(q1, q2);
200 #if OGLPLUS_DOCUMENTATION_ONLY
207 return Quaternion(q1._a,-q1._x,-q1._y,-q1._z);
216 #if OGLPLUS_DOCUMENTATION_ONLY
223 T id = DotProduct(q1, q1);
234 #if OGLPLUS_DOCUMENTATION_ONLY
252 return Added(q1, q2);
255 #if OGLPLUS_DOCUMENTATION_ONLY
263 q1._a*q2._a - q1._x*q2._x - q1._y*q2._y - q1._z*q2._z,
264 q1._a*q2._x + q1._x*q2._a + q1._y*q2._z - q1._z*q2._y,
265 q1._a*q2._y - q1._x*q2._z + q1._y*q2._a + q1._z*q2._x,
266 q1._a*q2._z + q1._x*q2._y - q1._y*q2._x + q1._z*q2._a
273 return Multiplied(q1, q2);
278 return Quaternion(q1._a*t, q1._x*t, q1._y*t, q1._z*t);
284 return Multiplied(q1, t);
290 return Multiplied(q1, t);
293 #if OGLPLUS_DOCUMENTATION_ONLY
310 template <
typename T>
311 inline T Dot(
const Quaternion<T>& q1,
const Quaternion<T>& q2)
313 return Quaternion<T>::DotProduct(q1, q2);
316 template <
typename T>
317 inline T Magnitude(
const Quaternion<T>& q1)
319 return q1.Magnitude();
322 template <
typename T>
328 template <
typename T>
334 template <
typename T>
340 template <
typename T>
346 template <
typename T>
358 template <
typename T>
359 class QuaternionSLERP
360 :
public BaseSLERP<Quaternion<T>, T>
377 #endif // include guard
friend Quaternion operator+(const Quaternion &q1, const Quaternion &q2)
Addition operator.
Definition: quaternion.hpp:250
Template class for quaternions.
Definition: fwd.hpp:59
bool IsUnit(T eps=T(0)) const
Returns true if the quaternion has unit Magnitude.
Definition: quaternion.hpp:126
Quaternion(Vector< T, 3 > axis, Angle< T > angle)
Construct a Quaternion from an axis and an angle.
Definition: quaternion.hpp:65
Vector< T, 3 > Rotate(const Quaternion< T > &q, const Vector< T, 3 > &v)
Definition: quaternion.hpp:347
Class implementing planar angle-related functionality.
Definition: fwd.hpp:24
Definition: vector.hpp:14
Functor template for quaternion spherical-linear interpolation.
Definition: quaternion.hpp:26
Quaternion(T a, T x, T y, T z)
Constructs a quaternion.
Definition: quaternion.hpp:57
friend bool operator==(const Quaternion &q1, const Quaternion &q2)
Equality comparison.
Definition: quaternion.hpp:189
friend bool Close(const Quaternion &q1, const Quaternion &q2, T eps)
Near-equality comparison.
Definition: quaternion.hpp:174
Quaternion< GLfloat > Quatf
Float quaternion.
Definition: quaternion.hpp:26
A template for spherical-linear interpolation.
bool IsDegenerate(T eps=T(0)) const
Returns true if the quaternion has zero Magnitude.
Definition: quaternion.hpp:142
friend bool operator!=(const Quaternion &q1, const Quaternion &q2)
Non-equality comparison.
Definition: quaternion.hpp:195
Vector< T, 3 > Imag(void) const
Returns the imaginary vector part of the quaternion.
Definition: quaternion.hpp:91
Quaternion< GLdouble > Quatd
Double-precision quaternion.
Definition: quaternion.hpp:42
friend Quaternion Add(const Quaternion &q1, const Quaternion &q2)
Quaternion addition.
Definition: quaternion.hpp:335
Quaternion & Normalize(void)
Normalizes this quaternion.
Definition: quaternion.hpp:152
void Normalize(void)
Normalizes this vector.
Definition: vector.hpp:326
T Magnitude(void) const
Returns the magnitude of the quaternion.
Definition: quaternion.hpp:116
QuaternionSLERP(const Quaternion< T > &q1, const Quaternion< T > &q2, T eps=0.001)
Constructs a SLERP functor from two unit quaternions.
Definition: quaternion.hpp:367
friend Quaternion Multiply(const Quaternion &q1, const Quaternion &q2)
Quaternion multiplication.
Definition: quaternion.hpp:341
friend Quaternion Conjugate(const Quaternion &q1)
Conjugate quaternion.
Definition: quaternion.hpp:323
friend bool Equal(const Quaternion &q1, const Quaternion &q2)
Equality comparison.
Definition: quaternion.hpp:165
friend Vector< T, 3 > Rotate(const Quaternion &q, const Vector< T, 3 > &v)
Rotate a vector by this quaternion.
Definition: quaternion.hpp:347
friend Quaternion Inverse(const Quaternion &q1)
Inverse quaternion.
Definition: quaternion.hpp:329
Base template for spherical-linear interpolation functors.
Definition: slerp.hpp:28
Quaternion(T real, const Vector< T, 3 > &imag)
Construct q Quaternion from the real and imag parts.
Definition: quaternion.hpp:77
friend Quaternion operator~(const Quaternion &q1)
Conjugation.
Definition: quaternion.hpp:211
friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2)
Multiplication operator.
Definition: quaternion.hpp:271
bool IsNormal(T eps=T(0)) const
Synonym for IsUnit.
Definition: quaternion.hpp:136
T Real(void) const
Returns the real scalar part of the quaternion.
Definition: quaternion.hpp:85