1 | /* |
---|---|

2 | --------------------------------------------------------------------------- |

3 | Open Asset Import Library (assimp) |

4 | --------------------------------------------------------------------------- |

5 | |

6 | Copyright (c) 2006-2017, assimp team |

7 | |

8 | |

9 | All rights reserved. |

10 | |

11 | Redistribution and use of this software in source and binary forms, |

12 | with or without modification, are permitted provided that the following |

13 | conditions are met: |

14 | |

15 | * Redistributions of source code must retain the above |

16 | copyright notice, this list of conditions and the |

17 | following disclaimer. |

18 | |

19 | * Redistributions in binary form must reproduce the above |

20 | copyright notice, this list of conditions and the |

21 | following disclaimer in the documentation and/or other |

22 | materials provided with the distribution. |

23 | |

24 | * Neither the name of the assimp team, nor the names of its |

25 | contributors may be used to endorse or promote products |

26 | derived from this software without specific prior |

27 | written permission of the assimp team. |

28 | |

29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |

30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |

31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |

32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |

33 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |

34 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |

35 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |

36 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |

37 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |

38 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |

39 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |

40 | --------------------------------------------------------------------------- |

41 | */ |

42 | |

43 | /** @file matrix3x3.h |

44 | * @brief Definition of a 3x3 matrix, including operators when compiling in C++ |

45 | */ |

46 | #pragma once |

47 | #ifndef AI_MATRIX3X3_H_INC |

48 | #define AI_MATRIX3X3_H_INC |

49 | |

50 | #include "defs.h" |

51 | |

52 | #ifdef __cplusplus |

53 | |

54 | template <typename T> class aiMatrix4x4t; |

55 | template <typename T> class aiVector2t; |

56 | |

57 | // --------------------------------------------------------------------------- |

58 | /** @brief Represents a row-major 3x3 matrix |

59 | * |

60 | * There's much confusion about matrix layouts (column vs. row order). |

61 | * This is *always* a row-major matrix. Not even with the |

62 | * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect |

63 | * matrix order - it just affects the handedness of the coordinate system |

64 | * defined thereby. |

65 | */ |

66 | template <typename TReal> |

67 | class aiMatrix3x3t |

68 | { |

69 | public: |

70 | |

71 | aiMatrix3x3t () : |

72 | a1(static_cast<TReal>(1.0f)), a2(), a3(), |

73 | b1(), b2(static_cast<TReal>(1.0f)), b3(), |

74 | c1(), c2(), c3(static_cast<TReal>(1.0f)) {} |

75 | |

76 | aiMatrix3x3t ( TReal _a1, TReal _a2, TReal _a3, |

77 | TReal _b1, TReal _b2, TReal _b3, |

78 | TReal _c1, TReal _c2, TReal _c3) : |

79 | a1(_a1), a2(_a2), a3(_a3), |

80 | b1(_b1), b2(_b2), b3(_b3), |

81 | c1(_c1), c2(_c2), c3(_c3) |

82 | {} |

83 | |

84 | public: |

85 | |

86 | // matrix multiplication. |

87 | aiMatrix3x3t& operator *= (const aiMatrix3x3t& m); |

88 | aiMatrix3x3t operator * (const aiMatrix3x3t& m) const; |

89 | |

90 | // array access operators |

91 | TReal* operator[] (unsigned int p_iIndex); |

92 | const TReal* operator[] (unsigned int p_iIndex) const; |

93 | |

94 | // comparison operators |

95 | bool operator== (const aiMatrix4x4t<TReal>& m) const; |

96 | bool operator!= (const aiMatrix4x4t<TReal>& m) const; |

97 | |

98 | bool Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon = 1e-6) const; |

99 | |

100 | template <typename TOther> |

101 | operator aiMatrix3x3t<TOther> () const; |

102 | |

103 | public: |

104 | |

105 | // ------------------------------------------------------------------- |

106 | /** @brief Construction from a 4x4 matrix. The remaining parts |

107 | * of the matrix are ignored. |

108 | */ |

109 | explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix); |

110 | |

111 | // ------------------------------------------------------------------- |

112 | /** @brief Transpose the matrix |

113 | */ |

114 | aiMatrix3x3t& Transpose(); |

115 | |

116 | // ------------------------------------------------------------------- |

117 | /** @brief Invert the matrix. |

118 | * If the matrix is not invertible all elements are set to qnan. |

119 | * Beware, use (f != f) to check whether a TReal f is qnan. |

120 | */ |

121 | aiMatrix3x3t& Inverse(); |

122 | TReal Determinant() const; |

123 | |

124 | public: |

125 | // ------------------------------------------------------------------- |

126 | /** @brief Returns a rotation matrix for a rotation around z |

127 | * @param a Rotation angle, in radians |

128 | * @param out Receives the output matrix |

129 | * @return Reference to the output matrix |

130 | */ |

131 | static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out); |

132 | |

133 | // ------------------------------------------------------------------- |

134 | /** @brief Returns a rotation matrix for a rotation around |

135 | * an arbitrary axis. |

136 | * |

137 | * @param a Rotation angle, in radians |

138 | * @param axis Axis to rotate around |

139 | * @param out To be filled |

140 | */ |

141 | static aiMatrix3x3t& Rotation( TReal a, |

142 | const aiVector3t<TReal>& axis, aiMatrix3x3t& out); |

143 | |

144 | // ------------------------------------------------------------------- |

145 | /** @brief Returns a translation matrix |

146 | * @param v Translation vector |

147 | * @param out Receives the output matrix |

148 | * @return Reference to the output matrix |

149 | */ |

150 | static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out); |

151 | |

152 | // ------------------------------------------------------------------- |

153 | /** @brief A function for creating a rotation matrix that rotates a |

154 | * vector called "from" into another vector called "to". |

155 | * Input : from[3], to[3] which both must be *normalized* non-zero vectors |

156 | * Output: mtx[3][3] -- a 3x3 matrix in column-major form |

157 | * Authors: Tomas MÃ¶ller, John Hughes |

158 | * "Efficiently Building a Matrix to Rotate One Vector to Another" |

159 | * Journal of Graphics Tools, 4(4):1-4, 1999 |

160 | */ |

161 | static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from, |

162 | const aiVector3t<TReal>& to, aiMatrix3x3t& out); |

163 | |

164 | public: |

165 | TReal a1, a2, a3; |

166 | TReal b1, b2, b3; |

167 | TReal c1, c2, c3; |

168 | }; |

169 | |

170 | typedef aiMatrix3x3t<ai_real> aiMatrix3x3; |

171 | |

172 | #else |

173 | |

174 | struct aiMatrix3x3 { |

175 | ai_real a1, a2, a3; |

176 | ai_real b1, b2, b3; |

177 | ai_real c1, c2, c3; |

178 | }; |

179 | |

180 | #endif // __cplusplus |

181 | |

182 | #endif // AI_MATRIX3X3_H_INC |

183 |