22 class Quaternion :
public Vector<4, t_type>
25 constexpr Quaternion()
26 : Vector<4, t_type>(t_type(1), t_type(0), t_type(0), t_type(0))
28 constexpr Quaternion(
const Vector<4, t_type>& vec)
29 : Vector<4, t_type>(vec)
31 constexpr Quaternion(t_type x, t_type y, t_type z, t_type w)
32 : Vector<4, t_type>(x, y, z, w)
34 constexpr explicit Quaternion(t_type x)
35 : Vector<4, t_type>(x, x, x, x)
37 template<
class t_angle_type,
class t_axis_type>
43 for (
uint01 i = 0; i < 3; i++)
47 template<
class t_angle_type>
57 axis_angle.axis = Vector<4, t_type>::template
as<3, t_type>() / divider;
69 template<
class t_angle_type>
72 double cy =
cos(euler[
ROLL] * 0.5);
73 double sy =
sin(euler[
ROLL] * 0.5);
74 double cr =
cos(euler[
YAW] * 0.5);
75 double sr =
sin(euler[
YAW] * 0.5);
85 template<
class t_angle_type>
86 Vector<3, Angle<t_angle_type>> euler()
const
88 Vector<3, Angle<t_angle_type>> output;
108 Quaternion conjugate()
const
112 for (
uint01 i = 0; i < 3; i++)
116 Quaternion invert()
const
118 Quaternion q = conjugate();
119 return q /
dot((*
this), (*
this));
121 const Quaternion operator/(t_type s)
const
123 return Quaternion((*
this)[X] / s, (*
this)[Y] / s, (*
this)[Z] / s, (*
this)[W] / s);
125 Quaternion operator*(
const Quaternion& q2)
const
144 template<
class t_vec_type>
145 Vector<3, t_vec_type> operator*(
const Vector<3, t_vec_type>& v)
const
147 Vector<3, t_vec_type> result;
165 result[0] = ww * v[0] + 2 * wy * v[2] - 2 * wz * v[1] +
166 xx * v[0] + 2 * xy * v[1] + 2 * xz * v[2] -
167 zz * v[0] - yy * v[0];
168 result[1] = 2 * xy * v[0] + yy * v[1] + 2 * yz * v[2] +
169 2 * wz * v[0] - zz * v[1] + ww * v[1] -
170 2 * wx * v[2] - xx * v[1];
171 result[2] = 2 * xz * v[0] + 2 * yz * v[1] + zz * v[2] -
172 2 * wy * v[0] - yy * v[2] + 2 * wx * v[1] -
173 xx * v[2] + ww * v[2];
217 t_type x2 = (*this)[X] + (*this)[X];
218 t_type y2 = (*this)[Y] + (*this)[Y];
219 t_type z2 = (*this)[Z] + (*this)[Z];
220 t_type xx2 = (*this)[X] * x2;
221 t_type xy2 = (*this)[X] * y2;
222 t_type xz2 = (*this)[X] * z2;
223 t_type yy2 = (*this)[Y] * y2;
224 t_type yz2 = (*this)[Y] * z2;
225 t_type zz2 = (*this)[Z] * z2;
226 t_type sx2 = (*this)[W] * x2;
227 t_type sy2 = (*this)[W] * y2;
228 t_type sz2 = (*this)[W] * z2;
232 1 - (yy2 + zz2), xy2 + sz2, xz2 - sy2, 0,
233 xy2 - sz2, 1 - (xx2 + zz2), yz2 + sx2, 0,
234 xz2 + sy2, yz2 - sx2, 1 - (xx2 + yy2), 0,
static Angle atan2(t_value_type x, t_value_type y)
measures the counterclockwise angle between the positive x-axis and the point (x, y)
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Performs optimized sine operation on the given angle using pre-computed lookup table for optimal spee...
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Performs optimized cosine operation on the given angle using pre-computed lookup table for optimal sp...
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...