vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/matrix4x4.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,238 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 +/** @file matrix4x4.h 1.45 + * @brief 4x4 matrix structure, including operators when compiling in C++ 1.46 + */ 1.47 +#ifndef AI_MATRIX4X4_H_INC 1.48 +#define AI_MATRIX4X4_H_INC 1.49 + 1.50 +#include "./Compiler/pushpack1.h" 1.51 + 1.52 +#ifdef __cplusplus 1.53 + 1.54 +template<typename TReal> class aiMatrix3x3t; 1.55 +template<typename TReal> class aiQuaterniont; 1.56 + 1.57 +// --------------------------------------------------------------------------- 1.58 +/** @brief Represents a row-major 4x4 matrix, use this for homogeneous 1.59 + * coordinates. 1.60 + * 1.61 + * There's much confusion about matrix layouts (column vs. row order). 1.62 + * This is *always* a row-major matrix. Not even with the 1.63 + * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect 1.64 + * matrix order - it just affects the handedness of the coordinate system 1.65 + * defined thereby. 1.66 + */ 1.67 +template<typename TReal> 1.68 +class aiMatrix4x4t 1.69 +{ 1.70 +public: 1.71 + 1.72 + /** set to identity */ 1.73 + aiMatrix4x4t (); 1.74 + 1.75 + /** construction from single values */ 1.76 + aiMatrix4x4t ( TReal _a1, TReal _a2, TReal _a3, TReal _a4, 1.77 + TReal _b1, TReal _b2, TReal _b3, TReal _b4, 1.78 + TReal _c1, TReal _c2, TReal _c3, TReal _c4, 1.79 + TReal _d1, TReal _d2, TReal _d3, TReal _d4); 1.80 + 1.81 + 1.82 + /** construction from 3x3 matrix, remaining elements are set to identity */ 1.83 + explicit aiMatrix4x4t( const aiMatrix3x3t<TReal>& m); 1.84 + 1.85 +public: 1.86 + 1.87 + // array access operators 1.88 + TReal* operator[] (unsigned int p_iIndex); 1.89 + const TReal* operator[] (unsigned int p_iIndex) const; 1.90 + 1.91 + // comparison operators 1.92 + bool operator== (const aiMatrix4x4t m) const; 1.93 + bool operator!= (const aiMatrix4x4t m) const; 1.94 + 1.95 + // matrix multiplication. 1.96 + aiMatrix4x4t& operator *= (const aiMatrix4x4t& m); 1.97 + aiMatrix4x4t operator * (const aiMatrix4x4t& m) const; 1.98 + 1.99 + template <typename TOther> 1.100 + operator aiMatrix4x4t<TOther> () const; 1.101 + 1.102 +public: 1.103 + 1.104 + // ------------------------------------------------------------------- 1.105 + /** @brief Transpose the matrix */ 1.106 + aiMatrix4x4t& Transpose(); 1.107 + 1.108 + // ------------------------------------------------------------------- 1.109 + /** @brief Invert the matrix. 1.110 + * If the matrix is not invertible all elements are set to qnan. 1.111 + * Beware, use (f != f) to check whether a TReal f is qnan. 1.112 + */ 1.113 + aiMatrix4x4t& Inverse(); 1.114 + TReal Determinant() const; 1.115 + 1.116 + 1.117 + // ------------------------------------------------------------------- 1.118 + /** @brief Returns true of the matrix is the identity matrix. 1.119 + * The check is performed against a not so small epsilon. 1.120 + */ 1.121 + inline bool IsIdentity() const; 1.122 + 1.123 + // ------------------------------------------------------------------- 1.124 + /** @brief Decompose a trafo matrix into its original components 1.125 + * @param scaling Receives the output scaling for the x,y,z axes 1.126 + * @param rotation Receives the output rotation as a hamilton 1.127 + * quaternion 1.128 + * @param position Receives the output position for the x,y,z axes 1.129 + */ 1.130 + void Decompose (aiVector3t<TReal>& scaling, aiQuaterniont<TReal>& rotation, 1.131 + aiVector3t<TReal>& position) const; 1.132 + 1.133 + // ------------------------------------------------------------------- 1.134 + /** @brief Decompose a trafo matrix with no scaling into its 1.135 + * original components 1.136 + * @param rotation Receives the output rotation as a hamilton 1.137 + * quaternion 1.138 + * @param position Receives the output position for the x,y,z axes 1.139 + */ 1.140 + void DecomposeNoScaling (aiQuaterniont<TReal>& rotation, 1.141 + aiVector3t<TReal>& position) const; 1.142 + 1.143 + 1.144 + // ------------------------------------------------------------------- 1.145 + /** @brief Creates a trafo matrix from a set of euler angles 1.146 + * @param x Rotation angle for the x-axis, in radians 1.147 + * @param y Rotation angle for the y-axis, in radians 1.148 + * @param z Rotation angle for the z-axis, in radians 1.149 + */ 1.150 + aiMatrix4x4t& FromEulerAnglesXYZ(TReal x, TReal y, TReal z); 1.151 + aiMatrix4x4t& FromEulerAnglesXYZ(const aiVector3t<TReal>& blubb); 1.152 + 1.153 +public: 1.154 + // ------------------------------------------------------------------- 1.155 + /** @brief Returns a rotation matrix for a rotation around the x axis 1.156 + * @param a Rotation angle, in radians 1.157 + * @param out Receives the output matrix 1.158 + * @return Reference to the output matrix 1.159 + */ 1.160 + static aiMatrix4x4t& RotationX(TReal a, aiMatrix4x4t& out); 1.161 + 1.162 + // ------------------------------------------------------------------- 1.163 + /** @brief Returns a rotation matrix for a rotation around the y axis 1.164 + * @param a Rotation angle, in radians 1.165 + * @param out Receives the output matrix 1.166 + * @return Reference to the output matrix 1.167 + */ 1.168 + static aiMatrix4x4t& RotationY(TReal a, aiMatrix4x4t& out); 1.169 + 1.170 + // ------------------------------------------------------------------- 1.171 + /** @brief Returns a rotation matrix for a rotation around the z axis 1.172 + * @param a Rotation angle, in radians 1.173 + * @param out Receives the output matrix 1.174 + * @return Reference to the output matrix 1.175 + */ 1.176 + static aiMatrix4x4t& RotationZ(TReal a, aiMatrix4x4t& out); 1.177 + 1.178 + // ------------------------------------------------------------------- 1.179 + /** Returns a rotation matrix for a rotation around an arbitrary axis. 1.180 + * @param a Rotation angle, in radians 1.181 + * @param axis Rotation axis, should be a normalized vector. 1.182 + * @param out Receives the output matrix 1.183 + * @return Reference to the output matrix 1.184 + */ 1.185 + static aiMatrix4x4t& Rotation(TReal a, const aiVector3t<TReal>& axis, 1.186 + aiMatrix4x4t& out); 1.187 + 1.188 + // ------------------------------------------------------------------- 1.189 + /** @brief Returns a translation matrix 1.190 + * @param v Translation vector 1.191 + * @param out Receives the output matrix 1.192 + * @return Reference to the output matrix 1.193 + */ 1.194 + static aiMatrix4x4t& Translation( const aiVector3t<TReal>& v, aiMatrix4x4t& out); 1.195 + 1.196 + // ------------------------------------------------------------------- 1.197 + /** @brief Returns a scaling matrix 1.198 + * @param v Scaling vector 1.199 + * @param out Receives the output matrix 1.200 + * @return Reference to the output matrix 1.201 + */ 1.202 + static aiMatrix4x4t& Scaling( const aiVector3t<TReal>& v, aiMatrix4x4t& out); 1.203 + 1.204 + // ------------------------------------------------------------------- 1.205 + /** @brief A function for creating a rotation matrix that rotates a 1.206 + * vector called "from" into another vector called "to". 1.207 + * Input : from[3], to[3] which both must be *normalized* non-zero vectors 1.208 + * Output: mtx[3][3] -- a 3x3 matrix in colum-major form 1.209 + * Authors: Tomas Möller, John Hughes 1.210 + * "Efficiently Building a Matrix to Rotate One Vector to Another" 1.211 + * Journal of Graphics Tools, 4(4):1-4, 1999 1.212 + */ 1.213 + static aiMatrix4x4t& FromToMatrix(const aiVector3t<TReal>& from, 1.214 + const aiVector3t<TReal>& to, aiMatrix4x4t& out); 1.215 + 1.216 +public: 1.217 + 1.218 + TReal a1, a2, a3, a4; 1.219 + TReal b1, b2, b3, b4; 1.220 + TReal c1, c2, c3, c4; 1.221 + TReal d1, d2, d3, d4; 1.222 + 1.223 +} PACK_STRUCT; 1.224 + 1.225 +typedef aiMatrix4x4t<float> aiMatrix4x4; 1.226 + 1.227 +#else 1.228 + 1.229 +struct aiMatrix4x4 { 1.230 + float a1, a2, a3, a4; 1.231 + float b1, b2, b3, b4; 1.232 + float c1, c2, c3, c4; 1.233 + float d1, d2, d3, d4; 1.234 +}; 1.235 + 1.236 + 1.237 +#endif // __cplusplus 1.238 + 1.239 +#include "./Compiler/poppack1.h" 1.240 + 1.241 +#endif // AI_MATRIX4X4_H_INC