matrix3x3.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. template <typename TOther>
  78. operator aiMatrix3x3t<TOther> () const;
  79. public:
  80. // -------------------------------------------------------------------
  81. /** @brief Construction from a 4x4 matrix. The remaining parts
  82. * of the matrix are ignored.
  83. */
  84. explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix);
  85. // -------------------------------------------------------------------
  86. /** @brief Transpose the matrix
  87. */
  88. aiMatrix3x3t& Transpose();
  89. // -------------------------------------------------------------------
  90. /** @brief Invert the matrix.
  91. * If the matrix is not invertible all elements are set to qnan.
  92. * Beware, use (f != f) to check whether a TReal f is qnan.
  93. */
  94. aiMatrix3x3t& Inverse();
  95. TReal Determinant() const;
  96. public:
  97. // -------------------------------------------------------------------
  98. /** @brief Returns a rotation matrix for a rotation around z
  99. * @param a Rotation angle, in radians
  100. * @param out Receives the output matrix
  101. * @return Reference to the output matrix
  102. */
  103. static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out);
  104. // -------------------------------------------------------------------
  105. /** @brief Returns a rotation matrix for a rotation around
  106. * an arbitrary axis.
  107. *
  108. * @param a Rotation angle, in radians
  109. * @param axis Axis to rotate around
  110. * @param out To be filled
  111. */
  112. static aiMatrix3x3t& Rotation( TReal a,
  113. const aiVector3t<TReal>& axis, aiMatrix3x3t& out);
  114. // -------------------------------------------------------------------
  115. /** @brief Returns a translation matrix
  116. * @param v Translation vector
  117. * @param out Receives the output matrix
  118. * @return Reference to the output matrix
  119. */
  120. static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out);
  121. // -------------------------------------------------------------------
  122. /** @brief A function for creating a rotation matrix that rotates a
  123. * vector called "from" into another vector called "to".
  124. * Input : from[3], to[3] which both must be *normalized* non-zero vectors
  125. * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
  126. * Authors: Tomas Möller, John Hughes
  127. * "Efficiently Building a Matrix to Rotate One Vector to Another"
  128. * Journal of Graphics Tools, 4(4):1-4, 1999
  129. */
  130. static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from,
  131. const aiVector3t<TReal>& to, aiMatrix3x3t& out);
  132. public:
  133. TReal a1, a2, a3;
  134. TReal b1, b2, b3;
  135. TReal c1, c2, c3;
  136. } PACK_STRUCT;
  137. typedef aiMatrix3x3t<float> aiMatrix3x3;
  138. #else
  139. struct aiMatrix3x3 {
  140. float a1, a2, a3;
  141. float b1, b2, b3;
  142. float c1, c2, c3;
  143. } PACK_STRUCT;
  144. #endif
  145. #include "./Compiler/poppack1.h"
  146. #endif // AI_MATRIX3x3_H_INC