You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

186 lines
6.0 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp 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 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 matrix3x3.h
  35. * @brief Definition of a 3x3 matrix, including operators when compiling in C++
  36. */
  37. #ifndef AI_MATRIX3x3_H_INC
  38. #define AI_MATRIX3x3_H_INC
  39. #include "./Compiler/pushpack1.h"
  40. #ifdef __cplusplus
  41. template <typename T> class aiMatrix4x4t;
  42. template <typename T> class aiVector2t;
  43. // ---------------------------------------------------------------------------
  44. /** @brief Represents a row-major 3x3 matrix
  45. *
  46. * There's much confusion about matrix layouts (column vs. row order).
  47. * This is *always* a row-major matrix. Not even with the
  48. * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect
  49. * matrix order - it just affects the handedness of the coordinate system
  50. * defined thereby.
  51. */
  52. template <typename TReal>
  53. class aiMatrix3x3t
  54. {
  55. public:
  56. aiMatrix3x3t () :
  57. a1(static_cast<TReal>(1.0f)), a2(), a3(),
  58. b1(), b2(static_cast<TReal>(1.0f)), b3(),
  59. c1(), c2(), c3(static_cast<TReal>(1.0f)) {}
  60. aiMatrix3x3t ( TReal _a1, TReal _a2, TReal _a3,
  61. TReal _b1, TReal _b2, TReal _b3,
  62. TReal _c1, TReal _c2, TReal _c3) :
  63. a1(_a1), a2(_a2), a3(_a3),
  64. b1(_b1), b2(_b2), b3(_b3),
  65. c1(_c1), c2(_c2), c3(_c3)
  66. {}
  67. public:
  68. // matrix multiplication.
  69. aiMatrix3x3t& operator *= (const aiMatrix3x3t& m);
  70. aiMatrix3x3t operator * (const aiMatrix3x3t& m) const;
  71. // array access operators
  72. TReal* operator[] (unsigned int p_iIndex);
  73. const TReal* operator[] (unsigned int p_iIndex) const;
  74. // comparison operators
  75. bool operator== (const aiMatrix4x4t<TReal>& m) const;
  76. bool operator!= (const aiMatrix4x4t<TReal>& m) const;
  77. bool Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon = 1e-6) const;
  78. template <typename TOther>
  79. operator aiMatrix3x3t<TOther> () const;
  80. public:
  81. // -------------------------------------------------------------------
  82. /** @brief Construction from a 4x4 matrix. The remaining parts
  83. * of the matrix are ignored.
  84. */
  85. explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix);
  86. // -------------------------------------------------------------------
  87. /** @brief Transpose the matrix
  88. */
  89. aiMatrix3x3t& Transpose();
  90. // -------------------------------------------------------------------
  91. /** @brief Invert the matrix.
  92. * If the matrix is not invertible all elements are set to qnan.
  93. * Beware, use (f != f) to check whether a TReal f is qnan.
  94. */
  95. aiMatrix3x3t& Inverse();
  96. TReal Determinant() const;
  97. public:
  98. // -------------------------------------------------------------------
  99. /** @brief Returns a rotation matrix for a rotation around z
  100. * @param a Rotation angle, in radians
  101. * @param out Receives the output matrix
  102. * @return Reference to the output matrix
  103. */
  104. static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out);
  105. // -------------------------------------------------------------------
  106. /** @brief Returns a rotation matrix for a rotation around
  107. * an arbitrary axis.
  108. *
  109. * @param a Rotation angle, in radians
  110. * @param axis Axis to rotate around
  111. * @param out To be filled
  112. */
  113. static aiMatrix3x3t& Rotation( TReal a,
  114. const aiVector3t<TReal>& axis, aiMatrix3x3t& out);
  115. // -------------------------------------------------------------------
  116. /** @brief Returns a translation matrix
  117. * @param v Translation vector
  118. * @param out Receives the output matrix
  119. * @return Reference to the output matrix
  120. */
  121. static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out);
  122. // -------------------------------------------------------------------
  123. /** @brief A function for creating a rotation matrix that rotates a
  124. * vector called "from" into another vector called "to".
  125. * Input : from[3], to[3] which both must be *normalized* non-zero vectors
  126. * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
  127. * Authors: Tomas Möller, John Hughes
  128. * "Efficiently Building a Matrix to Rotate One Vector to Another"
  129. * Journal of Graphics Tools, 4(4):1-4, 1999
  130. */
  131. static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from,
  132. const aiVector3t<TReal>& to, aiMatrix3x3t& out);
  133. public:
  134. TReal a1, a2, a3;
  135. TReal b1, b2, b3;
  136. TReal c1, c2, c3;
  137. } PACK_STRUCT;
  138. typedef aiMatrix3x3t<float> aiMatrix3x3;
  139. #else
  140. struct aiMatrix3x3 {
  141. float a1, a2, a3;
  142. float b1, b2, b3;
  143. float c1, c2, c3;
  144. } PACK_STRUCT;
  145. #endif
  146. #include "./Compiler/poppack1.h"
  147. #endif // AI_MATRIX3x3_H_INC