miniassimp

view include/miniassimp/quaternion.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2018, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
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.
40 ----------------------------------------------------------------------
41 */
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
50 #ifdef __cplusplus
52 #include "defs.h"
54 template <typename TReal> class aiVector3t;
55 template <typename TReal> class aiMatrix3x3t;
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) {}
67 /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */
68 explicit aiQuaterniont( const aiMatrix3x3t<TReal>& pRotMatrix);
70 /** Construct from euler angles */
71 aiQuaterniont( TReal rotx, TReal roty, TReal rotz);
73 /** Construct from an axis-angle pair */
74 aiQuaterniont( aiVector3t<TReal> axis, TReal angle);
76 /** Construct from a normalized quaternion stored in a vec3 */
77 explicit aiQuaterniont( aiVector3t<TReal> normalized);
79 /** Returns a matrix representation of the quaternion */
80 aiMatrix3x3t<TReal> GetMatrix() const;
82 public:
84 bool operator== (const aiQuaterniont& o) const;
85 bool operator!= (const aiQuaterniont& o) const;
87 bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const;
89 public:
91 /** Normalize the quaternion */
92 aiQuaterniont& Normalize();
94 /** Compute quaternion conjugate */
95 aiQuaterniont& Conjugate ();
97 /** Rotate a point by this quaternion */
98 aiVector3t<TReal> Rotate (const aiVector3t<TReal>& in);
100 /** Multiply two quaternions */
101 aiQuaterniont operator* (const aiQuaterniont& two) const;
103 public:
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);
114 public:
116 //! w,x,y,z components of the quaternion
117 TReal w, x, y, z;
118 } ;
120 typedef aiQuaterniont<ai_real> aiQuaternion;
122 #else
124 struct aiQuaternion {
125 ai_real w, x, y, z;
126 };
128 #endif
130 #endif // AI_QUATERNION_H_INC