ScummVM API documentation
te_quaternion.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TETRAEDGE_TE_TE_QUATERNION_H
23 #define TETRAEDGE_TE_TE_QUATERNION_H
24 
25 #include "math/quat.h"
26 
27 #include "tetraedge/te/te_vector3f32.h"
28 #include "tetraedge/te/te_matrix4x4.h"
29 
30 namespace Tetraedge {
31 
32 class TeQuaternion: public Math::Quaternion {
33 public:
34  TeQuaternion();
35  TeQuaternion(const Math::Quaternion &q) : Math::Quaternion(q) {};
36  TeQuaternion(float a, float b, float c, float d) : Math::Quaternion(a, b, c, d) {};
37 
38  static TeQuaternion fromAxisAndAngle(const TeVector3f32 &axis, float angle) {
39  TeQuaternion ret;
40  float f = sinf(angle * 0.5);
41  ret.x() = axis.x() * f;
42  ret.y() = axis.y() * f;
43  ret.z() = axis.z() * f;
44  ret.w() = cosf(angle * 0.5);
45  return ret;
46  }
47 
48  static TeQuaternion fromEuler(const TeVector3f32 &euler) {
49  TeQuaternion rot;
50 
51  rot.x() = sinf(euler.x() / 2.0);
52  rot.y() = 0.0;
53  rot.z() = 0.0;
54  rot.w() = cosf(euler.x() / 2.0);
55  TeQuaternion retval = rot;
56 
57  rot.x() = 0.0;
58  rot.y() = sinf(euler.y() / 2.0);
59  rot.z() = 0.0;
60  rot.w() = cosf(euler.y() / 2.0);
61  retval *= rot;
62 
63  rot.x() = 0.0;
64  rot.y() = 0.0;
65  rot.z() = sinf(euler.z() / 2.0);
66  rot.w() = cosf(euler.z() / 2.0);
67  retval *= rot;
68 
69  return retval;
70  }
71 
72  static TeQuaternion fromEulerDegrees(const TeVector3f32 &euler) {
73  const float xdeg = (float)(euler.x() * M_PI / 180.0);
74  const float ydeg = (float)(euler.y() * M_PI / 180.0);
75  const float zdeg = (float)(euler.z() * M_PI / 180.0);
76  return fromEuler(TeVector3f32(xdeg, ydeg, zdeg));
77  }
78 
79  TeMatrix4x4 toTeMatrix() const {
80  const TeMatrix4x4 retval = toMatrix();
81  return retval.transpose();
82  }
83 
84  static void deserialize(Common::ReadStream &stream, TeQuaternion &dest) {
85  dest.x() = stream.readFloatLE();
86  dest.y() = stream.readFloatLE();
87  dest.z() = stream.readFloatLE();
88  dest.w() = stream.readFloatLE();
89  }
90 
91  static void serialize(Common::WriteStream &stream, const TeQuaternion &src) {
92  stream.writeFloatLE(src.x());
93  stream.writeFloatLE(src.y());
94  stream.writeFloatLE(src.z());
95  stream.writeFloatLE(src.w());
96  }
97 
98  Common::String dump() const;
99 };
100 
101 } // end namespace Tetraedge
102 
103 #endif // TETRAEDGE_TE_TE_QUATERNION_H
Definition: str.h:59
Definition: detection.h:27
Definition: stream.h:77
Definition: te_quaternion.h:32
Definition: te_matrix4x4.h:37
FORCEINLINE void writeFloatLE(float value)
Definition: stream.h:233
FORCEINLINE float readFloatLE()
Definition: stream.h:615
Definition: te_vector3f32.h:33
Definition: stream.h:385