quat.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * OpenHMD - Free and Open Source API and drivers for immersive technology.
  3. * Copyright (C) 2013 Fredrik Hultin.
  4. * Copyright (C) 2013 Jakob Bornecrantz.
  5. * Distributed under the Boost 1.0 licence, see LICENSE for full text.
  6. */
  7. /* Unit Tests - Quaternion Tests */
  8. #include "tests.h"
  9. static const float t = 0.001;
  10. bool quatf_eq(quatf q1, quatf q2, float t)
  11. {
  12. for(int i = 0; i < 4; i++)
  13. if(!float_eq(q1.arr[i], q2.arr[i], t))
  14. return false;
  15. return true;
  16. }
  17. typedef struct {
  18. vec3f v;
  19. float f;
  20. quatf q;
  21. } vec_float_quat;
  22. void test_oquatf_init_axis()
  23. {
  24. //void oquatf_init_axis(quatf* me, const vec3f* vec, float angle);
  25. vec_float_quat list[] = {
  26. { {{0, 0, 0}}, 0, {{0, 0, 0, 1}}},
  27. { {{5, 12, 3}}, 1, {{0.1796723168488794, 0.43121356043731063, 0.10780339010932766, 0.8775825618903728}}},
  28. { {{-2, -3, 3}}, 1, {{-0.2044277365391809, -0.30664160480877134, 0.30664160480877134, 0.8775825618903728}} },
  29. { {{100, -3, 3}}, -300, {{0.7142339081165469, -0.021427017243496407, 0.021427017243496407, 0.6992508064783751}} },
  30. };
  31. int sz = sizeof(vec_float_quat);
  32. for(int i = 0; i < sizeof(list) / sz; i++){
  33. quatf q;
  34. oquatf_init_axis(&q, &list[i].v, list[i].f);
  35. //printf("%f %f %f %f\n", q.x, q.y, q.z, q.w);
  36. TAssert(quatf_eq(q, list[i].q, t));
  37. }
  38. }
  39. typedef struct {
  40. quatf q;
  41. vec3f v1, v2;
  42. } quat_vec2;
  43. void test_oquatf_get_rotated()
  44. {
  45. // void oquatf_get_rotated(const quatf* me, const vec3f* vec, vec3f* out_vec);
  46. quat_vec2 list[] = {
  47. { {{0, 0, 0, 0}}, {{0, 0, 0}}, {{0, 0, 0}} },
  48. { {{0, 0, 0, 0}}, {{1, 2, 3}}, {{0, 0, 0}} },
  49. { {{0, 0, 0, 1}}, {{1, 2, 3}}, {{1, 2, 3}} },
  50. { {{.4, .2, .1, 1}}, {{2, 1, 0}}, {{2.18, 1.59, 0.2}} },
  51. { {{.4, .2, .1, -1}}, {{2, 1, 0}}, {{2.58, 0.79, 0.2}} },
  52. };
  53. int sz = sizeof(quat_vec2);
  54. for(int i = 0; i < sizeof(list) / sz; i++){
  55. vec3f vec;
  56. oquatf_get_rotated(&list[i].q, &list[i].v1, &vec);
  57. TAssert(vec3f_eq(vec, list[i].v2, t));
  58. }
  59. }
  60. void test_oquatf_mult()
  61. {
  62. }
  63. void test_oquatf_normalize()
  64. {
  65. }
  66. void test_oquatf_get_length()
  67. {
  68. }
  69. void test_oquatf_get_mat4x4()
  70. {
  71. }
  72. void test_oquatf_get_mat3x3()
  73. {
  74. }
  75. void test_omat3x3_get_scales()
  76. {
  77. }
  78. void test_omat3x3_get_euler_angles()
  79. {
  80. }