ScummVM API documentation
dgQuaternion.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __dgQuaternion__
23 #define __dgQuaternion__
24 
25 #include "dgStdafx.h"
26 
27 class dgVector;
28 class dgMatrix;
29 
30 DG_MSC_VECTOR_ALIGMENT
31 class dgQuaternion {
32 public:
33  dgQuaternion();
34  dgQuaternion(const dgMatrix &matrix);
35  dgQuaternion(dgFloat32 q0, dgFloat32 q1, dgFloat32 q2, dgFloat32 q3);
36  dgQuaternion(const dgVector &unit_Axis, dgFloat32 angle = dgFloat32(0.0f));
37 
38  void Scale(dgFloat32 scale);
39  void Normalize();
40  inline dgFloat32 DotProduct(const dgQuaternion &QB) const;
41  dgQuaternion Inverse() const;
42 
43  dgQuaternion Slerp(const dgQuaternion &q1, dgFloat32 t) const;
44  dgVector CalcAverageOmega(const dgQuaternion &q1, dgFloat32 dt) const;
45 
46  dgQuaternion operator* (const dgQuaternion &B) const;
47  dgQuaternion operator+ (const dgQuaternion &B) const;
48  dgQuaternion operator- (const dgQuaternion &B) const;
49 
50  dgFloat32 m_q0;
51  dgFloat32 m_q1;
52  dgFloat32 m_q2;
53  dgFloat32 m_q3;
54 } DG_GCC_VECTOR_ALIGMENT;
55 
56 
57 
58 
59 inline dgQuaternion::dgQuaternion() {
60  m_q0 = dgFloat32(1.0f);
61  m_q1 = dgFloat32(0.0f);
62  m_q2 = dgFloat32(0.0f);
63  m_q3 = dgFloat32(0.0f);
64 }
65 
66 inline dgQuaternion::dgQuaternion(dgFloat32 Q0, dgFloat32 Q1, dgFloat32 Q2, dgFloat32 Q3) {
67  m_q0 = Q0;
68  m_q1 = Q1;
69  m_q2 = Q2;
70  m_q3 = Q3;
71 // NEWTON_ASSERT (dgAbsf (DotProduct (*this) -dgFloat32 (1.0f)) < dgFloat32(1.0e-4f));
72 }
73 
74 
75 
76 inline void dgQuaternion::Scale(dgFloat32 scale) {
77  m_q0 *= scale;
78  m_q1 *= scale;
79  m_q2 *= scale;
80  m_q3 *= scale;
81 }
82 
83 inline void dgQuaternion::Normalize() {
84  Scale(dgRsqrt(DotProduct(*this)));
85 }
86 
87 inline dgFloat32 dgQuaternion::DotProduct(const dgQuaternion &QB) const {
88  return m_q0 * QB.m_q0 + m_q1 * QB.m_q1 + m_q2 * QB.m_q2 + m_q3 * QB.m_q3;
89 }
90 
91 inline dgQuaternion dgQuaternion::Inverse() const {
92  return dgQuaternion(m_q0, -m_q1, -m_q2, -m_q3);
93 }
94 
95 inline dgQuaternion dgQuaternion::operator+ (const dgQuaternion &B) const {
96  return dgQuaternion(m_q0 + B.m_q0, m_q1 + B.m_q1, m_q2 + B.m_q2, m_q3 + B.m_q3);
97 }
98 
99 inline dgQuaternion dgQuaternion::operator- (const dgQuaternion &B) const {
100  return dgQuaternion(m_q0 - B.m_q0, m_q1 - B.m_q1, m_q2 - B.m_q2, m_q3 - B.m_q3);
101 }
102 
103 
104 inline dgQuaternion dgQuaternion::operator* (const dgQuaternion &B) const {
105  return dgQuaternion(B.m_q0 * m_q0 - B.m_q1 * m_q1 - B.m_q2 * m_q2 - B.m_q3 * m_q3,
106  B.m_q1 * m_q0 + B.m_q0 * m_q1 - B.m_q3 * m_q2 + B.m_q2 * m_q3,
107  B.m_q2 * m_q0 + B.m_q3 * m_q1 + B.m_q0 * m_q2 - B.m_q1 * m_q3,
108  B.m_q3 * m_q0 - B.m_q2 * m_q1 + B.m_q1 * m_q2 + B.m_q0 * m_q3);
109 }
110 
111 
112 
113 #endif
114 
Definition: dgVector.h:86
Definition: dgQuaternion.h:31
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: dgMatrix.h:41