2#include <NDEVR/Vector.h>
3#include <NDEVR/Angle.h>
4#include <NDEVR/Matrix.h>
12 template<
class t_angle_type,
class t_axis_type>
18 template<
class t_type>
23 :
Vector<4, t_type>(t_type(1), t_type(0), t_type(0), t_type(0))
28 constexpr Quaternion(t_type x, t_type y, t_type z, t_type w)
29 :
Vector<4, t_type>(x, y, z, w)
32 :
Vector<4, t_type>(x, x, x, x)
34 template<
class t_angle_type,
class t_axis_type>
40 for (
uint01 i = 0; i < 3; i++)
44 template<
class t_angle_type>
66 template<
class t_angle_type>
82 template<
class t_angle_type>
109 for (
uint01 i = 0; i < 3; i++)
116 return q /
dot((*
this), (*
this));
120 return Quaternion((*
this)[
X] / s, (*
this)[
Y] / s, (*
this)[
Z] / s, (*
this)[
W] / s);
141 template<
class t_vec_type>
162 result[0] = ww * v[0] + 2 * wy * v[2] - 2 * wz * v[1] +
163 xx * v[0] + 2 * xy * v[1] + 2 * xz * v[2] -
164 zz * v[0] - yy * v[0];
165 result[1] = 2 * xy * v[0] + yy * v[1] + 2 * yz * v[2] +
166 2 * wz * v[0] - zz * v[1] + ww * v[1] -
167 2 * wx * v[2] - xx * v[1];
168 result[2] = 2 * xz * v[0] + 2 * yz * v[1] + zz * v[2] -
169 2 * wy * v[0] - yy * v[2] + 2 * wx * v[1] -
170 xx * v[2] + ww * v[2];
214 t_type x2 = (*this)[
X] + (*this)[
X];
215 t_type y2 = (*this)[
Y] + (*this)[
Y];
216 t_type z2 = (*this)[
Z] + (*this)[
Z];
217 t_type xx2 = (*this)[
X] * x2;
218 t_type xy2 = (*this)[
X] * y2;
219 t_type xz2 = (*this)[
X] * z2;
220 t_type yy2 = (*this)[
Y] * y2;
221 t_type yz2 = (*this)[
Y] * z2;
222 t_type zz2 = (*this)[
Z] * z2;
223 t_type sx2 = (*this)[
W] * x2;
224 t_type sy2 = (*this)[
W] * y2;
225 t_type sz2 = (*this)[
W] * z2;
229 1 - (yy2 + zz2), xy2 + sz2, xz2 - sy2, 0,
230 xy2 - sz2, 1 - (xx2 + zz2), yz2 + sx2, 0,
231 xz2 + sy2, yz2 - sx2, 1 - (xx2 + yy2), 0,
235 static Quaternion<fltp08> difference(
const Quaternion<fltp08>& q1,
const Quaternion<fltp08>& q2)
239 static Quaternion<fltp04> difference(
const Quaternion<fltp04>& q1,
const Quaternion<fltp04>& q2)
252 template<
class t_type>
279 template<
class t_type>
280 static constexpr bool isNaN(
const Quaternion<t_type>& value)
282 for (
uint01 dim = 0; dim < 4; ++dim)
284 if (isNaN(value[dim]))
Stores an angle in an optimized format.
Definition StringStream.h:352
static Angle atan2(fltp04 value_a, fltp04 value_b)
Definition Angle.h:481
static Angle asin(fltp04 value)
Definition Angle.h:461
static Angle acos(fltp04 value)
Definition Angle.h:437
Definition Matrix.hpp:173
Definition Quaternion.hpp:20
constexpr Quaternion()
Definition Quaternion.hpp:22
Vector< 3, Angle< t_angle_type > > euler() const
Definition Quaternion.hpp:83
AxisAngle< t_angle_type, t_type > axisAngle() const
Definition Quaternion.hpp:45
Quaternion operator*(const Quaternion &q2) const
Definition Quaternion.hpp:122
constexpr Quaternion(const Vector< 4, t_type > &vec)
Definition Quaternion.hpp:25
Quaternion conjugate() const
Definition Quaternion.hpp:105
void setFromEuler(Vector< 3, Angle< t_angle_type > > euler)
Definition Quaternion.hpp:67
constexpr Quaternion(Angle< t_angle_type > angle, Vector< 3, t_axis_type > axis)
Definition Quaternion.hpp:35
const Quaternion operator/(t_type s) const
Definition Quaternion.hpp:118
Matrix< t_type > toMatrix() const
Definition Quaternion.hpp:210
constexpr Quaternion(t_type x, t_type y, t_type z, t_type w)
Definition Quaternion.hpp:28
Vector< 3, t_vec_type > operator*(const Vector< 3, t_vec_type > &v) const
Definition Quaternion.hpp:142
constexpr Quaternion(t_type x)
Definition Quaternion.hpp:31
Quaternion invert() const
Definition Quaternion.hpp:113
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr Vector< t_dims, t_new_type > as() const
Definition Vector.hpp:324
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1096
@ ROLL
Definition Angle.h:51
@ YAW
Definition Angle.h:53
@ PITCH
Definition Angle.h:52
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
@ DEGREES
Definition Angle.h:66
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Definition AngleFunctions.h:154
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1309
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Definition AngleFunctions.h:113
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204
@ W
Definition BaseValues.hpp:206
An angle about a particular, defined 3D axis.
Definition Quaternion.hpp:14
Vector< 3, t_axis_type > axis
Definition Quaternion.hpp:16
Angle< t_angle_type > angle
Definition Quaternion.hpp:15
Definition BaseValues.hpp:272
static const t_type Min
Definition BaseValues.hpp:276
static const t_type Max
Definition BaseValues.hpp:278
static const t_type NaN
Definition BaseValues.hpp:274