vrshoot

view libs/assimp/assimp/matrix4x4.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, 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 following
12 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.
39 ---------------------------------------------------------------------------
40 */
41 /** @file matrix4x4.h
42 * @brief 4x4 matrix structure, including operators when compiling in C++
43 */
44 #ifndef AI_MATRIX4X4_H_INC
45 #define AI_MATRIX4X4_H_INC
47 #include "./Compiler/pushpack1.h"
49 #ifdef __cplusplus
51 template<typename TReal> class aiMatrix3x3t;
52 template<typename TReal> class aiQuaterniont;
54 // ---------------------------------------------------------------------------
55 /** @brief Represents a row-major 4x4 matrix, use this for homogeneous
56 * coordinates.
57 *
58 * There's much confusion about matrix layouts (column vs. row order).
59 * This is *always* a row-major matrix. Not even with the
60 * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect
61 * matrix order - it just affects the handedness of the coordinate system
62 * defined thereby.
63 */
64 template<typename TReal>
65 class aiMatrix4x4t
66 {
67 public:
69 /** set to identity */
70 aiMatrix4x4t ();
72 /** construction from single values */
73 aiMatrix4x4t ( TReal _a1, TReal _a2, TReal _a3, TReal _a4,
74 TReal _b1, TReal _b2, TReal _b3, TReal _b4,
75 TReal _c1, TReal _c2, TReal _c3, TReal _c4,
76 TReal _d1, TReal _d2, TReal _d3, TReal _d4);
79 /** construction from 3x3 matrix, remaining elements are set to identity */
80 explicit aiMatrix4x4t( const aiMatrix3x3t<TReal>& m);
82 public:
84 // array access operators
85 TReal* operator[] (unsigned int p_iIndex);
86 const TReal* operator[] (unsigned int p_iIndex) const;
88 // comparison operators
89 bool operator== (const aiMatrix4x4t m) const;
90 bool operator!= (const aiMatrix4x4t m) const;
92 // matrix multiplication.
93 aiMatrix4x4t& operator *= (const aiMatrix4x4t& m);
94 aiMatrix4x4t operator * (const aiMatrix4x4t& m) const;
96 template <typename TOther>
97 operator aiMatrix4x4t<TOther> () const;
99 public:
101 // -------------------------------------------------------------------
102 /** @brief Transpose the matrix */
103 aiMatrix4x4t& Transpose();
105 // -------------------------------------------------------------------
106 /** @brief Invert the matrix.
107 * If the matrix is not invertible all elements are set to qnan.
108 * Beware, use (f != f) to check whether a TReal f is qnan.
109 */
110 aiMatrix4x4t& Inverse();
111 TReal Determinant() const;
114 // -------------------------------------------------------------------
115 /** @brief Returns true of the matrix is the identity matrix.
116 * The check is performed against a not so small epsilon.
117 */
118 inline bool IsIdentity() const;
120 // -------------------------------------------------------------------
121 /** @brief Decompose a trafo matrix into its original components
122 * @param scaling Receives the output scaling for the x,y,z axes
123 * @param rotation Receives the output rotation as a hamilton
124 * quaternion
125 * @param position Receives the output position for the x,y,z axes
126 */
127 void Decompose (aiVector3t<TReal>& scaling, aiQuaterniont<TReal>& rotation,
128 aiVector3t<TReal>& position) const;
130 // -------------------------------------------------------------------
131 /** @brief Decompose a trafo matrix with no scaling into its
132 * original components
133 * @param rotation Receives the output rotation as a hamilton
134 * quaternion
135 * @param position Receives the output position for the x,y,z axes
136 */
137 void DecomposeNoScaling (aiQuaterniont<TReal>& rotation,
138 aiVector3t<TReal>& position) const;
141 // -------------------------------------------------------------------
142 /** @brief Creates a trafo matrix from a set of euler angles
143 * @param x Rotation angle for the x-axis, in radians
144 * @param y Rotation angle for the y-axis, in radians
145 * @param z Rotation angle for the z-axis, in radians
146 */
147 aiMatrix4x4t& FromEulerAnglesXYZ(TReal x, TReal y, TReal z);
148 aiMatrix4x4t& FromEulerAnglesXYZ(const aiVector3t<TReal>& blubb);
150 public:
151 // -------------------------------------------------------------------
152 /** @brief Returns a rotation matrix for a rotation around the x axis
153 * @param a Rotation angle, in radians
154 * @param out Receives the output matrix
155 * @return Reference to the output matrix
156 */
157 static aiMatrix4x4t& RotationX(TReal a, aiMatrix4x4t& out);
159 // -------------------------------------------------------------------
160 /** @brief Returns a rotation matrix for a rotation around the y axis
161 * @param a Rotation angle, in radians
162 * @param out Receives the output matrix
163 * @return Reference to the output matrix
164 */
165 static aiMatrix4x4t& RotationY(TReal a, aiMatrix4x4t& out);
167 // -------------------------------------------------------------------
168 /** @brief Returns a rotation matrix for a rotation around the z axis
169 * @param a Rotation angle, in radians
170 * @param out Receives the output matrix
171 * @return Reference to the output matrix
172 */
173 static aiMatrix4x4t& RotationZ(TReal a, aiMatrix4x4t& out);
175 // -------------------------------------------------------------------
176 /** Returns a rotation matrix for a rotation around an arbitrary axis.
177 * @param a Rotation angle, in radians
178 * @param axis Rotation axis, should be a normalized vector.
179 * @param out Receives the output matrix
180 * @return Reference to the output matrix
181 */
182 static aiMatrix4x4t& Rotation(TReal a, const aiVector3t<TReal>& axis,
183 aiMatrix4x4t& out);
185 // -------------------------------------------------------------------
186 /** @brief Returns a translation matrix
187 * @param v Translation vector
188 * @param out Receives the output matrix
189 * @return Reference to the output matrix
190 */
191 static aiMatrix4x4t& Translation( const aiVector3t<TReal>& v, aiMatrix4x4t& out);
193 // -------------------------------------------------------------------
194 /** @brief Returns a scaling matrix
195 * @param v Scaling vector
196 * @param out Receives the output matrix
197 * @return Reference to the output matrix
198 */
199 static aiMatrix4x4t& Scaling( const aiVector3t<TReal>& v, aiMatrix4x4t& out);
201 // -------------------------------------------------------------------
202 /** @brief A function for creating a rotation matrix that rotates a
203 * vector called "from" into another vector called "to".
204 * Input : from[3], to[3] which both must be *normalized* non-zero vectors
205 * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
206 * Authors: Tomas Möller, John Hughes
207 * "Efficiently Building a Matrix to Rotate One Vector to Another"
208 * Journal of Graphics Tools, 4(4):1-4, 1999
209 */
210 static aiMatrix4x4t& FromToMatrix(const aiVector3t<TReal>& from,
211 const aiVector3t<TReal>& to, aiMatrix4x4t& out);
213 public:
215 TReal a1, a2, a3, a4;
216 TReal b1, b2, b3, b4;
217 TReal c1, c2, c3, c4;
218 TReal d1, d2, d3, d4;
220 } PACK_STRUCT;
222 typedef aiMatrix4x4t<float> aiMatrix4x4;
224 #else
226 struct aiMatrix4x4 {
227 float a1, a2, a3, a4;
228 float b1, b2, b3, b4;
229 float c1, c2, c3, c4;
230 float d1, d2, d3, d4;
231 };
234 #endif // __cplusplus
236 #include "./Compiler/poppack1.h"
238 #endif // AI_MATRIX4X4_H_INC