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

source code of boost/libs/qvm/test/rot_quat_test.cpp