rot_quat_test.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/qvm/quat_operations.hpp>
  5. #include <boost/qvm/mat_operations.hpp>
  6. #include "test_qvm_matrix.hpp"
  7. #include "test_qvm_quaternion.hpp"
  8. #include "test_qvm_vector.hpp"
  9. #include "gold.hpp"
  10. namespace
  11. {
  12. void
  13. test_x()
  14. {
  15. using namespace boost::qvm;
  16. test_qvm::vector<V1,3> axis; axis.a[0]=1;
  17. for( float r=0; r<6.28f; r+=0.5f )
  18. {
  19. test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
  20. test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
  21. test_qvm::rotation_x(x1.b,r);
  22. BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
  23. test_qvm::quaternion<Q2> q2(42,1);
  24. set_rot(q2,axis,r);
  25. test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
  26. test_qvm::rotation_x(x2.b,r);
  27. BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
  28. test_qvm::quaternion<Q1> q3(42,1);
  29. test_qvm::quaternion<Q1> q4(42,1);
  30. rotate(q3,axis,r);
  31. q3 = q3*q1;
  32. BOOST_QVM_TEST_EQ(q3.a,q3.a);
  33. }
  34. }
  35. void
  36. test_y()
  37. {
  38. using namespace boost::qvm;
  39. test_qvm::vector<V1,3> axis; axis.a[1]=1;
  40. for( float r=0; r<6.28f; r+=0.5f )
  41. {
  42. test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
  43. test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
  44. test_qvm::rotation_y(x1.b,r);
  45. BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
  46. test_qvm::quaternion<Q2> q2(42,1);
  47. set_rot(q2,axis,r);
  48. test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
  49. test_qvm::rotation_y(x2.b,r);
  50. BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
  51. test_qvm::quaternion<Q1> q3(42,1);
  52. test_qvm::quaternion<Q1> q4(42,1);
  53. rotate(q3,axis,r);
  54. q3 = q3*q1;
  55. BOOST_QVM_TEST_EQ(q3.a,q3.a);
  56. }
  57. }
  58. void
  59. test_z()
  60. {
  61. using namespace boost::qvm;
  62. test_qvm::vector<V1,3> axis; axis.a[2]=1;
  63. for( float r=0; r<6.28f; r+=0.5f )
  64. {
  65. test_qvm::quaternion<Q1> q1=rot_quat(axis,r);
  66. test_qvm::matrix<M1,3,3> x1=convert_to< test_qvm::matrix<M1,3,3> >(q1);
  67. test_qvm::rotation_z(x1.b,r);
  68. BOOST_QVM_TEST_CLOSE(x1.a,x1.b,0.000001f);
  69. test_qvm::quaternion<Q2> q2(42,1);
  70. set_rot(q2,axis,r);
  71. test_qvm::matrix<M2,3,3> x2=convert_to< test_qvm::matrix<M2,3,3> >(q2);
  72. test_qvm::rotation_z(x2.b,r);
  73. BOOST_QVM_TEST_CLOSE(x2.a,x2.b,0.000001f);
  74. test_qvm::quaternion<Q1> q3(42,1);
  75. test_qvm::quaternion<Q1> q4(42,1);
  76. rotate(q3,axis,r);
  77. q3 = q3*q1;
  78. BOOST_QVM_TEST_EQ(q3.a,q3.a);
  79. }
  80. }
  81. }
  82. int
  83. main()
  84. {
  85. test_x();
  86. test_y();
  87. test_z();
  88. return boost::report_errors();
  89. }