aiMatrix3x3.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 aiMatrix3x3.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. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. struct aiMatrix4x4;
  43. struct aiVector2D;
  44. // ---------------------------------------------------------------------------
  45. /** @brief Represents a row-major 3x3 matrix
  46. *
  47. * There's much confusion about matrix layouts (colum vs. row order).
  48. * This is *always* a row-major matrix. Even with the
  49. * aiProcess_ConvertToLeftHanded flag.
  50. */
  51. struct aiMatrix3x3
  52. {
  53. #ifdef __cplusplus
  54. aiMatrix3x3 () :
  55. a1(1.0f), a2(0.0f), a3(0.0f),
  56. b1(0.0f), b2(1.0f), b3(0.0f),
  57. c1(0.0f), c2(0.0f), c3(1.0f) {}
  58. aiMatrix3x3 ( float _a1, float _a2, float _a3,
  59. float _b1, float _b2, float _b3,
  60. float _c1, float _c2, float _c3) :
  61. a1(_a1), a2(_a2), a3(_a3),
  62. b1(_b1), b2(_b2), b3(_b3),
  63. c1(_c1), c2(_c2), c3(_c3)
  64. {}
  65. public:
  66. // matrix multiplication. beware, not commutative
  67. aiMatrix3x3& operator *= (const aiMatrix3x3& m);
  68. aiMatrix3x3 operator * (const aiMatrix3x3& m) const;
  69. // array access operators
  70. float* operator[] (unsigned int p_iIndex);
  71. const float* operator[] (unsigned int p_iIndex) const;
  72. // comparison operators
  73. bool operator== (const aiMatrix4x4 m) const;
  74. bool operator!= (const aiMatrix4x4 m) const;
  75. public:
  76. // -------------------------------------------------------------------
  77. /** @brief Construction from a 4x4 matrix. The remaining parts
  78. * of the matrix are ignored.
  79. */
  80. explicit aiMatrix3x3( const aiMatrix4x4& pMatrix);
  81. // -------------------------------------------------------------------
  82. /** @brief Transpose the matrix
  83. */
  84. aiMatrix3x3& Transpose();
  85. // -------------------------------------------------------------------
  86. /** @brief Invert the matrix.
  87. * If the matrix is not invertible all elements are set to qnan.
  88. * Beware, use (f != f) to check whether a float f is qnan.
  89. */
  90. aiMatrix3x3& Inverse();
  91. float Determinant() const;
  92. public:
  93. // -------------------------------------------------------------------
  94. /** @brief Returns a rotation matrix for a rotation around z
  95. * @param a Rotation angle, in radians
  96. * @param out Receives the output matrix
  97. * @return Reference to the output matrix
  98. */
  99. static aiMatrix3x3& RotationZ(float a, aiMatrix3x3& out);
  100. // -------------------------------------------------------------------
  101. /** @brief Returns a rotation matrix for a rotation around
  102. * an arbitrary axis.
  103. *
  104. * @param a Rotation angle, in radians
  105. * @param axis Axis to rotate around
  106. * @param out To be filled
  107. */
  108. static aiMatrix3x3& Rotation( float a,
  109. const aiVector3D& axis, aiMatrix3x3& out);
  110. // -------------------------------------------------------------------
  111. /** @brief Returns a translation matrix
  112. * @param v Translation vector
  113. * @param out Receives the output matrix
  114. * @return Reference to the output matrix
  115. */
  116. static aiMatrix3x3& Translation( const aiVector2D& v, aiMatrix3x3& out);
  117. // -------------------------------------------------------------------
  118. /** @brief A function for creating a rotation matrix that rotates a
  119. * vector called "from" into another vector called "to".
  120. * Input : from[3], to[3] which both must be *normalized* non-zero vectors
  121. * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
  122. * Authors: Tomas Möller, John Hughes
  123. * "Efficiently Building a Matrix to Rotate One Vector to Another"
  124. * Journal of Graphics Tools, 4(4):1-4, 1999
  125. */
  126. static aiMatrix3x3& FromToMatrix(const aiVector3D& from,
  127. const aiVector3D& to, aiMatrix3x3& out);
  128. #endif // __cplusplus
  129. float a1, a2, a3;
  130. float b1, b2, b3;
  131. float c1, c2, c3;
  132. };
  133. #ifdef __cplusplus
  134. } // end of extern C
  135. #endif
  136. #endif // AI_MATRIX3x3_H_INC