SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
QuaternionTest.cpp
Go to the documentation of this file.
1 #include <SL.h>
2 #include <SLVec3.h>
3 #include <SLMat3.h>
4 #include <SLMat4.h>
5 #include <SLQuat4.h>
6 
7 int main()
8 {
9  float angleDEG;
10  SLVec3f axis;
11  SLQuat4f q1;
12 
13  cout << "Quaternion q1: 45deg. around y-axis: ";
14  SLMat3f m1(45, 0, 1, 0);
15  q1.fromMat3(m1);
16  q1.toAngleAxis(angleDEG, axis);
17  cout << angleDEG << ", " << axis << endl
18  << endl;
19 
20  cout << "Quaternion q1: 45deg. around y-axis: ";
21  q1.fromAngleAxis(45, SLVec3f(0, 1, 0));
22  q1.toAngleAxis(angleDEG, axis);
23  cout << angleDEG << ", " << axis << endl
24  << endl;
25 
26  cout << "Quaternion to matrix: 45deg. around y-axis: ";
27  SLMat3f m2 = q1.toMat3();
28  m2.toAngleAxis(angleDEG, axis);
29  cout << angleDEG << ", " << axis << endl
30  << endl;
31 
32  cout << "Quaternion q2: 45 deg. around y-axis" << endl;
33  cout << "Quaternion q3 = q1 x q2: 90 deg. around y-axis: ";
34  SLQuat4f q2(45, SLVec3f(0, 1, 0));
35  SLQuat4f q3 = q1.rotated(q2);
36  q3.toAngleAxis(angleDEG, axis);
37  cout << angleDEG << ", " << axis << endl
38  << endl;
39 
40  float t = 0.1f;
41  for (int i = 0; i < 9; ++i)
42  {
43  cout << "Quaternion q1.slerp(" << t << ", q3): ";
44  q1.slerp(q3, t).toAngleAxis(angleDEG, axis);
45  cout << angleDEG << ", " << axis << endl;
46 
47  cout << "Quaternion q1.lerp (" << t << ", q3): ";
48  q1.lerp(q3, t).toAngleAxis(angleDEG, axis);
49  cout << angleDEG << ", " << axis << endl;
50  t += 0.1f;
51  }
52  cout << endl;
53 
54  cout << "Quaternion q1: 45deg. around y-axis: " << endl;
55  cout << "Quaternion q2 = q1.inverted(): ";
56  q1.fromAngleAxis(45, SLVec3f(0, 1, 0));
57  q2 = q1.inverted();
58  q2.toAngleAxis(angleDEG, axis);
59  cout << angleDEG << ", " << axis << endl;
60  cout << "Quaternion q3 = q1 * q2: ";
61  q3 = q1 * q2;
62  q3.toAngleAxis(angleDEG, axis);
63  cout << angleDEG << ", " << axis << endl
64  << endl;
65 
66  cout << "Quaternion q1.fromEuler(0,45,0): " << endl;
67  q1.fromEuler(0, 45, 0);
68  q1.toAngleAxis(angleDEG, axis);
69  cout << angleDEG << ", " << axis << endl;
70 
71  return 0;
72 }
int main()
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
void toAngleAxis(T &angleDEG, SLVec3< T > &axis) const
Conversion to axis and angle in radians.
Definition: SLMat3.h:507
SLQuat4< T > inverted() const
Definition: SLQuat4.h:600
SLQuat4< T > rotated(const SLQuat4< T > &b) const
Definition: SLQuat4.h:669
void fromAngleAxis(T angleRAD, T axisX, T axisY, T axisZ)
Definition: SLQuat4.h:275
SLQuat4< T > slerp(const SLQuat4< T > &q2, T t) const
Definition: SLQuat4.h:745
SLMat3< T > toMat3() const
Definition: SLQuat4.h:318
SLQuat4< T > lerp(const SLQuat4< T > &q2, T t) const
Linear interpolation.
Definition: SLQuat4.h:723
void fromMat3(const SLMat3< T > &m)
Definition: SLQuat4.h:149
void toAngleAxis(T &angleDEG, SLVec3< T > &axis) const
Definition: SLQuat4.h:363