23#include <kiwano/math/Rect.hpp>
24#include <kiwano/math/Vec2.hpp>
30template <
typename _Ty,
typename _Lty,
typename _Rty>
33template <
typename _Ty>
36 using ValueType = _Ty;
49 _Ty _11, _12, _21, _22, _31, _32;
63 Matrix3x2T(ValueType _11, ValueType _12, ValueType _21, ValueType _22, ValueType _31, ValueType _32)
75 for (
int i = 0; i < 6; i++)
89 KGE_SUPPRESS_WARNING_PUSH
90 KGE_SUPPRESS_WARNING(26495)
92 template <
typename _MTy>
95 for (
int i = 0; i < 6; i++)
99 KGE_SUPPRESS_WARNING_POP
101 inline ValueType operator[](uint32_t index)
const
106 inline ValueType& operator[](uint32_t index)
113 for (
int i = 0; i < 6; i++)
118 template <
typename _Lty,
typename _Rty>
128 return operator=((*
this) * other);
131 inline void Identity()
141 inline bool IsIdentity()
const
143 return _11 == 1.f && _12 == 0.f && _21 == 0.f && _22 == 1.f && _31 == 0.f && _32 == 0.f;
148 ValueType det = 1.f / Determinant();
149 return Matrix3x2T(det * _22, -det * _12, -det * _21, det * _11, det * (_21 * _32 - _22 * _31),
150 det * (_12 * _31 - _11 * _32));
153 inline bool IsInvertible()
const
155 return 0 != Determinant();
158 inline ValueType Determinant()
const
160 return (_11 * _22) - (_12 * _21);
165 return Vec2Type(v.x * _11 + v.y * _21 + _31, v.x * _12 + v.y * _22 + _32);
175 ValueType left = std::min(std::min(top_left.x, top_right.x), std::min(bottom_left.x, bottom_right.x));
176 ValueType right = std::max(std::max(top_left.x, top_right.x), std::max(bottom_left.x, bottom_right.x));
177 ValueType top = std::min(std::min(top_left.y, top_right.y), std::min(bottom_left.y, bottom_right.y));
178 ValueType bottom = std::max(std::max(top_left.y, top_right.y), std::max(bottom_left.y, bottom_right.y));
180 return RectType{ left, top, right, bottom };
183 inline void Translate(
const Vec2Type& v)
185 _31 += _11 * v.x + _21 * v.y;
186 _32 += _12 * v.x + _22 * v.y;
191 return Matrix3x2T(1.f, 0.f, 0.f, 1.f, v.x, v.y);
196 return Matrix3x2T(v.x, 0.f, 0.f, v.y, 0.f, 0.f);
201 return Matrix3x2T(v.x, 0.f, 0.f, v.y, center.x - v.x * center.x, center.y - v.y * center.y);
204 static inline Matrix3x2T Rotation(ValueType angle)
206 ValueType s = math::Sin(angle);
207 ValueType c = math::Cos(angle);
213 ValueType s = math::Sin(angle);
214 ValueType c = math::Cos(angle);
215 return Matrix3x2T(c, s, -s, c, center.x * (1 - c) + center.y * s, center.y * (1 - c) - center.x * s);
220 ValueType s = math::Sin(angle);
221 ValueType c = math::Cos(angle);
222 return Matrix3x2T(c * scale.x, s * scale.x, -s * scale.y, c * scale.y, trans.x, trans.y);
227 ValueType tx = math::Tan(angle.x);
228 ValueType ty = math::Tan(angle.y);
229 return Matrix3x2T(1.f, -ty, -tx, 1.f, 0.f, 0.f);
234 ValueType tx = math::Tan(angle.x);
235 ValueType ty = math::Tan(angle.y);
236 return Matrix3x2T(1.f, -ty, -tx, 1.f, center.y * tx, center.x * ty);
241template <
typename _Ty,
typename _Lty,
typename _Rty>
253 inline _Ty operator[](uint32_t index)
const
258 return lhs[0] * rhs[0] + lhs[1] * rhs[2];
260 return lhs[0] * rhs[1] + lhs[1] * rhs[3];
262 return lhs[2] * rhs[0] + lhs[3] * rhs[2];
264 return lhs[2] * rhs[1] + lhs[3] * rhs[3];
266 return lhs[4] * rhs[0] + lhs[5] * rhs[2] + rhs[4];
268 return lhs[4] * rhs[1] + lhs[5] * rhs[3] + rhs[5];
275template <
typename _Ty>
282template <
typename _Ty,
typename _Lty,
typename _Rty>
283inline MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, Matrix3x2T<_Ty>>
284operator*(
const MatrixMultiply<_Ty, _Lty, _Rty>& lhs,
const Matrix3x2T<_Ty>& rhs)
286 return MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, Matrix3x2T<_Ty>>(lhs, rhs);
Definition: Matrix.hpp:35
Definition: Matrix.hpp:243