aiMatrix4x4.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file aiMatrix4x4.h
  35. * @brief 4x4 matrix structure, including operators when compiling in C++
  36. */
  37. #ifndef AI_MATRIX4X4_H_INC
  38. #define AI_MATRIX4X4_H_INC
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. struct aiMatrix3x3;
  43. struct aiQuaternion;
  44. #include "./Compiler/pushpack1.h"
  45. // ---------------------------------------------------------------------------
  46. /** @brief Represents a row-major 4x4 matrix, use this for homogeneous
  47. * coordinates.
  48. *
  49. * There's much confusion about matrix layouts (colum vs. row order).
  50. * This is *always* a row-major matrix. Even with the
  51. * aiProcess_ConvertToLeftHanded flag.
  52. */
  53. struct aiMatrix4x4
  54. {
  55. #ifdef __cplusplus
  56. // default c'tor, init to zero
  57. aiMatrix4x4 () :
  58. a1(1.0f), a2(0.0f), a3(0.0f), a4(0.0f),
  59. b1(0.0f), b2(1.0f), b3(0.0f), b4(0.0f),
  60. c1(0.0f), c2(0.0f), c3(1.0f), c4(0.0f),
  61. d1(0.0f), d2(0.0f), d3(0.0f), d4(1.0f)
  62. {}
  63. // from single values
  64. aiMatrix4x4 ( float _a1, float _a2, float _a3, float _a4,
  65. float _b1, float _b2, float _b3, float _b4,
  66. float _c1, float _c2, float _c3, float _c4,
  67. float _d1, float _d2, float _d3, float _d4) :
  68. a1(_a1), a2(_a2), a3(_a3), a4(_a4),
  69. b1(_b1), b2(_b2), b3(_b3), b4(_b4),
  70. c1(_c1), c2(_c2), c3(_c3), c4(_c4),
  71. d1(_d1), d2(_d2), d3(_d3), d4(_d4)
  72. {}
  73. // -------------------------------------------------------------------
  74. /** @brief Constructor from 3x3 matrix.
  75. * The remaining elements are set to identity.
  76. */
  77. explicit aiMatrix4x4( const aiMatrix3x3& m);
  78. public:
  79. // array access operators
  80. float* operator[] (unsigned int p_iIndex);
  81. const float* operator[] (unsigned int p_iIndex) const;
  82. // comparison operators
  83. bool operator== (const aiMatrix4x4 m) const;
  84. bool operator!= (const aiMatrix4x4 m) const;
  85. // Matrix multiplication. Not commutative.
  86. aiMatrix4x4& operator *= (const aiMatrix4x4& m);
  87. aiMatrix4x4 operator * (const aiMatrix4x4& m) const;
  88. public:
  89. // -------------------------------------------------------------------
  90. /** @brief Transpose the matrix
  91. */
  92. aiMatrix4x4& Transpose();
  93. // -------------------------------------------------------------------
  94. /** @brief Invert the matrix.
  95. * If the matrix is not invertible all elements are set to qnan.
  96. * Beware, use (f != f) to check whether a float f is qnan.
  97. */
  98. aiMatrix4x4& Inverse();
  99. float Determinant() const;
  100. // -------------------------------------------------------------------
  101. /** @brief Returns true of the matrix is the identity matrix.
  102. * The check is performed against a not so small epsilon.
  103. */
  104. inline bool IsIdentity() const;
  105. // -------------------------------------------------------------------
  106. /** @brief Decompose a trafo matrix into its original components
  107. * @param scaling Receives the output scaling for the x,y,z axes
  108. * @param rotation Receives the output rotation as a hamilton
  109. * quaternion
  110. * @param position Receives the output position for the x,y,z axes
  111. */
  112. void Decompose (aiVector3D& scaling, aiQuaternion& rotation,
  113. aiVector3D& position) const;
  114. // -------------------------------------------------------------------
  115. /** @brief Decompose a trafo matrix with no scaling into its
  116. * original components
  117. * @param rotation Receives the output rotation as a hamilton
  118. * quaternion
  119. * @param position Receives the output position for the x,y,z axes
  120. */
  121. void DecomposeNoScaling (aiQuaternion& rotation,
  122. aiVector3D& position) const;
  123. // -------------------------------------------------------------------
  124. /** @brief Creates a trafo matrix from a set of euler angles
  125. * @param x Rotation angle for the x-axis, in radians
  126. * @param y Rotation angle for the y-axis, in radians
  127. * @param z Rotation angle for the z-axis, in radians
  128. */
  129. aiMatrix4x4& FromEulerAnglesXYZ(float x, float y, float z);
  130. aiMatrix4x4& FromEulerAnglesXYZ(const aiVector3D& blubb);
  131. public:
  132. // -------------------------------------------------------------------
  133. /** @brief Returns a rotation matrix for a rotation around the x axis
  134. * @param a Rotation angle, in radians
  135. * @param out Receives the output matrix
  136. * @return Reference to the output matrix
  137. */
  138. static aiMatrix4x4& RotationX(float a, aiMatrix4x4& out);
  139. // -------------------------------------------------------------------
  140. /** @brief Returns a rotation matrix for a rotation around the y axis
  141. * @param a Rotation angle, in radians
  142. * @param out Receives the output matrix
  143. * @return Reference to the output matrix
  144. */
  145. static aiMatrix4x4& RotationY(float a, aiMatrix4x4& out);
  146. // -------------------------------------------------------------------
  147. /** @brief Returns a rotation matrix for a rotation around the z axis
  148. * @param a Rotation angle, in radians
  149. * @param out Receives the output matrix
  150. * @return Reference to the output matrix
  151. */
  152. static aiMatrix4x4& RotationZ(float a, aiMatrix4x4& out);
  153. // -------------------------------------------------------------------
  154. /** Returns a rotation matrix for a rotation around an arbitrary axis.
  155. * @param a Rotation angle, in radians
  156. * @param axis Rotation axis, should be a normalized vector.
  157. * @param out Receives the output matrix
  158. * @return Reference to the output matrix
  159. */
  160. static aiMatrix4x4& Rotation(float a, const aiVector3D& axis,
  161. aiMatrix4x4& out);
  162. // -------------------------------------------------------------------
  163. /** @brief Returns a translation matrix
  164. * @param v Translation vector
  165. * @param out Receives the output matrix
  166. * @return Reference to the output matrix
  167. */
  168. static aiMatrix4x4& Translation( const aiVector3D& v, aiMatrix4x4& out);
  169. // -------------------------------------------------------------------
  170. /** @brief Returns a scaling matrix
  171. * @param v Scaling vector
  172. * @param out Receives the output matrix
  173. * @return Reference to the output matrix
  174. */
  175. static aiMatrix4x4& Scaling( const aiVector3D& v, aiMatrix4x4& out);
  176. // -------------------------------------------------------------------
  177. /** @brief A function for creating a rotation matrix that rotates a
  178. * vector called "from" into another vector called "to".
  179. * Input : from[3], to[3] which both must be *normalized* non-zero vectors
  180. * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
  181. * Authors: Tomas Möller, John Hughes
  182. * "Efficiently Building a Matrix to Rotate One Vector to Another"
  183. * Journal of Graphics Tools, 4(4):1-4, 1999
  184. */
  185. static aiMatrix4x4& FromToMatrix(const aiVector3D& from,
  186. const aiVector3D& to, aiMatrix4x4& out);
  187. #endif // __cplusplus
  188. float a1, a2, a3, a4;
  189. float b1, b2, b3, b4;
  190. float c1, c2, c3, c4;
  191. float d1, d2, d3, d4;
  192. } PACK_STRUCT; // !class aiMatrix4x4
  193. #include "./Compiler/poppack1.h"
  194. #ifdef __cplusplus
  195. } // end extern "C"
  196. #endif // __cplusplus
  197. #endif // AI_MATRIX4X4_H_INC