123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #pragma once
- #include <Mathematics/Matrix.h>
- #include <Mathematics/Vector2.h>
- namespace WwiseGTE
- {
-
- template <typename Real>
- using Matrix2x2 = Matrix<2, 2, Real>;
-
-
-
-
-
-
-
- template <typename Real>
- void MakeRotation(Real angle, Matrix2x2<Real>& rotation)
- {
- Real cs = std::cos(angle);
- Real sn = std::sin(angle);
- #if defined(GTE_USE_MAT_VEC)
- rotation(0, 0) = cs;
- rotation(0, 1) = -sn;
- rotation(1, 0) = sn;
- rotation(1, 1) = cs;
- #else
- rotation(0, 0) = cs;
- rotation(0, 1) = sn;
- rotation(1, 0) = -sn;
- rotation(1, 1) = cs;
- #endif
- }
-
-
- template <typename Real>
- Real GetRotationAngle(Matrix2x2<Real> const& rotation)
- {
- #if defined(GTE_USE_MAT_VEC)
- return std::atan2(rotation(1, 0), rotation(0, 0));
- #else
- return std::atan2(rotation(0, 1), rotation(0, 0));
- #endif
- }
-
- template <typename Real>
- Matrix2x2<Real> Inverse(Matrix2x2<Real> const& M, bool* reportInvertibility = nullptr)
- {
- Matrix2x2<Real> inverse;
- bool invertible;
- Real det = M(0, 0) * M(1, 1) - M(0, 1) * M(1, 0);
- if (det != (Real)0)
- {
- Real invDet = ((Real)1) / det;
- inverse = Matrix2x2<Real>
- {
- M(1, 1) * invDet, -M(0, 1) * invDet,
- -M(1, 0) * invDet, M(0, 0) * invDet
- };
- invertible = true;
- }
- else
- {
- inverse.MakeZero();
- invertible = false;
- }
- if (reportInvertibility)
- {
- *reportInvertibility = invertible;
- }
- return inverse;
- }
- template <typename Real>
- Matrix2x2<Real> Adjoint(Matrix2x2<Real> const& M)
- {
- return Matrix2x2<Real>
- {
- M(1, 1), -M(0, 1),
- -M(1, 0), M(0, 0)
- };
- }
- template <typename Real>
- Real Determinant(Matrix2x2<Real> const& M)
- {
- Real det = M(0, 0) * M(1, 1) - M(0, 1) * M(1, 0);
- return det;
- }
- template <typename Real>
- Real Trace(Matrix2x2<Real> const& M)
- {
- Real trace = M(0, 0) + M(1, 1);
- return trace;
- }
-
-
-
-
- template <typename Real>
- Vector2<Real> DoTransform(Matrix2x2<Real> const& M, Vector2<Real> const& V)
- {
- #if defined(GTE_USE_MAT_VEC)
- return M * V;
- #else
- return V * M;
- #endif
- }
- template <typename Real>
- Matrix2x2<Real> DoTransform(Matrix2x2<Real> const& A, Matrix2x2<Real> const& B)
- {
- #if defined(GTE_USE_MAT_VEC)
- return A * B;
- #else
- return B * A;
- #endif
- }
-
-
-
-
-
-
- template <typename Real>
- void SetBasis(Matrix2x2<Real>& M, int i, Vector2<Real> const& V)
- {
- #if defined(GTE_USE_MAT_VEC)
- return M.SetCol(i, V);
- #else
- return M.SetRow(i, V);
- #endif
- }
- template <typename Real>
- Vector2<Real> GetBasis(Matrix2x2<Real> const& M, int i)
- {
- #if defined(GTE_USE_MAT_VEC)
- return M.GetCol(i);
- #else
- return M.GetRow(i);
- #endif
- }
- }
|