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