1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2019, assimp team |
6 | |
7 | |
8 | All rights reserved. |
9 | |
10 | Redistribution and use of this software in source and binary forms, |
11 | with or without modification, are permitted provided that the |
12 | following conditions are met: |
13 | |
14 | * Redistributions of source code must retain the above |
15 | copyright notice, this list of conditions and the |
16 | following disclaimer. |
17 | |
18 | * Redistributions in binary form must reproduce the above |
19 | copyright notice, this list of conditions and the |
20 | following disclaimer in the documentation and/or other |
21 | materials provided with the distribution. |
22 | |
23 | * Neither the name of the assimp team, nor the names of its |
24 | contributors may be used to endorse or promote products |
25 | derived from this software without specific prior |
26 | written permission of the assimp team. |
27 | |
28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | |
40 | ---------------------------------------------------------------------- |
41 | */ |
42 | |
43 | /** @file quaternion.h |
44 | * @brief Quaternion structure, including operators when compiling in C++ |
45 | */ |
46 | #pragma once |
47 | #ifndef AI_QUATERNION_H_INC |
48 | #define AI_QUATERNION_H_INC |
49 | |
50 | #ifdef __cplusplus |
51 | |
52 | #include "defs.h" |
53 | |
54 | template <typename TReal> class aiVector3t; |
55 | template <typename TReal> class aiMatrix3x3t; |
56 | |
57 | // --------------------------------------------------------------------------- |
58 | /** Represents a quaternion in a 4D vector. */ |
59 | template <typename TReal> |
60 | class aiQuaterniont |
61 | { |
62 | public: |
63 | aiQuaterniont() AI_NO_EXCEPT : w(1.0), x(), y(), z() {} |
64 | aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz) |
65 | : w(pw), x(px), y(py), z(pz) {} |
66 | |
67 | /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */ |
68 | explicit aiQuaterniont( const aiMatrix3x3t<TReal>& pRotMatrix); |
69 | |
70 | /** Construct from euler angles */ |
71 | aiQuaterniont( TReal rotx, TReal roty, TReal rotz); |
72 | |
73 | /** Construct from an axis-angle pair */ |
74 | aiQuaterniont( aiVector3t<TReal> axis, TReal angle); |
75 | |
76 | /** Construct from a normalized quaternion stored in a vec3 */ |
77 | explicit aiQuaterniont( aiVector3t<TReal> normalized); |
78 | |
79 | /** Returns a matrix representation of the quaternion */ |
80 | aiMatrix3x3t<TReal> GetMatrix() const; |
81 | |
82 | public: |
83 | |
84 | bool operator== (const aiQuaterniont& o) const; |
85 | bool operator!= (const aiQuaterniont& o) const; |
86 | |
87 | bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const; |
88 | |
89 | public: |
90 | |
91 | /** Normalize the quaternion */ |
92 | aiQuaterniont& Normalize(); |
93 | |
94 | /** Compute quaternion conjugate */ |
95 | aiQuaterniont& Conjugate (); |
96 | |
97 | /** Rotate a point by this quaternion */ |
98 | aiVector3t<TReal> Rotate (const aiVector3t<TReal>& in); |
99 | |
100 | /** Multiply two quaternions */ |
101 | aiQuaterniont operator* (const aiQuaterniont& two) const; |
102 | |
103 | public: |
104 | |
105 | /** Performs a spherical interpolation between two quaternions and writes the result into the third. |
106 | * @param pOut Target object to received the interpolated rotation. |
107 | * @param pStart Start rotation of the interpolation at factor == 0. |
108 | * @param pEnd End rotation, factor == 1. |
109 | * @param pFactor Interpolation factor between 0 and 1. Values outside of this range yield undefined results. |
110 | */ |
111 | static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart, |
112 | const aiQuaterniont& pEnd, TReal pFactor); |
113 | |
114 | public: |
115 | |
116 | //! w,x,y,z components of the quaternion |
117 | TReal w, x, y, z; |
118 | } ; |
119 | |
120 | typedef aiQuaterniont<ai_real> aiQuaternion; |
121 | |
122 | #else |
123 | |
124 | struct aiQuaternion { |
125 | ai_real w, x, y, z; |
126 | }; |
127 | |
128 | #endif |
129 | |
130 | #endif // AI_QUATERNION_H_INC |
131 | |