Blender  V2.93
math_rotation.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  *
19  * The Original Code is: some of this file.
20  */
21 
26 #include "BLI_math.h"
27 
28 #include "BLI_strict_flags.h"
29 
30 /******************************** Quaternions ********************************/
31 
32 /* used to test is a quat is not normalized (only used for debug prints) */
33 #ifdef DEBUG
34 # define QUAT_EPSILON 0.0001
35 #endif
36 
37 /* convenience, avoids setting Y axis everywhere */
38 void unit_axis_angle(float axis[3], float *angle)
39 {
40  axis[0] = 0.0f;
41  axis[1] = 1.0f;
42  axis[2] = 0.0f;
43  *angle = 0.0f;
44 }
45 
46 void unit_qt(float q[4])
47 {
48  q[0] = 1.0f;
49  q[1] = q[2] = q[3] = 0.0f;
50 }
51 
52 void copy_qt_qt(float q[4], const float a[4])
53 {
54  q[0] = a[0];
55  q[1] = a[1];
56  q[2] = a[2];
57  q[3] = a[3];
58 }
59 
60 bool is_zero_qt(const float q[4])
61 {
62  return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0);
63 }
64 
65 void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
66 {
67  float t0, t1, t2;
68 
69  t0 = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
70  t1 = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
71  t2 = a[0] * b[2] + a[2] * b[0] + a[3] * b[1] - a[1] * b[3];
72  q[3] = a[0] * b[3] + a[3] * b[0] + a[1] * b[2] - a[2] * b[1];
73  q[0] = t0;
74  q[1] = t1;
75  q[2] = t2;
76 }
77 
97 void mul_qt_v3(const float q[4], float r[3])
98 {
99  float t0, t1, t2;
100 
101  t0 = -q[1] * r[0] - q[2] * r[1] - q[3] * r[2];
102  t1 = q[0] * r[0] + q[2] * r[2] - q[3] * r[1];
103  t2 = q[0] * r[1] + q[3] * r[0] - q[1] * r[2];
104  r[2] = q[0] * r[2] + q[1] * r[1] - q[2] * r[0];
105  r[0] = t1;
106  r[1] = t2;
107 
108  t1 = t0 * -q[1] + r[0] * q[0] - r[1] * q[3] + r[2] * q[2];
109  t2 = t0 * -q[2] + r[1] * q[0] - r[2] * q[1] + r[0] * q[3];
110  r[2] = t0 * -q[3] + r[2] * q[0] - r[0] * q[2] + r[1] * q[1];
111  r[0] = t1;
112  r[1] = t2;
113 }
114 
115 void conjugate_qt_qt(float q1[4], const float q2[4])
116 {
117  q1[0] = q2[0];
118  q1[1] = -q2[1];
119  q1[2] = -q2[2];
120  q1[3] = -q2[3];
121 }
122 
123 void conjugate_qt(float q[4])
124 {
125  q[1] = -q[1];
126  q[2] = -q[2];
127  q[3] = -q[3];
128 }
129 
130 float dot_qtqt(const float a[4], const float b[4])
131 {
132  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
133 }
134 
135 void invert_qt(float q[4])
136 {
137  const float f = dot_qtqt(q, q);
138 
139  if (f == 0.0f) {
140  return;
141  }
142 
143  conjugate_qt(q);
144  mul_qt_fl(q, 1.0f / f);
145 }
146 
147 void invert_qt_qt(float q1[4], const float q2[4])
148 {
149  copy_qt_qt(q1, q2);
150  invert_qt(q1);
151 }
152 
158 void invert_qt_normalized(float q[4])
159 {
161  conjugate_qt(q);
162 }
163 
164 void invert_qt_qt_normalized(float q1[4], const float q2[4])
165 {
166  copy_qt_qt(q1, q2);
168 }
169 
170 /* simple mult */
171 void mul_qt_fl(float q[4], const float f)
172 {
173  q[0] *= f;
174  q[1] *= f;
175  q[2] *= f;
176  q[3] *= f;
177 }
178 
179 void sub_qt_qtqt(float q[4], const float a[4], const float b[4])
180 {
181  float n_b[4];
182 
183  n_b[0] = -b[0];
184  n_b[1] = b[1];
185  n_b[2] = b[2];
186  n_b[3] = b[3];
187 
188  mul_qt_qtqt(q, a, n_b);
189 }
190 
191 /* raise a unit quaternion to the specified power */
192 void pow_qt_fl_normalized(float q[4], const float fac)
193 {
195  const float angle = fac * saacos(q[0]); /* quat[0] = cos(0.5 * angle),
196  * but now the 0.5 and 2.0 rule out */
197  const float co = cosf(angle);
198  const float si = sinf(angle);
199  q[0] = co;
200  normalize_v3_length(q + 1, si);
201 }
202 
207 void quat_to_compatible_quat(float q[4], const float a[4], const float old[4])
208 {
209  const float eps = 1e-4f;
211  float old_unit[4];
212  /* Skips `!finite_v4(old)` case too. */
213  if (normalize_qt_qt(old_unit, old) > eps) {
214  float q_negate[4];
215  float delta[4];
216  rotation_between_quats_to_quat(delta, old_unit, a);
217  mul_qt_qtqt(q, old, delta);
218  negate_v4_v4(q_negate, q);
219  if (len_squared_v4v4(q_negate, old) < len_squared_v4v4(q, old)) {
220  copy_qt_qt(q, q_negate);
221  }
222  }
223  else {
224  copy_qt_qt(q, a);
225  }
226 }
227 
228 /* skip error check, currently only needed by mat3_to_quat_is_ok */
229 static void quat_to_mat3_no_error(float m[3][3], const float q[4])
230 {
231  double q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc;
232 
233  q0 = M_SQRT2 * (double)q[0];
234  q1 = M_SQRT2 * (double)q[1];
235  q2 = M_SQRT2 * (double)q[2];
236  q3 = M_SQRT2 * (double)q[3];
237 
238  qda = q0 * q1;
239  qdb = q0 * q2;
240  qdc = q0 * q3;
241  qaa = q1 * q1;
242  qab = q1 * q2;
243  qac = q1 * q3;
244  qbb = q2 * q2;
245  qbc = q2 * q3;
246  qcc = q3 * q3;
247 
248  m[0][0] = (float)(1.0 - qbb - qcc);
249  m[0][1] = (float)(qdc + qab);
250  m[0][2] = (float)(-qdb + qac);
251 
252  m[1][0] = (float)(-qdc + qab);
253  m[1][1] = (float)(1.0 - qaa - qcc);
254  m[1][2] = (float)(qda + qbc);
255 
256  m[2][0] = (float)(qdb + qac);
257  m[2][1] = (float)(-qda + qbc);
258  m[2][2] = (float)(1.0 - qaa - qbb);
259 }
260 
261 void quat_to_mat3(float m[3][3], const float q[4])
262 {
263 #ifdef DEBUG
264  float f;
265  if (!((f = dot_qtqt(q, q)) == 0.0f || (fabsf(f - 1.0f) < (float)QUAT_EPSILON))) {
266  fprintf(stderr,
267  "Warning! quat_to_mat3() called with non-normalized: size %.8f *** report a bug ***\n",
268  f);
269  }
270 #endif
271 
272  quat_to_mat3_no_error(m, q);
273 }
274 
275 void quat_to_mat4(float m[4][4], const float q[4])
276 {
277  double q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc;
278 
279 #ifdef DEBUG
280  if (!((q0 = dot_qtqt(q, q)) == 0.0 || (fabs(q0 - 1.0) < QUAT_EPSILON))) {
281  fprintf(stderr,
282  "Warning! quat_to_mat4() called with non-normalized: size %.8f *** report a bug ***\n",
283  (float)q0);
284  }
285 #endif
286 
287  q0 = M_SQRT2 * (double)q[0];
288  q1 = M_SQRT2 * (double)q[1];
289  q2 = M_SQRT2 * (double)q[2];
290  q3 = M_SQRT2 * (double)q[3];
291 
292  qda = q0 * q1;
293  qdb = q0 * q2;
294  qdc = q0 * q3;
295  qaa = q1 * q1;
296  qab = q1 * q2;
297  qac = q1 * q3;
298  qbb = q2 * q2;
299  qbc = q2 * q3;
300  qcc = q3 * q3;
301 
302  m[0][0] = (float)(1.0 - qbb - qcc);
303  m[0][1] = (float)(qdc + qab);
304  m[0][2] = (float)(-qdb + qac);
305  m[0][3] = 0.0f;
306 
307  m[1][0] = (float)(-qdc + qab);
308  m[1][1] = (float)(1.0 - qaa - qcc);
309  m[1][2] = (float)(qda + qbc);
310  m[1][3] = 0.0f;
311 
312  m[2][0] = (float)(qdb + qac);
313  m[2][1] = (float)(-qda + qbc);
314  m[2][2] = (float)(1.0 - qaa - qbb);
315  m[2][3] = 0.0f;
316 
317  m[3][0] = m[3][1] = m[3][2] = 0.0f;
318  m[3][3] = 1.0f;
319 }
320 
321 void mat3_normalized_to_quat(float q[4], const float mat[3][3])
322 {
323  BLI_ASSERT_UNIT_M3(mat);
324 
325  /* Check the trace of the matrix - bad precision if close to -1. */
326  const float trace = mat[0][0] + mat[1][1] + mat[2][2];
327 
328  if (trace > 0) {
329  float s = 2.0f * sqrtf(1.0f + trace);
330 
331  q[0] = 0.25f * s;
332 
333  s = 1.0f / s;
334 
335  q[1] = (mat[1][2] - mat[2][1]) * s;
336  q[2] = (mat[2][0] - mat[0][2]) * s;
337  q[3] = (mat[0][1] - mat[1][0]) * s;
338  }
339  else {
340  /* Find the biggest diagonal element to choose the best formula.
341  * Here trace should also be always >= 0, avoiding bad precision. */
342  if (mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) {
343  float s = 2.0f * sqrtf(1.0f + mat[0][0] - mat[1][1] - mat[2][2]);
344 
345  q[1] = 0.25f * s;
346 
347  s = 1.0f / s;
348 
349  q[0] = (mat[1][2] - mat[2][1]) * s;
350  q[2] = (mat[1][0] + mat[0][1]) * s;
351  q[3] = (mat[2][0] + mat[0][2]) * s;
352  }
353  else if (mat[1][1] > mat[2][2]) {
354  float s = 2.0f * sqrtf(1.0f + mat[1][1] - mat[0][0] - mat[2][2]);
355 
356  q[2] = 0.25f * s;
357 
358  s = 1.0f / s;
359 
360  q[0] = (mat[2][0] - mat[0][2]) * s;
361  q[1] = (mat[1][0] + mat[0][1]) * s;
362  q[3] = (mat[2][1] + mat[1][2]) * s;
363  }
364  else {
365  float s = 2.0f * sqrtf(1.0f + mat[2][2] - mat[0][0] - mat[1][1]);
366 
367  q[3] = 0.25f * s;
368 
369  s = 1.0f / s;
370 
371  q[0] = (mat[0][1] - mat[1][0]) * s;
372  q[1] = (mat[2][0] + mat[0][2]) * s;
373  q[2] = (mat[2][1] + mat[1][2]) * s;
374  }
375 
376  /* Make sure w is nonnegative for a canonical result. */
377  if (q[0] < 0) {
378  negate_v4(q);
379  }
380  }
381 
382  normalize_qt(q);
383 }
384 void mat3_to_quat(float q[4], const float m[3][3])
385 {
386  float unit_mat[3][3];
387 
388  /* work on a copy */
389  /* this is needed AND a 'normalize_qt' in the end */
390  normalize_m3_m3(unit_mat, m);
391  mat3_normalized_to_quat(q, unit_mat);
392 }
393 
394 void mat4_normalized_to_quat(float q[4], const float m[4][4])
395 {
396  float mat3[3][3];
397 
398  copy_m3_m4(mat3, m);
399  mat3_normalized_to_quat(q, mat3);
400 }
401 
402 void mat4_to_quat(float q[4], const float m[4][4])
403 {
404  float mat3[3][3];
405 
406  copy_m3_m4(mat3, m);
407  mat3_to_quat(q, mat3);
408 }
409 
410 void mat3_to_quat_is_ok(float q[4], const float wmat[3][3])
411 {
412  float mat[3][3], matr[3][3], matn[3][3], q1[4], q2[4], angle, si, co, nor[3];
413 
414  /* work on a copy */
415  copy_m3_m3(mat, wmat);
416  normalize_m3(mat);
417 
418  /* rotate z-axis of matrix to z-axis */
419 
420  nor[0] = mat[2][1]; /* cross product with (0,0,1) */
421  nor[1] = -mat[2][0];
422  nor[2] = 0.0;
423  normalize_v3(nor);
424 
425  co = mat[2][2];
426  angle = 0.5f * saacos(co);
427 
428  co = cosf(angle);
429  si = sinf(angle);
430  q1[0] = co;
431  q1[1] = -nor[0] * si; /* negative here, but why? */
432  q1[2] = -nor[1] * si;
433  q1[3] = -nor[2] * si;
434 
435  /* rotate back x-axis from mat, using inverse q1 */
436  quat_to_mat3_no_error(matr, q1);
437  invert_m3_m3(matn, matr);
438  mul_m3_v3(matn, mat[0]);
439 
440  /* and align x-axes */
441  angle = 0.5f * atan2f(mat[0][1], mat[0][0]);
442 
443  co = cosf(angle);
444  si = sinf(angle);
445  q2[0] = co;
446  q2[1] = 0.0f;
447  q2[2] = 0.0f;
448  q2[3] = si;
449 
450  mul_qt_qtqt(q, q1, q2);
451 }
452 
453 float normalize_qt(float q[4])
454 {
455  const float len = sqrtf(dot_qtqt(q, q));
456 
457  if (len != 0.0f) {
458  mul_qt_fl(q, 1.0f / len);
459  }
460  else {
461  q[1] = 1.0f;
462  q[0] = q[2] = q[3] = 0.0f;
463  }
464 
465  return len;
466 }
467 
468 float normalize_qt_qt(float r[4], const float q[4])
469 {
470  copy_qt_qt(r, q);
471  return normalize_qt(r);
472 }
473 
477 void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
478 {
479  float axis[3];
480  /* avoid calculating the angle */
481  float angle_sin;
482  float angle_cos;
483 
486 
487  cross_v3_v3v3(axis, v1, v2);
488 
489  angle_sin = normalize_v3(axis);
490  angle_cos = dot_v3v3(v1, v2);
491 
492  if (angle_sin > FLT_EPSILON) {
493  axis_calc:
494  BLI_ASSERT_UNIT_V3(axis);
495  axis_angle_normalized_to_mat3_ex(m, axis, angle_sin, angle_cos);
497  }
498  else {
499  if (angle_cos > 0.0f) {
500  /* Same vectors, zero rotation... */
501  unit_m3(m);
502  }
503  else {
504  /* Colinear but opposed vectors, 180 rotation... */
505  ortho_v3_v3(axis, v1);
506  normalize_v3(axis);
507  angle_sin = 0.0f; /* sin(M_PI) */
508  angle_cos = -1.0f; /* cos(M_PI) */
509  goto axis_calc;
510  }
511  }
512 }
513 
514 /* note: expects vectors to be normalized */
515 void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
516 {
517  float axis[3];
518 
519  cross_v3_v3v3(axis, v1, v2);
520 
521  if (normalize_v3(axis) > FLT_EPSILON) {
522  float angle;
523 
525 
527  }
528  else {
529  /* degenerate case */
530 
531  if (dot_v3v3(v1, v2) > 0.0f) {
532  /* Same vectors, zero rotation... */
533  unit_qt(q);
534  }
535  else {
536  /* Colinear but opposed vectors, 180 rotation... */
537  ortho_v3_v3(axis, v1);
538  axis_angle_to_quat(q, axis, (float)M_PI);
539  }
540  }
541 }
542 
543 void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4])
544 {
545  float tquat[4];
546 
547  conjugate_qt_qt(tquat, q1);
548 
549  mul_qt_fl(tquat, 1.0f / dot_qtqt(tquat, tquat));
550 
551  mul_qt_qtqt(q, tquat, q2);
552 }
553 
564 float quat_split_swing_and_twist(const float q_in[4], int axis, float r_swing[4], float r_twist[4])
565 {
566  BLI_assert(axis >= 0 && axis <= 2);
567 
568  /* The calculation requires a canonical quaternion. */
569  float q[4];
570 
571  if (q_in[0] < 0) {
572  negate_v4_v4(q, q_in);
573  }
574  else {
575  copy_v4_v4(q, q_in);
576  }
577 
578  /* Half-twist angle can be computed directly. */
579  float t = atan2f(q[axis + 1], q[0]);
580 
581  if (r_swing || r_twist) {
582  float sin_t = sinf(t), cos_t = cosf(t);
583 
584  /* Compute swing by multiplying the original quaternion by inverted twist. */
585  if (r_swing) {
586  float twist_inv[4];
587 
588  twist_inv[0] = cos_t;
589  zero_v3(twist_inv + 1);
590  twist_inv[axis + 1] = -sin_t;
591 
592  mul_qt_qtqt(r_swing, q, twist_inv);
593 
594  BLI_assert(fabsf(r_swing[axis + 1]) < BLI_ASSERT_UNIT_EPSILON);
595  }
596 
597  /* Output twist last just in case q overlaps r_twist. */
598  if (r_twist) {
599  r_twist[0] = cos_t;
600  zero_v3(r_twist + 1);
601  r_twist[axis + 1] = sin_t;
602  }
603  }
604 
605  return 2.0f * t;
606 }
607 
608 /* -------------------------------------------------------------------- */
616 float angle_normalized_qt(const float q[4])
617 {
619  return 2.0f * saacos(q[0]);
620 }
621 
622 float angle_qt(const float q[4])
623 {
624  float tquat[4];
625 
626  normalize_qt_qt(tquat, q);
627 
628  return angle_normalized_qt(tquat);
629 }
630 
631 float angle_normalized_qtqt(const float q1[4], const float q2[4])
632 {
633  float qdelta[4];
634 
637 
638  rotation_between_quats_to_quat(qdelta, q1, q2);
639 
640  return angle_normalized_qt(qdelta);
641 }
642 
643 float angle_qtqt(const float q1[4], const float q2[4])
644 {
645  float quat1[4], quat2[4];
646 
647  normalize_qt_qt(quat1, q1);
648  normalize_qt_qt(quat2, q2);
649 
650  return angle_normalized_qtqt(quat1, quat2);
651 }
652 
655 /* -------------------------------------------------------------------- */
665 float angle_signed_normalized_qt(const float q[4])
666 {
668  if (q[0] >= 0.0f) {
669  return 2.0f * saacos(q[0]);
670  }
671 
672  return -2.0f * saacos(-q[0]);
673 }
674 
675 float angle_signed_normalized_qtqt(const float q1[4], const float q2[4])
676 {
677  if (dot_qtqt(q1, q2) >= 0.0f) {
678  return angle_normalized_qtqt(q1, q2);
679  }
680 
681  float q2_copy[4];
682  negate_v4_v4(q2_copy, q2);
683  return -angle_normalized_qtqt(q1, q2_copy);
684 }
685 
686 float angle_signed_qt(const float q[4])
687 {
688  float tquat[4];
689 
690  normalize_qt_qt(tquat, q);
691 
692  return angle_signed_normalized_qt(tquat);
693 }
694 
695 float angle_signed_qtqt(const float q1[4], const float q2[4])
696 {
697  if (dot_qtqt(q1, q2) >= 0.0f) {
698  return angle_qtqt(q1, q2);
699  }
700 
701  float q2_copy[4];
702  negate_v4_v4(q2_copy, q2);
703  return -angle_qtqt(q1, q2_copy);
704 }
705 
708 void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
709 {
710  const float eps = 1e-4f;
711  float nor[3], tvec[3];
712  float angle, si, co, len;
713 
714  BLI_assert(axis >= 0 && axis <= 5);
715  BLI_assert(upflag >= 0 && upflag <= 2);
716 
717  /* first set the quat to unit */
718  unit_qt(q);
719 
720  len = len_v3(vec);
721 
722  if (UNLIKELY(len == 0.0f)) {
723  return;
724  }
725 
726  /* rotate to axis */
727  if (axis > 2) {
728  copy_v3_v3(tvec, vec);
729  axis = (short)(axis - 3);
730  }
731  else {
732  negate_v3_v3(tvec, vec);
733  }
734 
735  /* nasty! I need a good routine for this...
736  * problem is a rotation of an Y axis to the negative Y-axis for example.
737  */
738 
739  if (axis == 0) { /* x-axis */
740  nor[0] = 0.0;
741  nor[1] = -tvec[2];
742  nor[2] = tvec[1];
743 
744  if (fabsf(tvec[1]) + fabsf(tvec[2]) < eps) {
745  nor[1] = 1.0f;
746  }
747 
748  co = tvec[0];
749  }
750  else if (axis == 1) { /* y-axis */
751  nor[0] = tvec[2];
752  nor[1] = 0.0;
753  nor[2] = -tvec[0];
754 
755  if (fabsf(tvec[0]) + fabsf(tvec[2]) < eps) {
756  nor[2] = 1.0f;
757  }
758 
759  co = tvec[1];
760  }
761  else { /* z-axis */
762  nor[0] = -tvec[1];
763  nor[1] = tvec[0];
764  nor[2] = 0.0;
765 
766  if (fabsf(tvec[0]) + fabsf(tvec[1]) < eps) {
767  nor[0] = 1.0f;
768  }
769 
770  co = tvec[2];
771  }
772  co /= len;
773 
774  normalize_v3(nor);
775 
777 
778  if (axis != upflag) {
779  float mat[3][3];
780  float q2[4];
781  const float *fp = mat[2];
782  quat_to_mat3(mat, q);
783 
784  if (axis == 0) {
785  if (upflag == 1) {
786  angle = 0.5f * atan2f(fp[2], fp[1]);
787  }
788  else {
789  angle = -0.5f * atan2f(fp[1], fp[2]);
790  }
791  }
792  else if (axis == 1) {
793  if (upflag == 0) {
794  angle = -0.5f * atan2f(fp[2], fp[0]);
795  }
796  else {
797  angle = 0.5f * atan2f(fp[0], fp[2]);
798  }
799  }
800  else {
801  if (upflag == 0) {
802  angle = 0.5f * atan2f(-fp[1], -fp[0]);
803  }
804  else {
805  angle = -0.5f * atan2f(-fp[0], -fp[1]);
806  }
807  }
808 
809  co = cosf(angle);
810  si = sinf(angle) / len;
811  q2[0] = co;
812  q2[1] = tvec[0] * si;
813  q2[2] = tvec[1] * si;
814  q2[3] = tvec[2] * si;
815 
816  mul_qt_qtqt(q, q2, q);
817  }
818 }
819 
820 #if 0
821 
822 /* A & M Watt, Advanced animation and rendering techniques, 1992 ACM press */
823 void QuatInterpolW(float *result, float quat1[4], float quat2[4], float t)
824 {
825  float omega, cosom, sinom, sc1, sc2;
826 
827  cosom = quat1[0] * quat2[0] + quat1[1] * quat2[1] + quat1[2] * quat2[2] + quat1[3] * quat2[3];
828 
829  /* rotate around shortest angle */
830  if ((1.0f + cosom) > 0.0001f) {
831 
832  if ((1.0f - cosom) > 0.0001f) {
833  omega = (float)acos(cosom);
834  sinom = sinf(omega);
835  sc1 = sinf((1.0 - t) * omega) / sinom;
836  sc2 = sinf(t * omega) / sinom;
837  }
838  else {
839  sc1 = 1.0f - t;
840  sc2 = t;
841  }
842  result[0] = sc1 * quat1[0] + sc2 * quat2[0];
843  result[1] = sc1 * quat1[1] + sc2 * quat2[1];
844  result[2] = sc1 * quat1[2] + sc2 * quat2[2];
845  result[3] = sc1 * quat1[3] + sc2 * quat2[3];
846  }
847  else {
848  result[0] = quat2[3];
849  result[1] = -quat2[2];
850  result[2] = quat2[1];
851  result[3] = -quat2[0];
852 
853  sc1 = sinf((1.0 - t) * M_PI_2);
854  sc2 = sinf(t * M_PI_2);
855 
856  result[0] = sc1 * quat1[0] + sc2 * result[0];
857  result[1] = sc1 * quat1[1] + sc2 * result[1];
858  result[2] = sc1 * quat1[2] + sc2 * result[2];
859  result[3] = sc1 * quat1[3] + sc2 * result[3];
860  }
861 }
862 #endif
863 
872 void interp_dot_slerp(const float t, const float cosom, float r_w[2])
873 {
874  const float eps = 1e-4f;
875 
876  BLI_assert(IN_RANGE_INCL(cosom, -1.0001f, 1.0001f));
877 
878  /* within [-1..1] range, avoid aligned axis */
879  if (LIKELY(fabsf(cosom) < (1.0f - eps))) {
880  float omega, sinom;
881 
882  omega = acosf(cosom);
883  sinom = sinf(omega);
884  r_w[0] = sinf((1.0f - t) * omega) / sinom;
885  r_w[1] = sinf(t * omega) / sinom;
886  }
887  else {
888  /* fallback to lerp */
889  r_w[0] = 1.0f - t;
890  r_w[1] = t;
891  }
892 }
893 
894 void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t)
895 {
896  float quat[4], cosom, w[2];
897 
900 
901  cosom = dot_qtqt(a, b);
902 
903  /* rotate around shortest angle */
904  if (cosom < 0.0f) {
905  cosom = -cosom;
906  negate_v4_v4(quat, a);
907  }
908  else {
909  copy_qt_qt(quat, a);
910  }
911 
912  interp_dot_slerp(t, cosom, w);
913 
914  q[0] = w[0] * quat[0] + w[1] * b[0];
915  q[1] = w[0] * quat[1] + w[1] * b[1];
916  q[2] = w[0] * quat[2] + w[1] * b[2];
917  q[3] = w[0] * quat[3] + w[1] * b[3];
918 }
919 
920 void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t)
921 {
922  q[0] = a[0] + t * b[0];
923  q[1] = a[1] + t * b[1];
924  q[2] = a[2] + t * b[2];
925  q[3] = a[3] + t * b[3];
926 }
927 
928 /* same as tri_to_quat() but takes pre-computed normal from the triangle
929  * used for ngons when we know their normal */
931  float quat[4], const float v1[3], const float v2[3], const float v3[3], const float no_orig[3])
932 {
933  /* imaginary x-axis, y-axis triangle is being rotated */
934  float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3];
935 
936  /* move z-axis to face-normal */
937 #if 0
938  normal_tri_v3(vec, v1, v2, v3);
939 #else
940  copy_v3_v3(vec, no_orig);
941  (void)v3;
942 #endif
943 
944  n[0] = vec[1];
945  n[1] = -vec[0];
946  n[2] = 0.0f;
947  normalize_v3(n);
948 
949  if (n[0] == 0.0f && n[1] == 0.0f) {
950  n[0] = 1.0f;
951  }
952 
953  angle = -0.5f * saacos(vec[2]);
954  co = cosf(angle);
955  si = sinf(angle);
956  q1[0] = co;
957  q1[1] = n[0] * si;
958  q1[2] = n[1] * si;
959  q1[3] = 0.0f;
960 
961  /* rotate back line v1-v2 */
962  quat_to_mat3(mat, q1);
963  invert_m3_m3(imat, mat);
964  sub_v3_v3v3(vec, v2, v1);
965  mul_m3_v3(imat, vec);
966 
967  /* what angle has this line with x-axis? */
968  vec[2] = 0.0f;
969  normalize_v3(vec);
970 
971  angle = 0.5f * atan2f(vec[1], vec[0]);
972  co = cosf(angle);
973  si = sinf(angle);
974  q2[0] = co;
975  q2[1] = 0.0f;
976  q2[2] = 0.0f;
977  q2[3] = si;
978 
979  mul_qt_qtqt(quat, q1, q2);
980 }
981 
985 float tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3])
986 {
987  float vec[3];
988  const float len = normal_tri_v3(vec, a, b, c);
989 
990  tri_to_quat_ex(q, a, b, c, vec);
991  return len;
992 }
993 
994 void print_qt(const char *str, const float q[4])
995 {
996  printf("%s: %.3f %.3f %.3f %.3f\n", str, q[0], q[1], q[2], q[3]);
997 }
998 
999 /******************************** Axis Angle *********************************/
1000 
1001 void axis_angle_normalized_to_quat(float r[4], const float axis[3], const float angle)
1002 {
1003  const float phi = 0.5f * angle;
1004  const float si = sinf(phi);
1005  const float co = cosf(phi);
1006  BLI_ASSERT_UNIT_V3(axis);
1007  r[0] = co;
1008  mul_v3_v3fl(r + 1, axis, si);
1009 }
1010 
1011 void axis_angle_to_quat(float r[4], const float axis[3], const float angle)
1012 {
1013  float nor[3];
1014 
1015  if (LIKELY(normalize_v3_v3(nor, axis) != 0.0f)) {
1017  }
1018  else {
1019  unit_qt(r);
1020  }
1021 }
1022 
1023 /* Quaternions to Axis Angle */
1024 void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
1025 {
1026  float ha, si;
1027 
1028 #ifdef DEBUG
1029  if (!((ha = dot_qtqt(q, q)) == 0.0f || (fabsf(ha - 1.0f) < (float)QUAT_EPSILON))) {
1030  fprintf(stderr,
1031  "Warning! quat_to_axis_angle() called with non-normalized: size %.8f *** report a bug "
1032  "***\n",
1033  ha);
1034  }
1035 #endif
1036 
1037  /* calculate angle/2, and sin(angle/2) */
1038  ha = acosf(q[0]);
1039  si = sinf(ha);
1040 
1041  /* from half-angle to angle */
1042  *angle = ha * 2;
1043 
1044  /* prevent division by zero for axis conversion */
1045  if (fabsf(si) < 0.0005f) {
1046  si = 1.0f;
1047  }
1048 
1049  axis[0] = q[1] / si;
1050  axis[1] = q[2] / si;
1051  axis[2] = q[3] / si;
1052  if (is_zero_v3(axis)) {
1053  axis[1] = 1.0f;
1054  }
1055 }
1056 
1057 /* Axis Angle to Euler Rotation */
1058 void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle)
1059 {
1060  float q[4];
1061 
1062  /* use quaternions as intermediate representation for now... */
1063  axis_angle_to_quat(q, axis, angle);
1064  quat_to_eulO(eul, order, q);
1065 }
1066 
1067 /* Euler Rotation to Axis Angle */
1068 void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order)
1069 {
1070  float q[4];
1071 
1072  /* use quaternions as intermediate representation for now... */
1073  eulO_to_quat(q, eul, order);
1074  quat_to_axis_angle(axis, angle, q);
1075 }
1076 
1087  const float axis[3],
1088  const float angle_sin,
1089  const float angle_cos)
1090 {
1091  float nsi[3], ico;
1092  float n_00, n_01, n_11, n_02, n_12, n_22;
1093 
1094  BLI_ASSERT_UNIT_V3(axis);
1095 
1096  /* now convert this to a 3x3 matrix */
1097 
1098  ico = (1.0f - angle_cos);
1099  nsi[0] = axis[0] * angle_sin;
1100  nsi[1] = axis[1] * angle_sin;
1101  nsi[2] = axis[2] * angle_sin;
1102 
1103  n_00 = (axis[0] * axis[0]) * ico;
1104  n_01 = (axis[0] * axis[1]) * ico;
1105  n_11 = (axis[1] * axis[1]) * ico;
1106  n_02 = (axis[0] * axis[2]) * ico;
1107  n_12 = (axis[1] * axis[2]) * ico;
1108  n_22 = (axis[2] * axis[2]) * ico;
1109 
1110  mat[0][0] = n_00 + angle_cos;
1111  mat[0][1] = n_01 + nsi[2];
1112  mat[0][2] = n_02 - nsi[1];
1113  mat[1][0] = n_01 - nsi[2];
1114  mat[1][1] = n_11 + angle_cos;
1115  mat[1][2] = n_12 + nsi[0];
1116  mat[2][0] = n_02 + nsi[1];
1117  mat[2][1] = n_12 - nsi[0];
1118  mat[2][2] = n_22 + angle_cos;
1119 }
1120 
1121 void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const float angle)
1122 {
1124 }
1125 
1126 /* axis angle to 3x3 matrix - safer version (normalization of axis performed) */
1127 void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle)
1128 {
1129  float nor[3];
1130 
1131  /* normalize the axis first (to remove unwanted scaling) */
1132  if (normalize_v3_v3(nor, axis) == 0.0f) {
1133  unit_m3(R);
1134  return;
1135  }
1136 
1138 }
1139 
1140 /* axis angle to 4x4 matrix - safer version (normalization of axis performed) */
1141 void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle)
1142 {
1143  float tmat[3][3];
1144 
1145  axis_angle_to_mat3(tmat, axis, angle);
1146  unit_m4(R);
1147  copy_m4_m3(R, tmat);
1148 }
1149 
1150 /* 3x3 matrix to axis angle */
1151 void mat3_normalized_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
1152 {
1153  float q[4];
1154 
1155  /* use quaternions as intermediate representation */
1156  /* TODO: it would be nicer to go straight there... */
1157  mat3_normalized_to_quat(q, mat);
1158  quat_to_axis_angle(axis, angle, q);
1159 }
1160 void mat3_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
1161 {
1162  float q[4];
1163 
1164  /* use quaternions as intermediate representation */
1165  /* TODO: it would be nicer to go straight there... */
1166  mat3_to_quat(q, mat);
1167  quat_to_axis_angle(axis, angle, q);
1168 }
1169 
1170 /* 4x4 matrix to axis angle */
1171 void mat4_normalized_to_axis_angle(float axis[3], float *angle, const float mat[4][4])
1172 {
1173  float q[4];
1174 
1175  /* use quaternions as intermediate representation */
1176  /* TODO: it would be nicer to go straight there... */
1177  mat4_normalized_to_quat(q, mat);
1178  quat_to_axis_angle(axis, angle, q);
1179 }
1180 
1181 /* 4x4 matrix to axis angle */
1182 void mat4_to_axis_angle(float axis[3], float *angle, const float mat[4][4])
1183 {
1184  float q[4];
1185 
1186  /* use quaternions as intermediate representation */
1187  /* TODO: it would be nicer to go straight there... */
1188  mat4_to_quat(q, mat);
1189  quat_to_axis_angle(axis, angle, q);
1190 }
1191 
1192 void axis_angle_to_mat4_single(float R[4][4], const char axis, const float angle)
1193 {
1194  float mat3[3][3];
1195  axis_angle_to_mat3_single(mat3, axis, angle);
1196  copy_m4_m3(R, mat3);
1197 }
1198 
1199 /* rotation matrix from a single axis */
1200 void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle)
1201 {
1202  const float angle_cos = cosf(angle);
1203  const float angle_sin = sinf(angle);
1204 
1205  switch (axis) {
1206  case 'X': /* rotation around X */
1207  R[0][0] = 1.0f;
1208  R[0][1] = 0.0f;
1209  R[0][2] = 0.0f;
1210  R[1][0] = 0.0f;
1211  R[1][1] = angle_cos;
1212  R[1][2] = angle_sin;
1213  R[2][0] = 0.0f;
1214  R[2][1] = -angle_sin;
1215  R[2][2] = angle_cos;
1216  break;
1217  case 'Y': /* rotation around Y */
1218  R[0][0] = angle_cos;
1219  R[0][1] = 0.0f;
1220  R[0][2] = -angle_sin;
1221  R[1][0] = 0.0f;
1222  R[1][1] = 1.0f;
1223  R[1][2] = 0.0f;
1224  R[2][0] = angle_sin;
1225  R[2][1] = 0.0f;
1226  R[2][2] = angle_cos;
1227  break;
1228  case 'Z': /* rotation around Z */
1229  R[0][0] = angle_cos;
1230  R[0][1] = angle_sin;
1231  R[0][2] = 0.0f;
1232  R[1][0] = -angle_sin;
1233  R[1][1] = angle_cos;
1234  R[1][2] = 0.0f;
1235  R[2][0] = 0.0f;
1236  R[2][1] = 0.0f;
1237  R[2][2] = 1.0f;
1238  break;
1239  default:
1240  BLI_assert(0);
1241  break;
1242  }
1243 }
1244 
1245 void angle_to_mat2(float R[2][2], const float angle)
1246 {
1247  const float angle_cos = cosf(angle);
1248  const float angle_sin = sinf(angle);
1249 
1250  /* 2D rotation matrix */
1251  R[0][0] = angle_cos;
1252  R[0][1] = angle_sin;
1253  R[1][0] = -angle_sin;
1254  R[1][1] = angle_cos;
1255 }
1256 
1257 void axis_angle_to_quat_single(float q[4], const char axis, const float angle)
1258 {
1259  const float angle_half = angle * 0.5f;
1260  const float angle_cos = cosf(angle_half);
1261  const float angle_sin = sinf(angle_half);
1262  const int axis_index = (axis - 'X');
1263 
1264  BLI_assert(axis >= 'X' && axis <= 'Z');
1265 
1266  q[0] = angle_cos;
1267  zero_v3(q + 1);
1268  q[axis_index + 1] = angle_sin;
1269 }
1270 
1271 /****************************** Exponential Map ******************************/
1272 
1273 void quat_normalized_to_expmap(float expmap[3], const float q[4])
1274 {
1275  float angle;
1277 
1278  /* Obtain axis/angle representation. */
1279  quat_to_axis_angle(expmap, &angle, q);
1280 
1281  /* Convert to exponential map. */
1282  mul_v3_fl(expmap, angle);
1283 }
1284 
1285 void quat_to_expmap(float expmap[3], const float q[4])
1286 {
1287  float q_no[4];
1288  normalize_qt_qt(q_no, q);
1289  quat_normalized_to_expmap(expmap, q_no);
1290 }
1291 
1292 void expmap_to_quat(float r[4], const float expmap[3])
1293 {
1294  float axis[3];
1295  float angle;
1296 
1297  /* Obtain axis/angle representation. */
1298  if (LIKELY((angle = normalize_v3_v3(axis, expmap)) != 0.0f)) {
1300  }
1301  else {
1302  unit_qt(r);
1303  }
1304 }
1305 
1306 /******************************** XYZ Eulers *********************************/
1307 
1308 /* XYZ order */
1309 void eul_to_mat3(float mat[3][3], const float eul[3])
1310 {
1311  double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
1312 
1313  ci = cos(eul[0]);
1314  cj = cos(eul[1]);
1315  ch = cos(eul[2]);
1316  si = sin(eul[0]);
1317  sj = sin(eul[1]);
1318  sh = sin(eul[2]);
1319  cc = ci * ch;
1320  cs = ci * sh;
1321  sc = si * ch;
1322  ss = si * sh;
1323 
1324  mat[0][0] = (float)(cj * ch);
1325  mat[1][0] = (float)(sj * sc - cs);
1326  mat[2][0] = (float)(sj * cc + ss);
1327  mat[0][1] = (float)(cj * sh);
1328  mat[1][1] = (float)(sj * ss + cc);
1329  mat[2][1] = (float)(sj * cs - sc);
1330  mat[0][2] = (float)-sj;
1331  mat[1][2] = (float)(cj * si);
1332  mat[2][2] = (float)(cj * ci);
1333 }
1334 
1335 /* XYZ order */
1336 void eul_to_mat4(float mat[4][4], const float eul[3])
1337 {
1338  double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
1339 
1340  ci = cos(eul[0]);
1341  cj = cos(eul[1]);
1342  ch = cos(eul[2]);
1343  si = sin(eul[0]);
1344  sj = sin(eul[1]);
1345  sh = sin(eul[2]);
1346  cc = ci * ch;
1347  cs = ci * sh;
1348  sc = si * ch;
1349  ss = si * sh;
1350 
1351  mat[0][0] = (float)(cj * ch);
1352  mat[1][0] = (float)(sj * sc - cs);
1353  mat[2][0] = (float)(sj * cc + ss);
1354  mat[0][1] = (float)(cj * sh);
1355  mat[1][1] = (float)(sj * ss + cc);
1356  mat[2][1] = (float)(sj * cs - sc);
1357  mat[0][2] = (float)-sj;
1358  mat[1][2] = (float)(cj * si);
1359  mat[2][2] = (float)(cj * ci);
1360 
1361  mat[3][0] = mat[3][1] = mat[3][2] = mat[0][3] = mat[1][3] = mat[2][3] = 0.0f;
1362  mat[3][3] = 1.0f;
1363 }
1364 
1365 /* returns two euler calculation methods, so we can pick the best */
1366 
1367 /* XYZ order */
1368 static void mat3_normalized_to_eul2(const float mat[3][3], float eul1[3], float eul2[3])
1369 {
1370  const float cy = hypotf(mat[0][0], mat[0][1]);
1371 
1372  BLI_ASSERT_UNIT_M3(mat);
1373 
1374  if (cy > 16.0f * FLT_EPSILON) {
1375 
1376  eul1[0] = atan2f(mat[1][2], mat[2][2]);
1377  eul1[1] = atan2f(-mat[0][2], cy);
1378  eul1[2] = atan2f(mat[0][1], mat[0][0]);
1379 
1380  eul2[0] = atan2f(-mat[1][2], -mat[2][2]);
1381  eul2[1] = atan2f(-mat[0][2], -cy);
1382  eul2[2] = atan2f(-mat[0][1], -mat[0][0]);
1383  }
1384  else {
1385  eul1[0] = atan2f(-mat[2][1], mat[1][1]);
1386  eul1[1] = atan2f(-mat[0][2], cy);
1387  eul1[2] = 0.0f;
1388 
1389  copy_v3_v3(eul2, eul1);
1390  }
1391 }
1392 
1393 /* XYZ order */
1394 void mat3_normalized_to_eul(float eul[3], const float mat[3][3])
1395 {
1396  float eul1[3], eul2[3];
1397 
1398  mat3_normalized_to_eul2(mat, eul1, eul2);
1399 
1400  /* return best, which is just the one with lowest values it in */
1401  if (fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]) >
1402  fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2])) {
1403  copy_v3_v3(eul, eul2);
1404  }
1405  else {
1406  copy_v3_v3(eul, eul1);
1407  }
1408 }
1409 void mat3_to_eul(float eul[3], const float mat[3][3])
1410 {
1411  float unit_mat[3][3];
1412  normalize_m3_m3(unit_mat, mat);
1413  mat3_normalized_to_eul(eul, unit_mat);
1414 }
1415 
1416 /* XYZ order */
1417 void mat4_normalized_to_eul(float eul[3], const float m[4][4])
1418 {
1419  float mat3[3][3];
1420  copy_m3_m4(mat3, m);
1421  mat3_normalized_to_eul(eul, mat3);
1422 }
1423 void mat4_to_eul(float eul[3], const float m[4][4])
1424 {
1425  float mat3[3][3];
1426  copy_m3_m4(mat3, m);
1427  mat3_to_eul(eul, mat3);
1428 }
1429 
1430 /* XYZ order */
1431 void quat_to_eul(float eul[3], const float quat[4])
1432 {
1433  float unit_mat[3][3];
1434  quat_to_mat3(unit_mat, quat);
1435  mat3_normalized_to_eul(eul, unit_mat);
1436 }
1437 
1438 /* XYZ order */
1439 void eul_to_quat(float quat[4], const float eul[3])
1440 {
1441  float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
1442 
1443  ti = eul[0] * 0.5f;
1444  tj = eul[1] * 0.5f;
1445  th = eul[2] * 0.5f;
1446  ci = cosf(ti);
1447  cj = cosf(tj);
1448  ch = cosf(th);
1449  si = sinf(ti);
1450  sj = sinf(tj);
1451  sh = sinf(th);
1452  cc = ci * ch;
1453  cs = ci * sh;
1454  sc = si * ch;
1455  ss = si * sh;
1456 
1457  quat[0] = cj * cc + sj * ss;
1458  quat[1] = cj * sc - sj * cs;
1459  quat[2] = cj * ss + sj * cc;
1460  quat[3] = cj * cs - sj * sc;
1461 }
1462 
1463 /* XYZ order */
1464 void rotate_eul(float beul[3], const char axis, const float ang)
1465 {
1466  float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
1467 
1468  BLI_assert(axis >= 'X' && axis <= 'Z');
1469 
1470  eul[0] = eul[1] = eul[2] = 0.0f;
1471  if (axis == 'X') {
1472  eul[0] = ang;
1473  }
1474  else if (axis == 'Y') {
1475  eul[1] = ang;
1476  }
1477  else {
1478  eul[2] = ang;
1479  }
1480 
1481  eul_to_mat3(mat1, eul);
1482  eul_to_mat3(mat2, beul);
1483 
1484  mul_m3_m3m3(totmat, mat2, mat1);
1485 
1486  mat3_to_eul(beul, totmat);
1487 }
1488 
1489 /* order independent! */
1490 void compatible_eul(float eul[3], const float oldrot[3])
1491 {
1492  /* we could use M_PI as pi_thresh: which is correct but 5.1 gives better results.
1493  * Checked with baking actions to fcurves - campbell */
1494  const float pi_thresh = (5.1f);
1495  const float pi_x2 = (2.0f * (float)M_PI);
1496 
1497  float deul[3];
1498  unsigned int i;
1499 
1500  /* correct differences of about 360 degrees first */
1501  for (i = 0; i < 3; i++) {
1502  deul[i] = eul[i] - oldrot[i];
1503  if (deul[i] > pi_thresh) {
1504  eul[i] -= floorf((deul[i] / pi_x2) + 0.5f) * pi_x2;
1505  deul[i] = eul[i] - oldrot[i];
1506  }
1507  else if (deul[i] < -pi_thresh) {
1508  eul[i] += floorf((-deul[i] / pi_x2) + 0.5f) * pi_x2;
1509  deul[i] = eul[i] - oldrot[i];
1510  }
1511  }
1512 
1513  /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */
1514  if (fabsf(deul[0]) > 3.2f && fabsf(deul[1]) < 1.6f && fabsf(deul[2]) < 1.6f) {
1515  if (deul[0] > 0.0f) {
1516  eul[0] -= pi_x2;
1517  }
1518  else {
1519  eul[0] += pi_x2;
1520  }
1521  }
1522  if (fabsf(deul[1]) > 3.2f && fabsf(deul[2]) < 1.6f && fabsf(deul[0]) < 1.6f) {
1523  if (deul[1] > 0.0f) {
1524  eul[1] -= pi_x2;
1525  }
1526  else {
1527  eul[1] += pi_x2;
1528  }
1529  }
1530  if (fabsf(deul[2]) > 3.2f && fabsf(deul[0]) < 1.6f && fabsf(deul[1]) < 1.6f) {
1531  if (deul[2] > 0.0f) {
1532  eul[2] -= pi_x2;
1533  }
1534  else {
1535  eul[2] += pi_x2;
1536  }
1537  }
1538 }
1539 
1540 /* uses 2 methods to retrieve eulers, and picks the closest */
1541 
1542 /* XYZ order */
1543 void mat3_normalized_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
1544 {
1545  float eul1[3], eul2[3];
1546  float d1, d2;
1547 
1548  mat3_normalized_to_eul2(mat, eul1, eul2);
1549 
1550  compatible_eul(eul1, oldrot);
1551  compatible_eul(eul2, oldrot);
1552 
1553  d1 = fabsf(eul1[0] - oldrot[0]) + fabsf(eul1[1] - oldrot[1]) + fabsf(eul1[2] - oldrot[2]);
1554  d2 = fabsf(eul2[0] - oldrot[0]) + fabsf(eul2[1] - oldrot[1]) + fabsf(eul2[2] - oldrot[2]);
1555 
1556  /* return best, which is just the one with lowest difference */
1557  if (d1 > d2) {
1558  copy_v3_v3(eul, eul2);
1559  }
1560  else {
1561  copy_v3_v3(eul, eul1);
1562  }
1563 }
1564 void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
1565 {
1566  float unit_mat[3][3];
1567  normalize_m3_m3(unit_mat, mat);
1568  mat3_normalized_to_compatible_eul(eul, oldrot, unit_mat);
1569 }
1570 
1571 void quat_to_compatible_eul(float eul[3], const float oldrot[3], const float quat[4])
1572 {
1573  float unit_mat[3][3];
1574  quat_to_mat3(unit_mat, quat);
1575  mat3_normalized_to_compatible_eul(eul, oldrot, unit_mat);
1576 }
1577 
1578 /************************** Arbitrary Order Eulers ***************************/
1579 
1580 /* Euler Rotation Order Code:
1581  * was adapted from
1582  * ANSI C code from the article
1583  * "Euler Angle Conversion"
1584  * by Ken Shoemake <shoemake@graphics.cis.upenn.edu>
1585  * in "Graphics Gems IV", Academic Press, 1994
1586  * for use in Blender
1587  */
1588 
1589 /* Type for rotation order info - see wiki for derivation details */
1590 typedef struct RotOrderInfo {
1591  short axis[3];
1592  short parity; /* parity of axis permutation (even=0, odd=1) - 'n' in original code */
1594 
1595 /* Array of info for Rotation Order calculations
1596  * WARNING: must be kept in same order as eEulerRotationOrders
1597  */
1598 static const RotOrderInfo rotOrders[] = {
1599  /* i, j, k, n */
1600  {{0, 1, 2}, 0}, /* XYZ */
1601  {{0, 2, 1}, 1}, /* XZY */
1602  {{1, 0, 2}, 1}, /* YXZ */
1603  {{1, 2, 0}, 0}, /* YZX */
1604  {{2, 0, 1}, 0}, /* ZXY */
1605  {{2, 1, 0}, 1} /* ZYX */
1606 };
1607 
1608 /* Get relevant pointer to rotation order set from the array
1609  * NOTE: since we start at 1 for the values, but arrays index from 0,
1610  * there is -1 factor involved in this process...
1611  */
1612 static const RotOrderInfo *get_rotation_order_info(const short order)
1613 {
1614  BLI_assert(order >= 0 && order <= 6);
1615  if (order < 1) {
1616  return &rotOrders[0];
1617  }
1618  if (order < 6) {
1619  return &rotOrders[order - 1];
1620  }
1621 
1622  return &rotOrders[5];
1623 }
1624 
1625 /* Construct quaternion from Euler angles (in radians). */
1626 void eulO_to_quat(float q[4], const float e[3], const short order)
1627 {
1629  short i = R->axis[0], j = R->axis[1], k = R->axis[2];
1630  double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
1631  double a[3];
1632 
1633  ti = e[i] * 0.5f;
1634  tj = e[j] * (R->parity ? -0.5f : 0.5f);
1635  th = e[k] * 0.5f;
1636 
1637  ci = cos(ti);
1638  cj = cos(tj);
1639  ch = cos(th);
1640  si = sin(ti);
1641  sj = sin(tj);
1642  sh = sin(th);
1643 
1644  cc = ci * ch;
1645  cs = ci * sh;
1646  sc = si * ch;
1647  ss = si * sh;
1648 
1649  a[i] = cj * sc - sj * cs;
1650  a[j] = cj * ss + sj * cc;
1651  a[k] = cj * cs - sj * sc;
1652 
1653  q[0] = (float)(cj * cc + sj * ss);
1654  q[1] = (float)(a[0]);
1655  q[2] = (float)(a[1]);
1656  q[3] = (float)(a[2]);
1657 
1658  if (R->parity) {
1659  q[j + 1] = -q[j + 1];
1660  }
1661 }
1662 
1663 /* Convert quaternion to Euler angles (in radians). */
1664 void quat_to_eulO(float e[3], short const order, const float q[4])
1665 {
1666  float unit_mat[3][3];
1667 
1668  quat_to_mat3(unit_mat, q);
1669  mat3_normalized_to_eulO(e, order, unit_mat);
1670 }
1671 
1672 /* Construct 3x3 matrix from Euler angles (in radians). */
1673 void eulO_to_mat3(float M[3][3], const float e[3], const short order)
1674 {
1676  short i = R->axis[0], j = R->axis[1], k = R->axis[2];
1677  double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
1678 
1679  if (R->parity) {
1680  ti = -e[i];
1681  tj = -e[j];
1682  th = -e[k];
1683  }
1684  else {
1685  ti = e[i];
1686  tj = e[j];
1687  th = e[k];
1688  }
1689 
1690  ci = cos(ti);
1691  cj = cos(tj);
1692  ch = cos(th);
1693  si = sin(ti);
1694  sj = sin(tj);
1695  sh = sin(th);
1696 
1697  cc = ci * ch;
1698  cs = ci * sh;
1699  sc = si * ch;
1700  ss = si * sh;
1701 
1702  M[i][i] = (float)(cj * ch);
1703  M[j][i] = (float)(sj * sc - cs);
1704  M[k][i] = (float)(sj * cc + ss);
1705  M[i][j] = (float)(cj * sh);
1706  M[j][j] = (float)(sj * ss + cc);
1707  M[k][j] = (float)(sj * cs - sc);
1708  M[i][k] = (float)(-sj);
1709  M[j][k] = (float)(cj * si);
1710  M[k][k] = (float)(cj * ci);
1711 }
1712 
1713 /* returns two euler calculation methods, so we can pick the best */
1714 static void mat3_normalized_to_eulo2(const float mat[3][3],
1715  float eul1[3],
1716  float eul2[3],
1717  const short order)
1718 {
1720  short i = R->axis[0], j = R->axis[1], k = R->axis[2];
1721  float cy;
1722 
1723  BLI_ASSERT_UNIT_M3(mat);
1724 
1725  cy = hypotf(mat[i][i], mat[i][j]);
1726 
1727  if (cy > 16.0f * FLT_EPSILON) {
1728  eul1[i] = atan2f(mat[j][k], mat[k][k]);
1729  eul1[j] = atan2f(-mat[i][k], cy);
1730  eul1[k] = atan2f(mat[i][j], mat[i][i]);
1731 
1732  eul2[i] = atan2f(-mat[j][k], -mat[k][k]);
1733  eul2[j] = atan2f(-mat[i][k], -cy);
1734  eul2[k] = atan2f(-mat[i][j], -mat[i][i]);
1735  }
1736  else {
1737  eul1[i] = atan2f(-mat[k][j], mat[j][j]);
1738  eul1[j] = atan2f(-mat[i][k], cy);
1739  eul1[k] = 0;
1740 
1741  copy_v3_v3(eul2, eul1);
1742  }
1743 
1744  if (R->parity) {
1745  negate_v3(eul1);
1746  negate_v3(eul2);
1747  }
1748 }
1749 
1750 /* Construct 4x4 matrix from Euler angles (in radians). */
1751 void eulO_to_mat4(float mat[4][4], const float e[3], const short order)
1752 {
1753  float unit_mat[3][3];
1754 
1755  /* for now, we'll just do this the slow way (i.e. copying matrices) */
1756  eulO_to_mat3(unit_mat, e, order);
1757  copy_m4_m3(mat, unit_mat);
1758 }
1759 
1760 /* Convert 3x3 matrix to Euler angles (in radians). */
1761 void mat3_normalized_to_eulO(float eul[3], const short order, const float m[3][3])
1762 {
1763  float eul1[3], eul2[3];
1764  float d1, d2;
1765 
1766  mat3_normalized_to_eulo2(m, eul1, eul2, order);
1767 
1768  d1 = fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]);
1769  d2 = fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2]);
1770 
1771  /* return best, which is just the one with lowest values it in */
1772  if (d1 > d2) {
1773  copy_v3_v3(eul, eul2);
1774  }
1775  else {
1776  copy_v3_v3(eul, eul1);
1777  }
1778 }
1779 void mat3_to_eulO(float eul[3], const short order, const float m[3][3])
1780 {
1781  float unit_mat[3][3];
1782  normalize_m3_m3(unit_mat, m);
1783  mat3_normalized_to_eulO(eul, order, unit_mat);
1784 }
1785 
1786 /* Convert 4x4 matrix to Euler angles (in radians). */
1787 void mat4_normalized_to_eulO(float eul[3], const short order, const float m[4][4])
1788 {
1789  float mat3[3][3];
1790 
1791  /* for now, we'll just do this the slow way (i.e. copying matrices) */
1792  copy_m3_m4(mat3, m);
1793  mat3_normalized_to_eulO(eul, order, mat3);
1794 }
1795 
1796 void mat4_to_eulO(float eul[3], const short order, const float m[4][4])
1797 {
1798  float mat3[3][3];
1799  copy_m3_m4(mat3, m);
1800  normalize_m3(mat3);
1801  mat3_normalized_to_eulO(eul, order, mat3);
1802 }
1803 
1804 /* uses 2 methods to retrieve eulers, and picks the closest */
1806  const float oldrot[3],
1807  const short order,
1808  const float mat[3][3])
1809 {
1810  float eul1[3], eul2[3];
1811  float d1, d2;
1812 
1813  mat3_normalized_to_eulo2(mat, eul1, eul2, order);
1814 
1815  compatible_eul(eul1, oldrot);
1816  compatible_eul(eul2, oldrot);
1817 
1818  d1 = fabsf(eul1[0] - oldrot[0]) + fabsf(eul1[1] - oldrot[1]) + fabsf(eul1[2] - oldrot[2]);
1819  d2 = fabsf(eul2[0] - oldrot[0]) + fabsf(eul2[1] - oldrot[1]) + fabsf(eul2[2] - oldrot[2]);
1820 
1821  /* return best, which is just the one with lowest difference */
1822  if (d1 > d2) {
1823  copy_v3_v3(eul, eul2);
1824  }
1825  else {
1826  copy_v3_v3(eul, eul1);
1827  }
1828 }
1829 void mat3_to_compatible_eulO(float eul[3],
1830  const float oldrot[3],
1831  const short order,
1832  const float mat[3][3])
1833 {
1834  float unit_mat[3][3];
1835 
1836  normalize_m3_m3(unit_mat, mat);
1837  mat3_normalized_to_compatible_eulO(eul, oldrot, order, unit_mat);
1838 }
1839 
1841  const float oldrot[3],
1842  const short order,
1843  const float m[4][4])
1844 {
1845  float mat3[3][3];
1846 
1847  /* for now, we'll just do this the slow way (i.e. copying matrices) */
1848  copy_m3_m4(mat3, m);
1849  mat3_normalized_to_compatible_eulO(eul, oldrot, order, mat3);
1850 }
1851 void mat4_to_compatible_eulO(float eul[3],
1852  const float oldrot[3],
1853  const short order,
1854  const float m[4][4])
1855 {
1856  float mat3[3][3];
1857 
1858  /* for now, we'll just do this the slow way (i.e. copying matrices) */
1859  copy_m3_m4(mat3, m);
1860  normalize_m3(mat3);
1861  mat3_normalized_to_compatible_eulO(eul, oldrot, order, mat3);
1862 }
1863 
1864 void quat_to_compatible_eulO(float eul[3],
1865  const float oldrot[3],
1866  const short order,
1867  const float quat[4])
1868 {
1869  float unit_mat[3][3];
1870 
1871  quat_to_mat3(unit_mat, quat);
1872  mat3_normalized_to_compatible_eulO(eul, oldrot, order, unit_mat);
1873 }
1874 
1875 /* rotate the given euler by the given angle on the specified axis */
1876 /* NOTE: is this safe to do with different axis orders? */
1877 
1878 void rotate_eulO(float beul[3], const short order, char axis, float ang)
1879 {
1880  float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
1881 
1882  BLI_assert(axis >= 'X' && axis <= 'Z');
1883 
1884  zero_v3(eul);
1885 
1886  if (axis == 'X') {
1887  eul[0] = ang;
1888  }
1889  else if (axis == 'Y') {
1890  eul[1] = ang;
1891  }
1892  else {
1893  eul[2] = ang;
1894  }
1895 
1896  eulO_to_mat3(mat1, eul, order);
1897  eulO_to_mat3(mat2, beul, order);
1898 
1899  mul_m3_m3m3(totmat, mat2, mat1);
1900 
1901  mat3_to_eulO(beul, order, totmat);
1902 }
1903 
1904 /* the matrix is written to as 3 axis vectors */
1905 void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order)
1906 {
1908 
1909  float mat[3][3];
1910  float teul[3];
1911 
1912  /* first axis is local */
1913  eulO_to_mat3(mat, eul, order);
1914  copy_v3_v3(gmat[R->axis[0]], mat[R->axis[0]]);
1915 
1916  /* second axis is local minus first rotation */
1917  copy_v3_v3(teul, eul);
1918  teul[R->axis[0]] = 0;
1919  eulO_to_mat3(mat, teul, order);
1920  copy_v3_v3(gmat[R->axis[1]], mat[R->axis[1]]);
1921 
1922  /* Last axis is global */
1923  zero_v3(gmat[R->axis[2]]);
1924  gmat[R->axis[2]][R->axis[2]] = 1;
1925 }
1926 
1927 /******************************* Dual Quaternions ****************************/
1928 
1958 void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4])
1959 {
1960  float *t, *q, dscale[3], scale[3], basequat[4], mat3[3][3];
1961  float baseRS[4][4], baseinv[4][4], baseR[4][4], baseRinv[4][4];
1962  float R[4][4], S[4][4];
1963 
1964  /* split scaling and rotation, there is probably a faster way to do
1965  * this, it's done like this now to correctly get negative scaling */
1966  mul_m4_m4m4(baseRS, mat, basemat);
1967  mat4_to_size(scale, baseRS);
1968 
1969  dscale[0] = scale[0] - 1.0f;
1970  dscale[1] = scale[1] - 1.0f;
1971  dscale[2] = scale[2] - 1.0f;
1972 
1973  copy_m3_m4(mat3, mat);
1974 
1975  if (!is_orthonormal_m3(mat3) || (determinant_m4(mat) < 0.0f) ||
1976  len_squared_v3(dscale) > square_f(1e-4f)) {
1977  /* extract R and S */
1978  float tmp[4][4];
1979 
1980  /* extra orthogonalize, to avoid flipping with stretched bones */
1981  copy_m4_m4(tmp, baseRS);
1982  orthogonalize_m4(tmp, 1);
1983  mat4_to_quat(basequat, tmp);
1984 
1985  quat_to_mat4(baseR, basequat);
1986  copy_v3_v3(baseR[3], baseRS[3]);
1987 
1988  invert_m4_m4(baseinv, basemat);
1989  mul_m4_m4m4(R, baseR, baseinv);
1990 
1991  invert_m4_m4(baseRinv, baseR);
1992  mul_m4_m4m4(S, baseRinv, baseRS);
1993 
1994  /* set scaling part */
1995  mul_m4_series(dq->scale, basemat, S, baseinv);
1996  dq->scale_weight = 1.0f;
1997  }
1998  else {
1999  /* matrix does not contain scaling */
2000  copy_m4_m4(R, mat);
2001  dq->scale_weight = 0.0f;
2002  }
2003 
2004  /* non-dual part */
2005  mat4_to_quat(dq->quat, R);
2006 
2007  /* dual part */
2008  t = R[3];
2009  q = dq->quat;
2010  dq->trans[0] = -0.5f * (t[0] * q[1] + t[1] * q[2] + t[2] * q[3]);
2011  dq->trans[1] = 0.5f * (t[0] * q[0] + t[1] * q[3] - t[2] * q[2]);
2012  dq->trans[2] = 0.5f * (-t[0] * q[3] + t[1] * q[0] + t[2] * q[1]);
2013  dq->trans[3] = 0.5f * (t[0] * q[2] - t[1] * q[1] + t[2] * q[0]);
2014 }
2015 
2016 void dquat_to_mat4(float R[4][4], const DualQuat *dq)
2017 {
2018  float len, q0[4];
2019  const float *t;
2020 
2021  /* regular quaternion */
2022  copy_qt_qt(q0, dq->quat);
2023 
2024  /* normalize */
2025  len = sqrtf(dot_qtqt(q0, q0));
2026  if (len != 0.0f) {
2027  len = 1.0f / len;
2028  }
2029  mul_qt_fl(q0, len);
2030 
2031  /* rotation */
2032  quat_to_mat4(R, q0);
2033 
2034  /* translation */
2035  t = dq->trans;
2036  R[3][0] = 2.0f * (-t[0] * q0[1] + t[1] * q0[0] - t[2] * q0[3] + t[3] * q0[2]) * len;
2037  R[3][1] = 2.0f * (-t[0] * q0[2] + t[1] * q0[3] + t[2] * q0[0] - t[3] * q0[1]) * len;
2038  R[3][2] = 2.0f * (-t[0] * q0[3] - t[1] * q0[2] + t[2] * q0[1] + t[3] * q0[0]) * len;
2039 
2040  /* scaling */
2041  if (dq->scale_weight) {
2042  mul_m4_m4m4(R, R, dq->scale);
2043  }
2044 }
2045 
2046 void add_weighted_dq_dq(DualQuat *dq_sum, const DualQuat *dq, float weight)
2047 {
2048  bool flipped = false;
2049 
2050  /* make sure we interpolate quats in the right direction */
2051  if (dot_qtqt(dq->quat, dq_sum->quat) < 0) {
2052  flipped = true;
2053  weight = -weight;
2054  }
2055 
2056  /* interpolate rotation and translation */
2057  dq_sum->quat[0] += weight * dq->quat[0];
2058  dq_sum->quat[1] += weight * dq->quat[1];
2059  dq_sum->quat[2] += weight * dq->quat[2];
2060  dq_sum->quat[3] += weight * dq->quat[3];
2061 
2062  dq_sum->trans[0] += weight * dq->trans[0];
2063  dq_sum->trans[1] += weight * dq->trans[1];
2064  dq_sum->trans[2] += weight * dq->trans[2];
2065  dq_sum->trans[3] += weight * dq->trans[3];
2066 
2067  /* Interpolate scale - but only if there is scale present. If any dual
2068  * quaternions without scale are added, they will be compensated for in
2069  * normalize_dq. */
2070  if (dq->scale_weight) {
2071  float wmat[4][4];
2072 
2073  if (flipped) {
2074  /* we don't want negative weights for scaling */
2075  weight = -weight;
2076  }
2077 
2078  copy_m4_m4(wmat, (float(*)[4])dq->scale);
2079  mul_m4_fl(wmat, weight);
2080  add_m4_m4m4(dq_sum->scale, dq_sum->scale, wmat);
2081  dq_sum->scale_weight += weight;
2082  }
2083 }
2084 
2085 void normalize_dq(DualQuat *dq, float totweight)
2086 {
2087  const float scale = 1.0f / totweight;
2088 
2089  mul_qt_fl(dq->quat, scale);
2090  mul_qt_fl(dq->trans, scale);
2091 
2092  /* Handle scale if needed. */
2093  if (dq->scale_weight) {
2094  /* Compensate for any dual quaternions added without scale. This is an
2095  * optimization so that we can skip the scale part when not needed. */
2096  float addweight = totweight - dq->scale_weight;
2097 
2098  if (addweight) {
2099  dq->scale[0][0] += addweight;
2100  dq->scale[1][1] += addweight;
2101  dq->scale[2][2] += addweight;
2102  dq->scale[3][3] += addweight;
2103  }
2104 
2105  mul_m4_fl(dq->scale, scale);
2106  dq->scale_weight = 1.0f;
2107  }
2108 }
2109 
2110 void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq)
2111 {
2112  float M[3][3], t[3], scalemat[3][3], len2;
2113  float w = dq->quat[0], x = dq->quat[1], y = dq->quat[2], z = dq->quat[3];
2114  float t0 = dq->trans[0], t1 = dq->trans[1], t2 = dq->trans[2], t3 = dq->trans[3];
2115 
2116  /* rotation matrix */
2117  M[0][0] = w * w + x * x - y * y - z * z;
2118  M[1][0] = 2 * (x * y - w * z);
2119  M[2][0] = 2 * (x * z + w * y);
2120 
2121  M[0][1] = 2 * (x * y + w * z);
2122  M[1][1] = w * w + y * y - x * x - z * z;
2123  M[2][1] = 2 * (y * z - w * x);
2124 
2125  M[0][2] = 2 * (x * z - w * y);
2126  M[1][2] = 2 * (y * z + w * x);
2127  M[2][2] = w * w + z * z - x * x - y * y;
2128 
2129  len2 = dot_qtqt(dq->quat, dq->quat);
2130  if (len2 > 0.0f) {
2131  len2 = 1.0f / len2;
2132  }
2133 
2134  /* translation */
2135  t[0] = 2 * (-t0 * x + w * t1 - t2 * z + y * t3);
2136  t[1] = 2 * (-t0 * y + t1 * z - x * t3 + w * t2);
2137  t[2] = 2 * (-t0 * z + x * t2 + w * t3 - t1 * y);
2138 
2139  /* apply scaling */
2140  if (dq->scale_weight) {
2141  mul_m4_v3(dq->scale, r);
2142  }
2143 
2144  /* apply rotation and translation */
2145  mul_m3_v3(M, r);
2146  r[0] = (r[0] + t[0]) * len2;
2147  r[1] = (r[1] + t[1]) * len2;
2148  r[2] = (r[2] + t[2]) * len2;
2149 
2150  /* Compute crazy-space correction matrix. */
2151  if (R) {
2152  if (dq->scale_weight) {
2153  copy_m3_m4(scalemat, dq->scale);
2154  mul_m3_m3m3(R, M, scalemat);
2155  }
2156  else {
2157  copy_m3_m3(R, M);
2158  }
2159  mul_m3_fl(R, len2);
2160  }
2161 }
2162 
2163 void copy_dq_dq(DualQuat *r, const DualQuat *dq)
2164 {
2165  memcpy(r, dq, sizeof(DualQuat));
2166 }
2167 
2168 /* axis matches eTrackToAxis_Modes */
2169 void quat_apply_track(float quat[4], short axis, short upflag)
2170 {
2171  /* rotations are hard coded to match vec_to_quat */
2172  const float sqrt_1_2 = (float)M_SQRT1_2;
2173  const float quat_track[][4] = {
2174  /* pos-y90 */
2175  {sqrt_1_2, 0.0, -sqrt_1_2, 0.0},
2176  /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */
2177  {0.5, 0.5, 0.5, 0.5},
2178  /* pos-z90 */
2179  {sqrt_1_2, 0.0, 0.0, sqrt_1_2},
2180  /* neg-y90 */
2181  {sqrt_1_2, 0.0, sqrt_1_2, 0.0},
2182  /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */
2183  {0.5, -0.5, -0.5, 0.5},
2184  /* no rotation */
2185  {0.0, sqrt_1_2, sqrt_1_2, 0.0},
2186  };
2187 
2188  BLI_assert(axis >= 0 && axis <= 5);
2189  BLI_assert(upflag >= 0 && upflag <= 2);
2190 
2191  mul_qt_qtqt(quat, quat, quat_track[axis]);
2192 
2193  if (axis > 2) {
2194  axis = (short)(axis - 3);
2195  }
2196 
2197  /* there are 2 possible up-axis for each axis used, the 'quat_track' applies so the first
2198  * up axis is used X->Y, Y->X, Z->X, if this first up axis isn't used then rotate 90d
2199  * the strange bit shift below just find the low axis {X:Y, Y:X, Z:X} */
2200  if (upflag != (2 - axis) >> 1) {
2201  float q[4] = {sqrt_1_2, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */
2202  q[axis + 1] = ((axis == 1)) ? sqrt_1_2 : -sqrt_1_2; /* flip non Y axis */
2203  mul_qt_qtqt(quat, quat, q);
2204  }
2205 }
2206 
2207 void vec_apply_track(float vec[3], short axis)
2208 {
2209  float tvec[3];
2210 
2211  BLI_assert(axis >= 0 && axis <= 5);
2212 
2213  copy_v3_v3(tvec, vec);
2214 
2215  switch (axis) {
2216  case 0: /* pos-x */
2217  /* vec[0] = 0.0; */
2218  vec[1] = tvec[2];
2219  vec[2] = -tvec[1];
2220  break;
2221  case 1: /* pos-y */
2222  /* vec[0] = tvec[0]; */
2223  /* vec[1] = 0.0; */
2224  /* vec[2] = tvec[2]; */
2225  break;
2226  case 2: /* pos-z */
2227  /* vec[0] = tvec[0]; */
2228  /* vec[1] = tvec[1]; */
2229  /* vec[2] = 0.0; */
2230  break;
2231  case 3: /* neg-x */
2232  /* vec[0] = 0.0; */
2233  vec[1] = tvec[2];
2234  vec[2] = -tvec[1];
2235  break;
2236  case 4: /* neg-y */
2237  vec[0] = -tvec[2];
2238  /* vec[1] = 0.0; */
2239  vec[2] = tvec[0];
2240  break;
2241  case 5: /* neg-z */
2242  vec[0] = -tvec[0];
2243  vec[1] = -tvec[1];
2244  /* vec[2] = 0.0; */
2245  break;
2246  }
2247 }
2248 
2249 /* lens/angle conversion (radians) */
2250 float focallength_to_fov(float focal_length, float sensor)
2251 {
2252  return 2.0f * atanf((sensor / 2.0f) / focal_length);
2253 }
2254 
2255 float fov_to_focallength(float hfov, float sensor)
2256 {
2257  return (sensor / 2.0f) / tanf(hfov * 0.5f);
2258 }
2259 
2260 /* 'mod_inline(-3, 4)= 1', 'fmod(-3, 4)= -3' */
2261 static float mod_inline(float a, float b)
2262 {
2263  return a - (b * floorf(a / b));
2264 }
2265 
2266 float angle_wrap_rad(float angle)
2267 {
2268  return mod_inline(angle + (float)M_PI, (float)M_PI * 2.0f) - (float)M_PI;
2269 }
2270 
2271 float angle_wrap_deg(float angle)
2272 {
2273  return mod_inline(angle + 180.0f, 360.0f) - 180.0f;
2274 }
2275 
2276 /* returns an angle compatible with angle_compat */
2277 float angle_compat_rad(float angle, float angle_compat)
2278 {
2279  return angle_compat + angle_wrap_rad(angle - angle_compat);
2280 }
2281 
2282 /* axis conversion */
2283 static float _axis_convert_matrix[23][3][3] = {
2284  {{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}},
2285  {{-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}},
2286  {{-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}},
2287  {{-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}},
2288  {{0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
2289  {{0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
2290  {{0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
2291  {{0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
2292  {{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}},
2293  {{0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}},
2294  {{0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}},
2295  {{0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}},
2296  {{0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}},
2297  {{0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}},
2298  {{0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}},
2299  {{0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}},
2300  {{0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
2301  {{0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
2302  {{0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
2303  {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
2304  {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}},
2305  {{1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}},
2306  {{1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}},
2307 };
2308 
2309 static int _axis_convert_lut[23][24] = {
2310  {0x8C8, 0x4D0, 0x2E0, 0xAE8, 0x701, 0x511, 0x119, 0xB29, 0x682, 0x88A, 0x09A, 0x2A2,
2311  0x80B, 0x413, 0x223, 0xA2B, 0x644, 0x454, 0x05C, 0xA6C, 0x745, 0x94D, 0x15D, 0x365},
2312  {0xAC8, 0x8D0, 0x4E0, 0x2E8, 0x741, 0x951, 0x159, 0x369, 0x702, 0xB0A, 0x11A, 0x522,
2313  0xA0B, 0x813, 0x423, 0x22B, 0x684, 0x894, 0x09C, 0x2AC, 0x645, 0xA4D, 0x05D, 0x465},
2314  {0x4C8, 0x2D0, 0xAE0, 0x8E8, 0x681, 0x291, 0x099, 0x8A9, 0x642, 0x44A, 0x05A, 0xA62,
2315  0x40B, 0x213, 0xA23, 0x82B, 0x744, 0x354, 0x15C, 0x96C, 0x705, 0x50D, 0x11D, 0xB25},
2316  {0x2C8, 0xAD0, 0x8E0, 0x4E8, 0x641, 0xA51, 0x059, 0x469, 0x742, 0x34A, 0x15A, 0x962,
2317  0x20B, 0xA13, 0x823, 0x42B, 0x704, 0xB14, 0x11C, 0x52C, 0x685, 0x28D, 0x09D, 0x8A5},
2318  {0x708, 0xB10, 0x120, 0x528, 0x8C1, 0xAD1, 0x2D9, 0x4E9, 0x942, 0x74A, 0x35A, 0x162,
2319  0x64B, 0xA53, 0x063, 0x46B, 0x804, 0xA14, 0x21C, 0x42C, 0x885, 0x68D, 0x29D, 0x0A5},
2320  {0xB08, 0x110, 0x520, 0x728, 0x941, 0x151, 0x359, 0x769, 0x802, 0xA0A, 0x21A, 0x422,
2321  0xA4B, 0x053, 0x463, 0x66B, 0x884, 0x094, 0x29C, 0x6AC, 0x8C5, 0xACD, 0x2DD, 0x4E5},
2322  {0x508, 0x710, 0xB20, 0x128, 0x881, 0x691, 0x299, 0x0A9, 0x8C2, 0x4CA, 0x2DA, 0xAE2,
2323  0x44B, 0x653, 0xA63, 0x06B, 0x944, 0x754, 0x35C, 0x16C, 0x805, 0x40D, 0x21D, 0xA25},
2324  {0x108, 0x510, 0x720, 0xB28, 0x801, 0x411, 0x219, 0xA29, 0x882, 0x08A, 0x29A, 0x6A2,
2325  0x04B, 0x453, 0x663, 0xA6B, 0x8C4, 0x4D4, 0x2DC, 0xAEC, 0x945, 0x14D, 0x35D, 0x765},
2326  {0x748, 0x350, 0x160, 0x968, 0xAC1, 0x2D1, 0x4D9, 0x8E9, 0xA42, 0x64A, 0x45A, 0x062,
2327  0x68B, 0x293, 0x0A3, 0x8AB, 0xA04, 0x214, 0x41C, 0x82C, 0xB05, 0x70D, 0x51D, 0x125},
2328  {0x948, 0x750, 0x360, 0x168, 0xB01, 0x711, 0x519, 0x129, 0xAC2, 0x8CA, 0x4DA, 0x2E2,
2329  0x88B, 0x693, 0x2A3, 0x0AB, 0xA44, 0x654, 0x45C, 0x06C, 0xA05, 0x80D, 0x41D, 0x225},
2330  {0x348, 0x150, 0x960, 0x768, 0xA41, 0x051, 0x459, 0x669, 0xA02, 0x20A, 0x41A, 0x822,
2331  0x28B, 0x093, 0x8A3, 0x6AB, 0xB04, 0x114, 0x51C, 0x72C, 0xAC5, 0x2CD, 0x4DD, 0x8E5},
2332  {0x148, 0x950, 0x760, 0x368, 0xA01, 0x811, 0x419, 0x229, 0xB02, 0x10A, 0x51A, 0x722,
2333  0x08B, 0x893, 0x6A3, 0x2AB, 0xAC4, 0x8D4, 0x4DC, 0x2EC, 0xA45, 0x04D, 0x45D, 0x665},
2334  {0x688, 0x890, 0x0A0, 0x2A8, 0x4C1, 0x8D1, 0xAD9, 0x2E9, 0x502, 0x70A, 0xB1A, 0x122,
2335  0x74B, 0x953, 0x163, 0x36B, 0x404, 0x814, 0xA1C, 0x22C, 0x445, 0x64D, 0xA5D, 0x065},
2336  {0x888, 0x090, 0x2A0, 0x6A8, 0x501, 0x111, 0xB19, 0x729, 0x402, 0x80A, 0xA1A, 0x222,
2337  0x94B, 0x153, 0x363, 0x76B, 0x444, 0x054, 0xA5C, 0x66C, 0x4C5, 0x8CD, 0xADD, 0x2E5},
2338  {0x288, 0x690, 0x8A0, 0x0A8, 0x441, 0x651, 0xA59, 0x069, 0x4C2, 0x2CA, 0xADA, 0x8E2,
2339  0x34B, 0x753, 0x963, 0x16B, 0x504, 0x714, 0xB1C, 0x12C, 0x405, 0x20D, 0xA1D, 0x825},
2340  {0x088, 0x290, 0x6A0, 0x8A8, 0x401, 0x211, 0xA19, 0x829, 0x442, 0x04A, 0xA5A, 0x662,
2341  0x14B, 0x353, 0x763, 0x96B, 0x4C4, 0x2D4, 0xADC, 0x8EC, 0x505, 0x10D, 0xB1D, 0x725},
2342  {0x648, 0x450, 0x060, 0xA68, 0x2C1, 0x4D1, 0x8D9, 0xAE9, 0x282, 0x68A, 0x89A, 0x0A2,
2343  0x70B, 0x513, 0x123, 0xB2B, 0x204, 0x414, 0x81C, 0xA2C, 0x345, 0x74D, 0x95D, 0x165},
2344  {0xA48, 0x650, 0x460, 0x068, 0x341, 0x751, 0x959, 0x169, 0x2C2, 0xACA, 0x8DA, 0x4E2,
2345  0xB0B, 0x713, 0x523, 0x12B, 0x284, 0x694, 0x89C, 0x0AC, 0x205, 0xA0D, 0x81D, 0x425},
2346  {0x448, 0x050, 0xA60, 0x668, 0x281, 0x091, 0x899, 0x6A9, 0x202, 0x40A, 0x81A, 0xA22,
2347  0x50B, 0x113, 0xB23, 0x72B, 0x344, 0x154, 0x95C, 0x76C, 0x2C5, 0x4CD, 0x8DD, 0xAE5},
2348  {0x048, 0xA50, 0x660, 0x468, 0x201, 0xA11, 0x819, 0x429, 0x342, 0x14A, 0x95A, 0x762,
2349  0x10B, 0xB13, 0x723, 0x52B, 0x2C4, 0xAD4, 0x8DC, 0x4EC, 0x285, 0x08D, 0x89D, 0x6A5},
2350  {0x808, 0xA10, 0x220, 0x428, 0x101, 0xB11, 0x719, 0x529, 0x142, 0x94A, 0x75A, 0x362,
2351  0x8CB, 0xAD3, 0x2E3, 0x4EB, 0x044, 0xA54, 0x65C, 0x46C, 0x085, 0x88D, 0x69D, 0x2A5},
2352  {0xA08, 0x210, 0x420, 0x828, 0x141, 0x351, 0x759, 0x969, 0x042, 0xA4A, 0x65A, 0x462,
2353  0xACB, 0x2D3, 0x4E3, 0x8EB, 0x084, 0x294, 0x69C, 0x8AC, 0x105, 0xB0D, 0x71D, 0x525},
2354  {0x408, 0x810, 0xA20, 0x228, 0x081, 0x891, 0x699, 0x2A9, 0x102, 0x50A, 0x71A, 0xB22,
2355  0x4CB, 0x8D3, 0xAE3, 0x2EB, 0x144, 0x954, 0x75C, 0x36C, 0x045, 0x44D, 0x65D, 0xA65},
2356 };
2357 
2358 // _axis_convert_num = {'X': 0, 'Y': 1, 'Z': 2, '-X': 3, '-Y': 4, '-Z': 5}
2359 
2360 BLI_INLINE int _axis_signed(const int axis)
2361 {
2362  return (axis < 3) ? axis : axis - 3;
2363 }
2364 
2370  int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
2371 {
2372  int value;
2373 
2374  if (src_forward == dst_forward && src_up == dst_up) {
2375  unit_m3(r_mat);
2376  return false;
2377  }
2378 
2379  if ((_axis_signed(src_forward) == _axis_signed(src_up)) ||
2380  (_axis_signed(dst_forward) == _axis_signed(dst_up))) {
2381  /* we could assert here! */
2382  unit_m3(r_mat);
2383  return false;
2384  }
2385 
2386  value = ((src_forward << (0 * 3)) | (src_up << (1 * 3)) | (dst_forward << (2 * 3)) |
2387  (dst_up << (3 * 3)));
2388 
2389  for (uint i = 0; i < (ARRAY_SIZE(_axis_convert_matrix)); i++) {
2390  for (uint j = 0; j < (ARRAY_SIZE(*_axis_convert_lut)); j++) {
2391  if (_axis_convert_lut[i][j] == value) {
2392  copy_m3_m3(r_mat, _axis_convert_matrix[i]);
2393  return true;
2394  }
2395  }
2396  }
2397  // BLI_assert(0);
2398  return false;
2399 }
2400 
2404 bool mat3_from_axis_conversion_single(int src_axis, int dst_axis, float r_mat[3][3])
2405 {
2406  if (src_axis == dst_axis) {
2407  unit_m3(r_mat);
2408  return false;
2409  }
2410 
2411  /* Pick predictable next axis. */
2412  int src_axis_next = (src_axis + 1) % 3;
2413  int dst_axis_next = (dst_axis + 1) % 3;
2414 
2415  if ((src_axis < 3) != (dst_axis < 3)) {
2416  /* Flip both axis so matrix sign remains positive. */
2417  dst_axis_next += 3;
2418  }
2419 
2420  return mat3_from_axis_conversion(src_axis, src_axis_next, dst_axis, dst_axis_next, r_mat);
2421 }
typedef float(TangentPoint)[2]
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_INLINE
MINLINE float saacos(float fac)
#define BLI_ASSERT_UNIT_EPSILON
#define M_SQRT2
Definition: BLI_math_base.h:47
#define BLI_ASSERT_UNIT_M3(m)
#define M_PI_2
Definition: BLI_math_base.h:41
MINLINE float square_f(float a)
#define BLI_ASSERT_UNIT_QUAT(q)
#define M_SQRT1_2
Definition: BLI_math_base.h:50
#define BLI_ASSERT_UNIT_V3(v)
#define M_PI
Definition: BLI_math_base.h:38
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition: math_geom.c:51
void orthogonalize_m4(float R[4][4], int axis)
Definition: math_matrix.c:1514
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void mul_m4_fl(float R[4][4], float f)
Definition: math_matrix.c:971
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void normalize_m3_m3(float R[3][3], const float M[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1934
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
void add_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:1047
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void mul_m3_fl(float R[3][3], float f)
Definition: math_matrix.c:960
void unit_m4(float m[4][4])
Definition: rct.c:1140
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:120
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
bool is_orthonormal_m3(const float mat[3][3])
Definition: math_matrix.c:1816
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
#define mul_m4_series(...)
float determinant_m4(const float m[4][4])
Definition: math_matrix.c:2070
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2145
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:391
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void ortho_v3_v3(float out[3], const float v[3])
Definition: math_vector.c:875
MINLINE void negate_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE float len_squared_v4v4(const float a[4], const float b[4]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3_length(float r[3], const float unit_scale)
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
Definition: math_vector.c:505
MINLINE void negate_v4_v4(float r[4], const float a[3])
MINLINE void negate_v4(float r[4])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
unsigned int uint
Definition: BLI_sys_types.h:83
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
#define IN_RANGE_INCL(a, b, c)
#define LIKELY(x)
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint order
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
#define str(s)
uint nor
#define sinf(x)
#define cosf(x)
#define tanf(x)
#define atan2f(x, y)
#define atanf(x)
#define hypotf(x, y)
#define floorf(x)
#define acosf(x)
#define fabsf(x)
#define sqrtf(x)
float angle_compat_rad(float angle, float angle_compat)
void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4])
void eulO_to_quat(float q[4], const float e[3], const short order)
float angle_qtqt(const float q1[4], const float q2[4])
void angle_to_mat2(float R[2][2], const float angle)
void mat3_normalized_to_eulO(float eul[3], const short order, const float m[3][3])
void mat4_to_compatible_eulO(float eul[3], const float oldrot[3], const short order, const float m[4][4])
void mat3_to_quat(float q[4], const float m[3][3])
static const RotOrderInfo * get_rotation_order_info(const short order)
float angle_signed_normalized_qtqt(const float q1[4], const float q2[4])
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void print_qt(const char *str, const float q[4])
void vec_apply_track(float vec[3], short axis)
static void mat3_normalized_to_eulo2(const float mat[3][3], float eul1[3], float eul2[3], const short order)
float angle_normalized_qt(const float q[4])
float tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3])
void mat3_normalized_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
void quat_to_compatible_eulO(float eul[3], const float oldrot[3], const short order, const float quat[4])
void mat3_to_quat_is_ok(float q[4], const float wmat[3][3])
float angle_signed_qt(const float q[4])
void invert_qt_normalized(float q[4])
void invert_qt_qt(float q1[4], const float q2[4])
void conjugate_qt_qt(float q1[4], const float q2[4])
void eul_to_mat3(float mat[3][3], const float eul[3])
static float mod_inline(float a, float b)
void add_weighted_dq_dq(DualQuat *dq_sum, const DualQuat *dq, float weight)
void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order)
void mul_qt_fl(float q[4], const float f)
void quat_to_mat3(float m[3][3], const float q[4])
void mat3_to_eulO(float eul[3], const short order, const float m[3][3])
void axis_angle_normalized_to_mat3_ex(float mat[3][3], const float axis[3], const float angle_sin, const float angle_cos)
void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle)
void sub_qt_qtqt(float q[4], const float a[4], const float b[4])
void axis_angle_to_quat(float r[4], const float axis[3], const float angle)
void rotate_eulO(float beul[3], const short order, char axis, float ang)
float normalize_qt(float q[4])
void invert_qt(float q[4])
void quat_normalized_to_expmap(float expmap[3], const float q[4])
void quat_to_mat4(float m[4][4], const float q[4])
void dquat_to_mat4(float R[4][4], const DualQuat *dq)
void mat4_normalized_to_axis_angle(float axis[3], float *angle, const float mat[4][4])
void mat4_normalized_to_eulO(float eul[3], const short order, const float m[4][4])
void mul_qt_v3(const float q[4], float r[3])
Definition: math_rotation.c:97
void unit_qt(float q[4])
Definition: math_rotation.c:46
void mat3_normalized_to_compatible_eulO(float eul[3], const float oldrot[3], const short order, const float mat[3][3])
void quat_to_eulO(float e[3], short const order, const float q[4])
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const float angle)
void eul_to_quat(float quat[4], const float eul[3])
void mat4_to_eulO(float eul[3], const short order, const float m[4][4])
float fov_to_focallength(float hfov, float sensor)
void axis_angle_normalized_to_quat(float r[4], const float axis[3], const float angle)
void pow_qt_fl_normalized(float q[4], const float fac)
void mat4_to_axis_angle(float axis[3], float *angle, const float mat[4][4])
void mat4_normalized_to_eul(float eul[3], const float m[4][4])
float angle_signed_normalized_qt(const float q[4])
void quat_to_eul(float eul[3], const float quat[4])
float normalize_qt_qt(float r[4], const float q[4])
float dot_qtqt(const float a[4], const float b[4])
void invert_qt_qt_normalized(float q1[4], const float q2[4])
static void mat3_normalized_to_eul2(const float mat[3][3], float eul1[3], float eul2[3])
bool is_zero_qt(const float q[4])
Definition: math_rotation.c:60
float quat_split_swing_and_twist(const float q_in[4], int axis, float r_swing[4], float r_twist[4])
void mat4_normalized_to_compatible_eulO(float eul[3], const float oldrot[3], const short order, const float m[4][4])
void mat3_normalized_to_eul(float eul[3], const float mat[3][3])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:65
void axis_angle_to_quat_single(float q[4], const char axis, const float angle)
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
void mat3_to_eul(float eul[3], const float mat[3][3])
void quat_to_expmap(float expmap[3], const float q[4])
static float _axis_convert_matrix[23][3][3]
static void quat_to_mat3_no_error(float m[3][3], const float q[4])
void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4])
void copy_dq_dq(DualQuat *r, const DualQuat *dq)
void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle)
void mat4_to_quat(float q[4], const float m[4][4])
void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
float focallength_to_fov(float focal_length, float sensor)
static int _axis_convert_lut[23][24]
void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle)
void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq)
void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t)
void conjugate_qt(float q[4])
void compatible_eul(float eul[3], const float oldrot[3])
void quat_apply_track(float quat[4], short axis, short upflag)
void mat3_to_compatible_eulO(float eul[3], const float oldrot[3], const short order, const float mat[3][3])
void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const float v3[3], const float no_orig[3])
void eulO_to_mat4(float mat[4][4], const float e[3], const short order)
void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle)
void mat4_to_eul(float eul[3], const float m[4][4])
void quat_to_compatible_eul(float eul[3], const float oldrot[3], const float quat[4])
void mat4_normalized_to_quat(float q[4], const float m[4][4])
void axis_angle_to_mat4_single(float R[4][4], const char axis, const float angle)
float angle_wrap_deg(float angle)
void unit_axis_angle(float axis[3], float *angle)
Definition: math_rotation.c:38
void mat3_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
struct RotOrderInfo RotOrderInfo
float angle_qt(const float q[4])
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:52
float angle_wrap_rad(float angle)
void normalize_dq(DualQuat *dq, float totweight)
void eulO_to_mat3(float M[3][3], const float e[3], const short order)
void quat_to_compatible_quat(float q[4], const float a[4], const float old[4])
void expmap_to_quat(float r[4], const float expmap[3])
BLI_INLINE int _axis_signed(const int axis)
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
void interp_dot_slerp(const float t, const float cosom, float r_w[2])
float angle_signed_qtqt(const float q1[4], const float q2[4])
void rotate_eul(float beul[3], const char axis, const float ang)
static const RotOrderInfo rotOrders[]
void mat3_normalized_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
float angle_normalized_qtqt(const float q1[4], const float q2[4])
void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
void eul_to_mat4(float mat[4][4], const float eul[3])
void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t)
bool mat3_from_axis_conversion_single(int src_axis, int dst_axis, float r_mat[3][3])
void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order)
#define M
#define R
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition: rall1d.h:399
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
const btScalar eps
Definition: poly34.cpp:11
float scale_weight
Definition: DNA_vec_types.h:95
float scale[4][4]
Definition: DNA_vec_types.h:94
float quat[4]
Definition: DNA_vec_types.h:91
float trans[4]
Definition: DNA_vec_types.h:92
ccl_device_inline float2 fabs(const float2 &a)
uint len