![]() |
|
|||
File indexing completed on 2025-02-21 09:30:09
0001 /* 0002 --------------------------------------------------------------------------- 0003 Open Asset Import Library (assimp) 0004 --------------------------------------------------------------------------- 0005 0006 Copyright (c) 2006-2024, assimp team 0007 0008 0009 0010 All rights reserved. 0011 0012 Redistribution and use of this software in source and binary forms, 0013 with or without modification, are permitted provided that the following 0014 conditions are met: 0015 0016 * Redistributions of source code must retain the above 0017 copyright notice, this list of conditions and the 0018 following disclaimer. 0019 0020 * Redistributions in binary form must reproduce the above 0021 copyright notice, this list of conditions and the 0022 following disclaimer in the documentation and/or other 0023 materials provided with the distribution. 0024 0025 * Neither the name of the assimp team, nor the names of its 0026 contributors may be used to endorse or promote products 0027 derived from this software without specific prior 0028 written permission of the assimp team. 0029 0030 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0031 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0032 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0033 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0034 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0035 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0036 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0037 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0038 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0039 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0040 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0041 --------------------------------------------------------------------------- 0042 */ 0043 /** @file matrix4x4.h 0044 * @brief 4x4 matrix structure, including operators when compiling in C++ 0045 */ 0046 #pragma once 0047 #ifndef AI_MATRIX4X4_H_INC 0048 #define AI_MATRIX4X4_H_INC 0049 0050 #ifdef __GNUC__ 0051 # pragma GCC system_header 0052 #endif 0053 0054 #include <assimp/vector3.h> 0055 #include <assimp/defs.h> 0056 #include <assimp/config.h> 0057 0058 #ifdef __cplusplus 0059 0060 template<typename TReal> class aiMatrix3x3t; 0061 template<typename TReal> class aiQuaterniont; 0062 0063 // --------------------------------------------------------------------------- 0064 /** @brief Represents a row-major 4x4 matrix, use this for homogeneous 0065 * coordinates. 0066 * 0067 * There's much confusion about matrix layouts (column vs. row order). 0068 * This is *always* a row-major matrix. Not even with the 0069 * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect 0070 * matrix order - it just affects the handedness of the coordinate system 0071 * defined thereby. 0072 */ 0073 template<typename TReal> 0074 class aiMatrix4x4t { 0075 public: 0076 0077 /** set to identity */ 0078 aiMatrix4x4t() AI_NO_EXCEPT; 0079 0080 /** construction from single values */ 0081 aiMatrix4x4t ( TReal _a1, TReal _a2, TReal _a3, TReal _a4, 0082 TReal _b1, TReal _b2, TReal _b3, TReal _b4, 0083 TReal _c1, TReal _c2, TReal _c3, TReal _c4, 0084 TReal _d1, TReal _d2, TReal _d3, TReal _d4); 0085 0086 0087 /** construction from 3x3 matrix, remaining elements are set to identity */ 0088 explicit aiMatrix4x4t( const aiMatrix3x3t<TReal>& m); 0089 0090 /** construction from position, rotation and scaling components 0091 * @param scaling The scaling for the x,y,z axes 0092 * @param rotation The rotation as a hamilton quaternion 0093 * @param position The position for the x,y,z axes 0094 */ 0095 aiMatrix4x4t(const aiVector3t<TReal>& scaling, const aiQuaterniont<TReal>& rotation, 0096 const aiVector3t<TReal>& position); 0097 0098 // array access operators 0099 /** @fn TReal* operator[] (unsigned int p_iIndex) 0100 * @param [in] p_iIndex - index of the row. 0101 * @return pointer to pointed row. 0102 */ 0103 TReal* operator[] (unsigned int p_iIndex); 0104 0105 /** @fn const TReal* operator[] (unsigned int p_iIndex) const 0106 * @overload TReal* operator[] (unsigned int p_iIndex) 0107 */ 0108 const TReal* operator[] (unsigned int p_iIndex) const; 0109 0110 // comparison operators 0111 bool operator== (const aiMatrix4x4t& m) const; 0112 bool operator!= (const aiMatrix4x4t& m) const; 0113 0114 bool Equal(const aiMatrix4x4t &m, TReal epsilon = ai_epsilon) const; 0115 0116 // matrix multiplication. 0117 aiMatrix4x4t& operator *= (const aiMatrix4x4t& m); 0118 aiMatrix4x4t operator * (const aiMatrix4x4t& m) const; 0119 aiMatrix4x4t operator * (const TReal& aFloat) const; 0120 aiMatrix4x4t operator + (const aiMatrix4x4t& aMatrix) const; 0121 0122 template <typename TOther> 0123 operator aiMatrix4x4t<TOther> () const; 0124 0125 // ------------------------------------------------------------------- 0126 /** @brief Transpose the matrix */ 0127 aiMatrix4x4t& Transpose(); 0128 0129 // ------------------------------------------------------------------- 0130 /** @brief Invert the matrix. 0131 * If the matrix is not invertible all elements are set to qnan. 0132 * Beware, use (f != f) to check whether a TReal f is qnan. 0133 */ 0134 aiMatrix4x4t& Inverse(); 0135 TReal Determinant() const; 0136 0137 0138 // ------------------------------------------------------------------- 0139 /** @brief Returns true of the matrix is the identity matrix. 0140 * @param epsilon Value of epsilon. Default value is 10e-3 for backward 0141 * compatibility with legacy code. 0142 * @return Returns true of the matrix is the identity matrix. 0143 * The check is performed against a not so small epsilon. 0144 */ 0145 inline bool IsIdentity(const TReal 0146 epsilon = AI_CONFIG_CHECK_IDENTITY_MATRIX_EPSILON_DEFAULT) const; 0147 0148 // ------------------------------------------------------------------- 0149 /** @brief Decompose a trafo matrix into its original components 0150 * @param scaling Receives the output scaling for the x,y,z axes 0151 * @param rotation Receives the output rotation as a hamilton 0152 * quaternion 0153 * @param position Receives the output position for the x,y,z axes 0154 */ 0155 void Decompose (aiVector3t<TReal>& scaling, aiQuaterniont<TReal>& rotation, 0156 aiVector3t<TReal>& position) const; 0157 0158 // ------------------------------------------------------------------- 0159 /** @fn void Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotation, aiVector3t<TReal>& pPosition) const 0160 * @brief Decompose a trafo matrix into its original components. 0161 * Thx to good FAQ at http://www.gamedev.ru/code/articles/faq_matrix_quat 0162 * @param [out] pScaling - Receives the output scaling for the x,y,z axes. 0163 * @param [out] pRotation - Receives the output rotation as a Euler angles. 0164 * @param [out] pPosition - Receives the output position for the x,y,z axes. 0165 */ 0166 void Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotation, aiVector3t<TReal>& pPosition) const; 0167 0168 // ------------------------------------------------------------------- 0169 /** @fn void Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotationAxis, TReal& pRotationAngle, aiVector3t<TReal>& pPosition) const 0170 * @brief Decompose a trafo matrix into its original components 0171 * Thx to good FAQ at http://www.gamedev.ru/code/articles/faq_matrix_quat 0172 * @param [out] pScaling - Receives the output scaling for the x,y,z axes. 0173 * @param [out] pRotationAxis - Receives the output rotation axis. 0174 * @param [out] pRotationAngle - Receives the output rotation angle for @ref pRotationAxis. 0175 * @param [out] pPosition - Receives the output position for the x,y,z axes. 0176 */ 0177 void Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotationAxis, TReal& pRotationAngle, aiVector3t<TReal>& pPosition) const; 0178 0179 // ------------------------------------------------------------------- 0180 /** @brief Decompose a trafo matrix with no scaling into its 0181 * original components 0182 * @param rotation Receives the output rotation as a hamilton 0183 * quaternion 0184 * @param position Receives the output position for the x,y,z axes 0185 */ 0186 void DecomposeNoScaling (aiQuaterniont<TReal>& rotation, 0187 aiVector3t<TReal>& position) const; 0188 0189 // ------------------------------------------------------------------- 0190 /** @brief Creates a trafo matrix from a set of euler angles 0191 * @param x Rotation angle for the x-axis, in radians 0192 * @param y Rotation angle for the y-axis, in radians 0193 * @param z Rotation angle for the z-axis, in radians 0194 */ 0195 aiMatrix4x4t& FromEulerAnglesXYZ(TReal x, TReal y, TReal z); 0196 aiMatrix4x4t& FromEulerAnglesXYZ(const aiVector3t<TReal>& blubb); 0197 0198 // ------------------------------------------------------------------- 0199 /** @brief Returns a rotation matrix for a rotation around the x axis 0200 * @param a Rotation angle, in radians 0201 * @param out Receives the output matrix 0202 * @return Reference to the output matrix 0203 */ 0204 static aiMatrix4x4t& RotationX(TReal a, aiMatrix4x4t& out); 0205 0206 // ------------------------------------------------------------------- 0207 /** @brief Returns a rotation matrix for a rotation around the y axis 0208 * @param a Rotation angle, in radians 0209 * @param out Receives the output matrix 0210 * @return Reference to the output matrix 0211 */ 0212 static aiMatrix4x4t& RotationY(TReal a, aiMatrix4x4t& out); 0213 0214 // ------------------------------------------------------------------- 0215 /** @brief Returns a rotation matrix for a rotation around the z axis 0216 * @param a Rotation angle, in radians 0217 * @param out Receives the output matrix 0218 * @return Reference to the output matrix 0219 */ 0220 static aiMatrix4x4t& RotationZ(TReal a, aiMatrix4x4t& out); 0221 0222 // ------------------------------------------------------------------- 0223 /** Returns a rotation matrix for a rotation around an arbitrary axis. 0224 * @param a Rotation angle, in radians 0225 * @param axis Rotation axis, should be a normalized vector. 0226 * @param out Receives the output matrix 0227 * @return Reference to the output matrix 0228 */ 0229 static aiMatrix4x4t& Rotation(TReal a, const aiVector3t<TReal>& axis, 0230 aiMatrix4x4t& out); 0231 0232 // ------------------------------------------------------------------- 0233 /** @brief Returns a translation matrix 0234 * @param v Translation vector 0235 * @param out Receives the output matrix 0236 * @return Reference to the output matrix 0237 */ 0238 static aiMatrix4x4t& Translation( const aiVector3t<TReal>& v, 0239 aiMatrix4x4t& out); 0240 0241 // ------------------------------------------------------------------- 0242 /** @brief Returns a scaling matrix 0243 * @param v Scaling vector 0244 * @param out Receives the output matrix 0245 * @return Reference to the output matrix 0246 */ 0247 static aiMatrix4x4t& Scaling( const aiVector3t<TReal>& v, aiMatrix4x4t& out); 0248 0249 // ------------------------------------------------------------------- 0250 /** @brief A function for creating a rotation matrix that rotates a 0251 * vector called "from" into another vector called "to". 0252 * Input : from[3], to[3] which both must be *normalized* non-zero vectors 0253 * Output: mtx[3][3] -- a 3x3 matrix in column-major form 0254 * Authors: Tomas Mueller, John Hughes 0255 * "Efficiently Building a Matrix to Rotate One Vector to Another" 0256 * Journal of Graphics Tools, 4(4):1-4, 1999 0257 */ 0258 static aiMatrix4x4t& FromToMatrix(const aiVector3t<TReal>& from, 0259 const aiVector3t<TReal>& to, aiMatrix4x4t& out); 0260 0261 TReal a1, a2, a3, a4; 0262 TReal b1, b2, b3, b4; 0263 TReal c1, c2, c3, c4; 0264 TReal d1, d2, d3, d4; 0265 }; 0266 0267 typedef aiMatrix4x4t<ai_real> aiMatrix4x4; 0268 0269 #else 0270 0271 struct aiMatrix4x4 { 0272 ai_real a1, a2, a3, a4; 0273 ai_real b1, b2, b3, b4; 0274 ai_real c1, c2, c3, c4; 0275 ai_real d1, d2, d3, d4; 0276 }; 0277 0278 0279 #endif // __cplusplus 0280 0281 #endif // AI_MATRIX4X4_H_INC
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |