My Project: dynamics.mod/NewtonDynamics/source/core/dgQuaternion.h Source File

My Project

dgQuaternion.h
Go to the documentation of this file.
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 {
33 public:
34 dgQuaternion ();
35 dgQuaternion (const dgMatrix& matrix);
36 dgQuaternion (dgFloat32 q0, dgFloat32 q1, dgFloat32 q2, dgFloat32 q3);
37 dgQuaternion (const dgVector &unit_Axis, dgFloat32 angle = dgFloat32 (0.0f));
38
39 void Scale (dgFloat32 scale);
40 void Normalize ();
41 inline dgFloat32 DotProduct (const dgQuaternion &QB) const;
42 dgQuaternion Inverse () const;
43
44 dgQuaternion Slerp (const dgQuaternion &q1, dgFloat32 t) const;
45 dgVector CalcAverageOmega (const dgQuaternion &q1, dgFloat32 invdt) const;
46
47 dgQuaternion operator* (const dgQuaternion &B) const;
48 dgQuaternion operator+ (const dgQuaternion &B) const;
49 dgQuaternion operator- (const dgQuaternion &B) const;
50
51 dgFloat32 m_q0;
52 dgFloat32 m_q1;
53 dgFloat32 m_q2;
54 dgFloat32 m_q3;
55 }DG_GCC_VECTOR_ALIGMENT;
56
57
58
59
60 inline dgQuaternion::dgQuaternion ()
61 {
62 m_q0 = dgFloat32 (1.0f);
63 m_q1 = dgFloat32 (0.0f);
64 m_q2 = dgFloat32 (0.0f);
65 m_q3 = dgFloat32 (0.0f);
66 }
67
68 inline dgQuaternion::dgQuaternion (dgFloat32 Q0, dgFloat32 Q1, dgFloat32 Q2, dgFloat32 Q3)
69 {
70 m_q0 = Q0;
71 m_q1 = Q1;
72 m_q2 = Q2;
73 m_q3 = Q3;
74 // dgAssert (dgAbsf (DotProduct (*this) -dgFloat32 (1.0f)) < dgFloat32(1.0e-4f));
75 }
76
77
78
79 inline void dgQuaternion::Scale (dgFloat32 scale)
80 {
81 m_q0 *= scale;
82 m_q1 *= scale;
83 m_q2 *= scale;
84 m_q3 *= scale;
85 }
86
87 inline void dgQuaternion::Normalize ()
88 {
89 Scale (dgRsqrt (DotProduct (*this)));
90 }
91
92 inline dgFloat32 dgQuaternion::DotProduct (const dgQuaternion &QB) const
93 {
94 return m_q0 * QB.m_q0 + m_q1 * QB.m_q1 + m_q2 * QB.m_q2 + m_q3 * QB.m_q3;
95 }
96
97 inline dgQuaternion dgQuaternion::Inverse () const
98 {
99 return dgQuaternion (m_q0, -m_q1, -m_q2, -m_q3);
100 }
101
102 inline dgQuaternion dgQuaternion::operator+ (const dgQuaternion &B) const
103 {
104 return dgQuaternion (m_q0 + B.m_q0, m_q1 + B.m_q1, m_q2 + B.m_q2, m_q3 + B.m_q3);
105 }
106
107 inline dgQuaternion dgQuaternion::operator- (const dgQuaternion &B) const
108 {
109 return dgQuaternion (m_q0 - B.m_q0, m_q1 - B.m_q1, m_q2 - B.m_q2, m_q3 - B.m_q3);
110 }
111
112
113 inline dgQuaternion dgQuaternion::operator* (const dgQuaternion &B) const
114 {
115 return dgQuaternion (B.m_q0 * m_q0 - B.m_q1 * m_q1 - B.m_q2 * m_q2 - B.m_q3 * m_q3,
116 B.m_q1 * m_q0 + B.m_q0 * m_q1 - B.m_q3 * m_q2 + B.m_q2 * m_q3,
117 B.m_q2 * m_q0 + B.m_q3 * m_q1 + B.m_q0 * m_q2 - B.m_q1 * m_q3,
118 B.m_q3 * m_q0 - B.m_q2 * m_q1 + B.m_q1 * m_q2 + B.m_q0 * m_q3);
119 }
120
121
122
123 #endif
124
dgQuaternion::operator+
dgQuaternion operator+(const dgQuaternion &B) const
Definition: dgQuaternion.h:102
dgQuaternion::CalcAverageOmega
dgVector CalcAverageOmega(const dgQuaternion &q1, dgFloat32 invdt) const
Definition: dgQuaternion.cpp:101
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgVector
Definition: dgVector.h:639
dgQuaternion::Inverse
dgQuaternion Inverse() const
Definition: dgQuaternion.h:97
dgQuaternion::m_q0
dgFloat32 m_q0
Definition: dgQuaternion.h:51
dgQuaternion
Definition: dgQuaternion.h:31
dgQuaternion::Slerp
dgQuaternion Slerp(const dgQuaternion &q1, dgFloat32 t) const
Definition: dgQuaternion.cpp:123
dgQuaternion::dgQuaternion
dgQuaternion()
Definition: dgQuaternion.h:60
dgQuaternion::operator-
dgQuaternion operator-(const dgQuaternion &B) const
Definition: dgQuaternion.h:107
dgQuaternion::operator*
dgQuaternion operator*(const dgQuaternion &B) const
Definition: dgQuaternion.h:113
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgRsqrt
DG_INLINE dgFloat32 dgRsqrt(dgFloat32 x)
Definition: dgTypes.h:686
dgStdafx.h
dgQuaternion::Normalize
void Normalize()
Definition: dgQuaternion.h:87
dgQuaternion::Scale
void Scale(dgFloat32 scale)
Definition: dgQuaternion.h:79
DG_GCC_VECTOR_ALIGMENT
DG_MSC_VECTOR_ALIGMENT class dgQuaternion DG_GCC_VECTOR_ALIGMENT
dgQuaternion::DotProduct
dgFloat32 DotProduct(const dgQuaternion &QB) const
Definition: dgQuaternion.h:92
dgQuaternion::m_q3
dgFloat32 m_q3
Definition: dgQuaternion.h:54
dgQuaternion::m_q2
dgFloat32 m_q2
Definition: dgQuaternion.h:53
dgMatrix
Definition: dgMatrix.h:40
dgQuaternion::m_q1
dgFloat32 m_q1
Definition: dgQuaternion.h:52