mQuatTest.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2014 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifdef TORQUE_TESTS_ENABLED
  23. #include "testing/unitTesting.h"
  24. #include "math/mQuat.h"
  25. #include "math/mAngAxis.h"
  26. #include "math/mMatrix.h"
  27. /// For testing things that should be close to 0, but accounting for floating-
  28. /// point inaccuracy.
  29. static const F32 epsilon = 1e-3f;
  30. /// Test quaternions for equality by expecting the angle between them to be
  31. /// close to 0.
  32. #define EXPECT_QUAT_EQ(q1, q2) EXPECT_LT(q1.angleBetween(q2), epsilon)
  33. TEST(QuatF, AngleBetween)
  34. {
  35. QuatF p(QuatF::Identity), q(QuatF::Identity);
  36. EXPECT_LT(p.angleBetween(q), epsilon)
  37. << "Angle between identity quaternions should be ~0.";
  38. p.set(EulerF(0.1, 0.15, -0.2));
  39. q = p;
  40. EXPECT_LT(p.angleBetween(q), epsilon)
  41. << "Angle between identical quaternions should be ~0.";
  42. }
  43. /// Test conversion from EulerF.
  44. TEST(QuatF, Construction)
  45. {
  46. EulerF eId(0, 0, 0);
  47. EXPECT_QUAT_EQ(QuatF(eId), QuatF::Identity)
  48. << "Quaternions constructed from identity EulerF and QuatF::Identity not equal.";
  49. EulerF eRot(0.0f, -0.0f, 1.5707963267948966f);
  50. MatrixF mat(eRot);
  51. AngAxisF aaRot(mat);
  52. EXPECT_QUAT_EQ(QuatF(eRot), QuatF(aaRot))
  53. << "Quaternions constructed from EulerF and AngAxisF not equal.";
  54. }
  55. #endif