Newton Dynamics  4.00
ndQuaternion.h
1 /* Copyright (c) <2003-2022> <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 __ND_QUATERNION_H__
23 #define __ND_QUATERNION_H__
24 
25 #include "ndCoreStdafx.h"
26 #include "ndTypes.h"
27 #include "ndVector.h"
28 
29 class ndMatrix;
30 
31 class ndQuaternion: public ndVector
32 {
33  public:
34  ndQuaternion();
35  ndQuaternion(const ndVector& quat);
36  ndQuaternion(const ndQuaternion& quat);
37  D_CORE_API ndQuaternion (const ndMatrix& matrix);
38  ndQuaternion (ndFloat32 q0, ndFloat32 q1, ndFloat32 q2, ndFloat32 q3);
39  D_CORE_API ndQuaternion (const ndVector &unit_Axis, ndFloat32 angle);
40 
41  ndQuaternion Normalize() const;
42  ndQuaternion Scale(ndFloat32 scale) const;
43  ndQuaternion Inverse () const;
44  ndQuaternion operator+ (const ndQuaternion &B) const;
45  ndQuaternion operator- (const ndQuaternion &B) const;
46 
47  D_CORE_API ndQuaternion operator* (const ndQuaternion &B) const;
48  D_CORE_API ndQuaternion Slerp(const ndQuaternion &q1, ndFloat32 t) const;
49  D_CORE_API ndVector CalcAverageOmega(const ndQuaternion &q1, ndFloat32 invdt) const;
50 
51 };
52 
53 inline ndQuaternion::ndQuaternion()
54  :ndVector(ndVector::m_wOne)
55 {
56 }
57 
58 inline ndQuaternion::ndQuaternion(const ndVector& quat)
59  :ndVector(quat)
60 {
61 }
62 
63 inline ndQuaternion::ndQuaternion(const ndQuaternion& quat)
64  :ndVector(quat)
65 {
66 }
67 
68 inline ndQuaternion::ndQuaternion(ndFloat32 q0, ndFloat32 q1, ndFloat32 q2, ndFloat32 q3)
69  :ndVector(q0, q1, q2, q3)
70 {
71  *this = Normalize();
72 }
73 
74 inline ndQuaternion ndQuaternion::Inverse () const
75 {
76  return ndQuaternion (-m_x, -m_y, -m_z, m_w);
77 }
78 
79 inline ndQuaternion ndQuaternion::operator+ (const ndQuaternion &q) const
80 {
81  //return ndQuaternion (m_x + q.m_x, m_y + q.m_y, m_z + q.m_z, m_w + q.m_w);
82  return ndVector::operator+(q);
83 }
84 
85 inline ndQuaternion ndQuaternion::operator- (const ndQuaternion &q) const
86 {
87  //return ndQuaternion (m_x - q.m_x, m_y - q.m_y, m_z - q.m_z, m_w - q.m_w);
88  return ndVector::operator-(q);
89 }
90 
91 inline ndQuaternion ndQuaternion::Normalize() const
92 {
93  return ndVector::Normalize();
94 }
95 
96 inline ndQuaternion ndQuaternion::Scale(ndFloat32 scale) const
97 {
98  return ndVector::Scale(scale);
99 }
100 
101 #endif
102 
ndMatrix
Definition: ndMatrix.h:42
ndQuaternion
Definition: ndQuaternion.h:32
ndVector
Definition: ndVectorArmNeon.h:41