diff options
author | crupest <crupest@outlook.com> | 2020-06-28 00:03:11 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-28 00:03:11 +0800 |
commit | 06d1d0442276a05b6caad6e3468f4afb1e8ee5df (patch) | |
tree | ebd46f0fb7343dc57bf947b7b5fffc139c3ddeac /include/cru/platform/matrix.hpp | |
parent | e11be6caa9ef9b2b198ca61846e32f469627556e (diff) | |
download | cru-06d1d0442276a05b6caad6e3468f4afb1e8ee5df.tar.gz cru-06d1d0442276a05b6caad6e3468f4afb1e8ee5df.tar.bz2 cru-06d1d0442276a05b6caad6e3468f4afb1e8ee5df.zip |
...
Diffstat (limited to 'include/cru/platform/matrix.hpp')
-rw-r--r-- | include/cru/platform/matrix.hpp | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp deleted file mode 100644 index cea5198b..00000000 --- a/include/cru/platform/matrix.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once -#include "GraphBase.hpp" - -#include <cmath> - -namespace cru::platform { -struct Matrix { - float m11; - float m12; - float m21; - float m22; - float m31; - float m32; - - Matrix() {} - - Matrix(float m11, float m12, float m21, float m22, float m31, float m32) { - this->m11 = m11; - this->m12 = m12; - this->m21 = m21; - this->m22 = m22; - this->m31 = m31; - this->m32 = m32; - } - - bool IsIdentity() const { - return m11 == 1.0f && m12 == 0.0f && m21 == 0.0f && m22 == 1.0f && - m31 == 0.0f && m32 == 0.0f; - } - - Matrix& operator*=(const Matrix& matrix) { - *this = Product(*this, matrix); - return *this; - } - - Matrix operator*(const Matrix& matrix) const { - return Product(*this, matrix); - } - - Point TransformPoint(const Point& point) const { - return Point{point.x * m11 + point.y * m21 + m31, - point.x * m12 + point.y * m22 + m32}; - } - - static Matrix Identity() { - return Matrix{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}; - } - - static Matrix Translation(float x, float y) { - return Matrix{1.0f, 0.0f, 0.0f, 1.0f, x, y}; - } - - static Matrix Scale(float sx, float sy) { - return Matrix{sx, 0.0f, 0.0f, sy, 0.0f, 0.0f}; - } - - static Matrix Rotation(float angle) { - float r = AngleToRadian(angle); - float s = std::sinf(r); - float c = std::cosf(r); - - return Matrix{c, s, -s, c, 0.0f, 0.0f}; - } - - static Matrix Skew(float sx, float sy) { - return Matrix{1.0f, sx, sy, 1.0f, 0.0f, 0.0f}; - } - - static Matrix Product(const Matrix& a, const Matrix& b) { - return Matrix{a.m11 * b.m11 + a.m12 * b.m21, - a.m11 * b.m12 + a.m12 * b.m22, - a.m21 * b.m11 + a.m22 * b.m21, - a.m21 * b.m12 + a.m22 * b.m22, - a.m31 * b.m11 + a.m32 * b.m21 + b.m31, - a.m31 * b.m12 + a.m32 * b.m22 + b.m32}; - } - - private: - static constexpr float PI = 3.1415926535f; - - static float AngleToRadian(float angle) { return angle / 180.f * PI; } -}; -} // namespace cru::platform |