10 template <
typename Real>
19 template <
typename Real>
28 template <
typename Real>
32 const Real s = glm::sin(a);
39 template <
typename Real>
46 w = u0.dot(u1) + u0.norm() * u1.norm();
50 template <
typename Real>
60 template <
typename Real>
65 Real cp = glm::cos(
Real(pitch * 0.5));
66 Real sp = glm::sin(
Real(pitch * 0.5));
70 w = cr * cp * cy + sr * sp * sy;
71 x = sr * cp * cy - cr * sp * sy;
72 y = cr * sp * cy + sr * cp * sy;
73 z = cr * cp * sy - sr * sp * cy;
77 template <
typename Real>
87 template <
typename Real>
97 template <
typename Real>
107 template <
typename Real>
113 template <
typename Real>
119 template <
typename Real>
125 template <
typename Real>
128 return Quat(
x * scale,
y * scale,
z * scale,
w * scale);
131 template <
typename Real>
136 result.
w = -
x * q.
x -
y * q.
y -
z * q.
z +
w * q.
w;
138 result.
x =
x * q.
w +
y * q.
z -
z * q.
y +
w * q.
x;
139 result.
y = -
x * q.
z +
y * q.
w +
z * q.
x +
w * q.
y;
140 result.
z =
x * q.
y -
y * q.
x +
z * q.
w +
w * q.
z;
145 template <
typename Real>
148 return Quat(
x / scale,
y / scale,
z / scale,
w / scale);
151 template <
typename Real>
159 template <
typename Real>
167 template <
typename Real>
171 result = glm::sqrt(result);
176 template <
typename Real>
179 return w *
w +
x *
x +
y *
y +
z *
z;
182 template <
typename Real>
200 template <
typename Real>
206 template <
typename Real>
210 Real sinr_cosp = 2 * (
w *
x +
y *
z);
211 Real cosr_cosp = 1 - 2 * (
x *
x +
y *
y);
212 roll = atan2(sinr_cosp, cosr_cosp);
216 if (glm::abs(sinp) >= 1)
221 pitch = glm::asin(sinp);
224 Real siny_cosp = 2 * (
w *
z +
x *
y);
225 Real cosy_cosp = 1 - 2 * (
y *
y +
z *
z);
226 yaw = atan2(siny_cosp, cosy_cosp);
230 template <
typename Real>
233 return glm::acos(
w) * (
Real)(2);
236 template <
typename Real>
241 dot_product = glm::clamp(dot_product, (
Real)-1, (
Real)1);
242 return glm::acos(dot_product) * (
Real)(2);
245 template <
typename Real>
251 template <
typename Real>
258 template <
typename Real>
268 return 2.0f * u.dot(v) * u
269 + (s*s - u.dot(u)) * v
270 + 2.0f * s * u.cross(v);
274 template <
typename Real>
278 Real xx = x2 *
x, yy = y2 *
y, zz = z2 *
z;
279 Real xy = x2 *
y, xz = x2 *
z, xw = x2 *
w;
280 Real yz = y2 *
z, yw = y2 *
w, zw = z2 *
w;
282 xy + zw,
Real(1) - xx - zz, yz - xw,
283 xz - yw, yz + xw,
Real(1) - xx - yy);
286 template <
typename Real>
290 Real xx = x2 *
x, yy = y2 *
y, zz = z2 *
z;
291 Real xy = x2 *
y, xz = x2 *
z, xw = x2 *
w;
292 Real yz = y2 *
z, yw = y2 *
w, zw = z2 *
w;
294 entries[0] =
Real(1) - yy - zz;
295 entries[1] = xy - zw;
296 entries[2] = xz + yw,
298 entries[4] = xy + zw;
299 entries[5] =
Real(1) - xx - zz;
300 entries[6] = yz - xw;
302 entries[8] = xz - yw;
303 entries[9] = yz + xw;
304 entries[10] =
Real(1) - xx - yy;
311 entries[4], entries[5], entries[6], entries[7],
312 entries[8], entries[9], entries[10], entries[11],
313 entries[12], entries[13], entries[14], entries[15]);
317 template <
typename Real>
320 Real tr = matrix(0, 0) + matrix(1, 1) + matrix(2, 2);
327 x = s * (matrix(2, 1) - matrix(1, 2));
328 y = s * (matrix(0, 2) - matrix(2, 0));
329 z = s * (matrix(1, 0) - matrix(0, 1));
334 int next[3] = { 1, 2, 0 };
336 if (matrix(1, 1) > matrix(0, 0)) i = 1;
337 if (matrix(2, 2) > matrix(i, i)) i = 2;
340 Real s = glm::sqrt(matrix(i, i) - matrix(j, j) - matrix(k, k) +
Real(1.0));
341 q[i] = s *
Real(0.5);
344 q[3] = s * (matrix(k, j) - matrix(j, k));
345 q[j] = s * (matrix(j, i) + matrix(i, j));
346 q[k] = s * (matrix(k, i) + matrix(i, k));
354 template <
typename Real>
357 Real tr = matrix(0, 0) + matrix(1, 1) + matrix(2, 2);
364 x = s * (matrix(2, 1) - matrix(1, 2));
365 y = s * (matrix(0, 2) - matrix(2, 0));
366 z = s * (matrix(1, 0) - matrix(0, 1));
371 int next[3] = { 1, 2, 0 };
373 if (matrix(1, 1) > matrix(0, 0)) i = 1;
374 if (matrix(2, 2) > matrix(i, i)) i = 2;
377 Real s = glm::sqrt(matrix(i, i) - matrix(j, j) - matrix(k, k) +
Real(1.0));
378 q[i] = s *
Real(0.5);
381 q[3] = s * (matrix(k, j) - matrix(j, k));
382 q[j] = s * (matrix(j, i) + matrix(i, j));
383 q[k] = s * (matrix(k, i) + matrix(i, k));
391 template <
typename Real>
394 rot =
Real(2) * glm::acos(
w);
396 axis[0] =
Real(0); axis[1] =
Real(0); axis[2] =
Real(1);
DYN_FUNC Quat< Real > & operator-=(const Quat< Real > &)
DYN_FUNC Quat< float > & normalize()
DYN_FUNC Quat< Real > operator-(void) const
DYN_FUNC void toRotationAxis(Real &rot, Vector< Real, 3 > &axis) const
DYN_FUNC Real normSquared() const
DYN_FUNC Quat< Real > conjugate() const
DYN_FUNC Quat< Real > inverse() const
DYN_FUNC Quat< Real > operator/(const Real &) const
DYN_FUNC Quat< Real > operator+(const Quat< Real > &) const
DYN_FUNC bool operator==(const Quat< Real > &) const
DYN_FUNC Real dot(const Quat< Real > &) const
DYN_FUNC Quat< Real > & operator=(const Quat< Real > &)
DYN_FUNC void toEulerAngle(Real &yaw, Real &pitch, Real &roll) const
DYN_FUNC Real norm() const
DYN_FUNC Quat< Real > operator*(const Quat< Real > &) const
DYN_FUNC Real angle() const
DYN_FUNC SquareMatrix< Real, 3 > toMatrix3x3() const
DYN_FUNC Quat< Real > & operator+=(const Quat< Real > &)
DYN_FUNC bool operator!=(const Quat< Real > &) const
DYN_FUNC Vector< Real, 3 > rotate(const Vector< Real, 3 > &v) const
Rotate a vector by the quaternion, guarantee the quaternion is normalized before rotating the vector.
DYN_FUNC SquareMatrix< Real, 4 > toMatrix4x4() const
This is an implementation of AdditiveCCD based on peridyno.
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)