miniassimp

view include/miniassimp/matrix3x3.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 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
12 Redistribution and use of this software in source and binary forms,
13 with or without modification, are permitted provided that the following
14 conditions are met:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
20 * Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the
22 following disclaimer in the documentation and/or other
23 materials provided with the distribution.
25 * Neither the name of the assimp team, nor the names of its
26 contributors may be used to endorse or promote products
27 derived from this software without specific prior
28 written permission of the assimp team.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ---------------------------------------------------------------------------
42 */
44 /** @file matrix3x3.h
45 * @brief Definition of a 3x3 matrix, including operators when compiling in C++
46 */
47 #pragma once
48 #ifndef AI_MATRIX3X3_H_INC
49 #define AI_MATRIX3X3_H_INC
51 #include "defs.h"
53 #ifdef __cplusplus
55 template <typename T> class aiMatrix4x4t;
56 template <typename T> class aiVector2t;
58 // ---------------------------------------------------------------------------
59 /** @brief Represents a row-major 3x3 matrix
60 *
61 * There's much confusion about matrix layouts (column vs. row order).
62 * This is *always* a row-major matrix. Not even with the
63 * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect
64 * matrix order - it just affects the handedness of the coordinate system
65 * defined thereby.
66 */
67 template <typename TReal>
68 class aiMatrix3x3t
69 {
70 public:
72 aiMatrix3x3t() AI_NO_EXCEPT :
73 a1(static_cast<TReal>(1.0f)), a2(), a3(),
74 b1(), b2(static_cast<TReal>(1.0f)), b3(),
75 c1(), c2(), c3(static_cast<TReal>(1.0f)) {}
77 aiMatrix3x3t ( TReal _a1, TReal _a2, TReal _a3,
78 TReal _b1, TReal _b2, TReal _b3,
79 TReal _c1, TReal _c2, TReal _c3) :
80 a1(_a1), a2(_a2), a3(_a3),
81 b1(_b1), b2(_b2), b3(_b3),
82 c1(_c1), c2(_c2), c3(_c3)
83 {}
85 public:
87 // matrix multiplication.
88 aiMatrix3x3t& operator *= (const aiMatrix3x3t& m);
89 aiMatrix3x3t operator * (const aiMatrix3x3t& m) const;
91 // array access operators
92 TReal* operator[] (unsigned int p_iIndex);
93 const TReal* operator[] (unsigned int p_iIndex) const;
95 // comparison operators
96 bool operator== (const aiMatrix4x4t<TReal>& m) const;
97 bool operator!= (const aiMatrix4x4t<TReal>& m) const;
99 bool Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon = 1e-6) const;
101 template <typename TOther>
102 operator aiMatrix3x3t<TOther> () const;
104 public:
106 // -------------------------------------------------------------------
107 /** @brief Construction from a 4x4 matrix. The remaining parts
108 * of the matrix are ignored.
109 */
110 explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix);
112 // -------------------------------------------------------------------
113 /** @brief Transpose the matrix
114 */
115 aiMatrix3x3t& Transpose();
117 // -------------------------------------------------------------------
118 /** @brief Invert the matrix.
119 * If the matrix is not invertible all elements are set to qnan.
120 * Beware, use (f != f) to check whether a TReal f is qnan.
121 */
122 aiMatrix3x3t& Inverse();
123 TReal Determinant() const;
125 public:
126 // -------------------------------------------------------------------
127 /** @brief Returns a rotation matrix for a rotation around z
128 * @param a Rotation angle, in radians
129 * @param out Receives the output matrix
130 * @return Reference to the output matrix
131 */
132 static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out);
134 // -------------------------------------------------------------------
135 /** @brief Returns a rotation matrix for a rotation around
136 * an arbitrary axis.
137 *
138 * @param a Rotation angle, in radians
139 * @param axis Axis to rotate around
140 * @param out To be filled
141 */
142 static aiMatrix3x3t& Rotation( TReal a,
143 const aiVector3t<TReal>& axis, aiMatrix3x3t& out);
145 // -------------------------------------------------------------------
146 /** @brief Returns a translation matrix
147 * @param v Translation vector
148 * @param out Receives the output matrix
149 * @return Reference to the output matrix
150 */
151 static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out);
153 // -------------------------------------------------------------------
154 /** @brief A function for creating a rotation matrix that rotates a
155 * vector called "from" into another vector called "to".
156 * Input : from[3], to[3] which both must be *normalized* non-zero vectors
157 * Output: mtx[3][3] -- a 3x3 matrix in column-major form
158 * Authors: Tomas Möller, John Hughes
159 * "Efficiently Building a Matrix to Rotate One Vector to Another"
160 * Journal of Graphics Tools, 4(4):1-4, 1999
161 */
162 static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from,
163 const aiVector3t<TReal>& to, aiMatrix3x3t& out);
165 public:
166 TReal a1, a2, a3;
167 TReal b1, b2, b3;
168 TReal c1, c2, c3;
169 };
171 typedef aiMatrix3x3t<ai_real> aiMatrix3x3;
173 #else
175 struct aiMatrix3x3 {
176 ai_real a1, a2, a3;
177 ai_real b1, b2, b3;
178 ai_real c1, c2, c3;
179 };
181 #endif // __cplusplus
183 #endif // AI_MATRIX3X3_H_INC