vrshoot

view libs/assimp/assimp/matrix3x3.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 */
42 /** @file matrix3x3.h
43 * @brief Definition of a 3x3 matrix, including operators when compiling in C++
44 */
45 #ifndef AI_MATRIX3x3_H_INC
46 #define AI_MATRIX3x3_H_INC
48 #include "./Compiler/pushpack1.h"
50 #ifdef __cplusplus
52 template <typename T> class aiMatrix4x4t;
53 template <typename T> class aiVector2t;
55 // ---------------------------------------------------------------------------
56 /** @brief Represents a row-major 3x3 matrix
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 aiMatrix3x3t
66 {
67 public:
69 aiMatrix3x3t () :
70 a1(static_cast<TReal>(1.0f)), a2(), a3(),
71 b1(), b2(static_cast<TReal>(1.0f)), b3(),
72 c1(), c2(), c3(static_cast<TReal>(1.0f)) {}
74 aiMatrix3x3t ( TReal _a1, TReal _a2, TReal _a3,
75 TReal _b1, TReal _b2, TReal _b3,
76 TReal _c1, TReal _c2, TReal _c3) :
77 a1(_a1), a2(_a2), a3(_a3),
78 b1(_b1), b2(_b2), b3(_b3),
79 c1(_c1), c2(_c2), c3(_c3)
80 {}
82 public:
84 // matrix multiplication.
85 aiMatrix3x3t& operator *= (const aiMatrix3x3t& m);
86 aiMatrix3x3t operator * (const aiMatrix3x3t& m) const;
88 // array access operators
89 TReal* operator[] (unsigned int p_iIndex);
90 const TReal* operator[] (unsigned int p_iIndex) const;
92 // comparison operators
93 bool operator== (const aiMatrix4x4t<TReal> m) const;
94 bool operator!= (const aiMatrix4x4t<TReal> m) const;
96 template <typename TOther>
97 operator aiMatrix3x3t<TOther> () const;
99 public:
101 // -------------------------------------------------------------------
102 /** @brief Construction from a 4x4 matrix. The remaining parts
103 * of the matrix are ignored.
104 */
105 explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix);
107 // -------------------------------------------------------------------
108 /** @brief Transpose the matrix
109 */
110 aiMatrix3x3t& Transpose();
112 // -------------------------------------------------------------------
113 /** @brief Invert the matrix.
114 * If the matrix is not invertible all elements are set to qnan.
115 * Beware, use (f != f) to check whether a TReal f is qnan.
116 */
117 aiMatrix3x3t& Inverse();
118 TReal Determinant() const;
120 public:
121 // -------------------------------------------------------------------
122 /** @brief Returns a rotation matrix for a rotation around z
123 * @param a Rotation angle, in radians
124 * @param out Receives the output matrix
125 * @return Reference to the output matrix
126 */
127 static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out);
129 // -------------------------------------------------------------------
130 /** @brief Returns a rotation matrix for a rotation around
131 * an arbitrary axis.
132 *
133 * @param a Rotation angle, in radians
134 * @param axis Axis to rotate around
135 * @param out To be filled
136 */
137 static aiMatrix3x3t& Rotation( TReal a,
138 const aiVector3t<TReal>& axis, aiMatrix3x3t& out);
140 // -------------------------------------------------------------------
141 /** @brief Returns a translation matrix
142 * @param v Translation vector
143 * @param out Receives the output matrix
144 * @return Reference to the output matrix
145 */
146 static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out);
148 // -------------------------------------------------------------------
149 /** @brief A function for creating a rotation matrix that rotates a
150 * vector called "from" into another vector called "to".
151 * Input : from[3], to[3] which both must be *normalized* non-zero vectors
152 * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
153 * Authors: Tomas Möller, John Hughes
154 * "Efficiently Building a Matrix to Rotate One Vector to Another"
155 * Journal of Graphics Tools, 4(4):1-4, 1999
156 */
157 static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from,
158 const aiVector3t<TReal>& to, aiMatrix3x3t& out);
160 public:
163 TReal a1, a2, a3;
164 TReal b1, b2, b3;
165 TReal c1, c2, c3;
166 } PACK_STRUCT;
168 typedef aiMatrix3x3t<float> aiMatrix3x3;
170 #else
172 struct aiMatrix3x3 {
174 float a1, a2, a3;
175 float b1, b2, b3;
176 float c1, c2, c3;
177 } PACK_STRUCT;
179 #endif
181 #include "./Compiler/poppack1.h"
183 #endif // AI_MATRIX3x3_H_INC