From a9d091329abf412798b79373dc4bc59a9ecdc882 Mon Sep 17 00:00:00 2001 From: Alister Date: Sat, 27 Nov 2021 20:48:33 +0000 Subject: [PATCH] removing remain matrix4x4 includes and files --- src/math/frustum.hpp | 3 +- src/math/matrix_4x4.cpp | 239 ------------------ src/math/matrix_4x4.hpp | 140 ---------- src/math/ray.hpp | 2 +- src/noggit/Model.h | 2 +- src/noggit/Red/AssetBrowser/ModelView.hpp | 1 - .../Red/PreviewRenderer/PreviewRenderer.hpp | 1 - .../Red/ViewportGizmo/ViewportGizmo.hpp | 1 - src/noggit/SceneObject.hpp | 2 +- src/noggit/camera.hpp | 4 +- src/noggit/cursor_render.cpp | 2 +- src/noggit/cursor_render.hpp | 1 - src/opengl/types.hpp | 2 +- 13 files changed, 8 insertions(+), 392 deletions(-) delete mode 100644 src/math/matrix_4x4.cpp delete mode 100644 src/math/matrix_4x4.hpp diff --git a/src/math/frustum.hpp b/src/math/frustum.hpp index 21dd4664..7c466c11 100644 --- a/src/math/frustum.hpp +++ b/src/math/frustum.hpp @@ -1,8 +1,7 @@ // This file is part of Noggit3, licensed under GNU General Public License (version 3). #pragma once -#include - +#include #include namespace math diff --git a/src/math/matrix_4x4.cpp b/src/math/matrix_4x4.cpp deleted file mode 100644 index 89af860d..00000000 --- a/src/math/matrix_4x4.cpp +++ /dev/null @@ -1,239 +0,0 @@ -// This file is part of Noggit3, licensed under GNU General Public License (version 3). - -#include - -#include -#include // memcpy, memset -#include -#include - -namespace math -{ - matrix_4x4::uninitialized_t matrix_4x4::uninitialized; - matrix_4x4::zero_t matrix_4x4::zero; - matrix_4x4::unit_t matrix_4x4::unit; - matrix_4x4::translation_t matrix_4x4::translation; - matrix_4x4::scale_t matrix_4x4::scale; - matrix_4x4::rotation_t matrix_4x4::rotation; - matrix_4x4::rotation_xyz_t matrix_4x4::rotation_xyz; - matrix_4x4::rotation_yzx_t matrix_4x4::rotation_yzx; - matrix_4x4::rotation_yxz_t matrix_4x4::rotation_yxz; - - matrix_4x4::matrix_4x4 (rotation_t, glm::quat const& q) - { - _m[0][0] = 1.0f - 2.0f * q.y * q.y - 2.0f * q.z * q.z; - _m[0][1] = 2.0f * q.x * q.y + 2.0f * q.w * q.z; - _m[0][2] = 2.0f * q.x * q.z - 2.0f * q.w * q.y; - _m[0][3] = 0.0f; - - _m[1][0] = 2.0f * q.x * q.y - 2.0f * q.w * q.z; - _m[1][1] = 1.0f - 2.0f * q.x * q.x - 2.0f * q.z * q.z; - _m[1][2] = 2.0f * q.y * q.z + 2.0f * q.w * q.x; - _m[1][3] = 0.0f; - - _m[2][0] = 2.0f * q.x * q.z + 2.0f * q.w * q.y; - _m[2][1] = 2.0f * q.y * q.z - 2.0f * q.w * q.x; - _m[2][2] = 1.0f - 2.0f * q.x * q.x - 2.0f * q.y * q.y; - _m[2][3] = 0.0f; - - _m[3][0] = 0.0f; - _m[3][1] = 0.0f; - _m[3][2] = 0.0f; - _m[3][3] = 1.0f; - } - - namespace - { - enum axis - { - x = 0, - y = 1, - z = 2, - num_axis, - }; - - template - matrix_4x4 rotate_axis (radians angle) - { - static std::size_t const i_indices[num_axis] = {2, 2, 1}; - static std::size_t const j_indices[num_axis] = {1, 0, 0}; - std::size_t const i_index (i_indices[a]); - std::size_t const j_index (j_indices[a]); - - float const cosV (glm::cos (angle._)); - float const sinV (glm::sin (angle._)); - - matrix_4x4 mat (matrix_4x4::unit); - mat (j_index, j_index, cosV); - mat (j_index, i_index, sinV); - mat (i_index, j_index, -sinV); - mat (i_index, i_index, cosV); - - return mat; - } - } - - matrix_4x4::matrix_4x4 (rotation_xyz_t, degrees::vec3 const& angle) - : matrix_4x4 (unit) - { - *this *= rotate_axis(degrees(angle.x)); - *this *= rotate_axis(degrees(angle.y)); - *this *= rotate_axis(degrees(angle.z)); - } - matrix_4x4::matrix_4x4 (rotation_yzx_t, degrees::vec3 const& angle) - : matrix_4x4 (unit) - { - *this *= rotate_axis (degrees(angle.y)); - *this *= rotate_axis (degrees(angle.z)); - *this *= rotate_axis (degrees(angle.x)); - } - - matrix_4x4::matrix_4x4(rotation_yxz_t, degrees::vec3 const& angle) - : matrix_4x4(unit) - { - *this *= rotate_axis(degrees(angle.y)); - *this *= rotate_axis(degrees(angle.x)); - *this *= rotate_axis(degrees(angle.z)); - } - - glm::vec3 matrix_4x4::operator* (glm::vec3 const& v) const - { - return { _m[0][0] * v[0] + _m[0][1] * v[1] + _m[0][2] * v[2] + _m[0][3] - , _m[1][0] * v[0] + _m[1][1] * v[1] + _m[1][2] * v[2] + _m[1][3] - , _m[2][0] * v[0] + _m[2][1] * v[1] + _m[2][2] * v[2] + _m[2][3] - }; - } - glm::vec4 matrix_4x4::operator* (const glm::vec4& v) const - { - return { _m[0][0] * v[0] + _m[0][1] * v[1] + _m[0][2] * v[2] + _m[0][3] * v[3] - , _m[1][0] * v[0] + _m[1][1] * v[1] + _m[1][2] * v[2] + _m[1][3] * v[3] - , _m[2][0] * v[0] + _m[2][1] * v[1] + _m[2][2] * v[2] + _m[2][3] * v[3] - , _m[3][0] * v[0] + _m[3][1] * v[1] + _m[3][2] * v[2] + _m[3][3] * v[3] - }; - } - - matrix_4x4 matrix_4x4::operator* (matrix_4x4 const& other) const - { - return { _m[0][0] * other._m[0][0] + _m[0][1] * other._m[1][0] + _m[0][2] * other._m[2][0] + _m[0][3] * other._m[3][0] - , _m[0][0] * other._m[0][1] + _m[0][1] * other._m[1][1] + _m[0][2] * other._m[2][1] + _m[0][3] * other._m[3][1] - , _m[0][0] * other._m[0][2] + _m[0][1] * other._m[1][2] + _m[0][2] * other._m[2][2] + _m[0][3] * other._m[3][2] - , _m[0][0] * other._m[0][3] + _m[0][1] * other._m[1][3] + _m[0][2] * other._m[2][3] + _m[0][3] * other._m[3][3] - , _m[1][0] * other._m[0][0] + _m[1][1] * other._m[1][0] + _m[1][2] * other._m[2][0] + _m[1][3] * other._m[3][0] - , _m[1][0] * other._m[0][1] + _m[1][1] * other._m[1][1] + _m[1][2] * other._m[2][1] + _m[1][3] * other._m[3][1] - , _m[1][0] * other._m[0][2] + _m[1][1] * other._m[1][2] + _m[1][2] * other._m[2][2] + _m[1][3] * other._m[3][2] - , _m[1][0] * other._m[0][3] + _m[1][1] * other._m[1][3] + _m[1][2] * other._m[2][3] + _m[1][3] * other._m[3][3] - , _m[2][0] * other._m[0][0] + _m[2][1] * other._m[1][0] + _m[2][2] * other._m[2][0] + _m[2][3] * other._m[3][0] - , _m[2][0] * other._m[0][1] + _m[2][1] * other._m[1][1] + _m[2][2] * other._m[2][1] + _m[2][3] * other._m[3][1] - , _m[2][0] * other._m[0][2] + _m[2][1] * other._m[1][2] + _m[2][2] * other._m[2][2] + _m[2][3] * other._m[3][2] - , _m[2][0] * other._m[0][3] + _m[2][1] * other._m[1][3] + _m[2][2] * other._m[2][3] + _m[2][3] * other._m[3][3] - , _m[3][0] * other._m[0][0] + _m[3][1] * other._m[1][0] + _m[3][2] * other._m[2][0] + _m[3][3] * other._m[3][0] - , _m[3][0] * other._m[0][1] + _m[3][1] * other._m[1][1] + _m[3][2] * other._m[2][1] + _m[3][3] * other._m[3][1] - , _m[3][0] * other._m[0][2] + _m[3][1] * other._m[1][2] + _m[3][2] * other._m[2][2] + _m[3][3] * other._m[3][2] - , _m[3][0] * other._m[0][3] + _m[3][1] * other._m[1][3] + _m[3][2] * other._m[2][3] + _m[3][3] * other._m[3][3] - }; - } - - std::vector matrix_4x4::operator* (std::vector points) const - { - auto adjustedPoints = std::vector(); - - for(auto const &point : points) - { - adjustedPoints.push_back(*this * point); - } - - return adjustedPoints; - } - - namespace - { - float minor_size (matrix_4x4 const& mat, std::size_t x, std::size_t y) - { - float s[3][3]; - for (std::size_t j (0), v (0); j < 4; ++j) - { - if (j != y) - { - for (std::size_t i (0), u (0); i < 4; ++i) - { - if (i != x) - { - s[v][u++] = mat (j, i); - } - } - ++v; - } - } -#define SUB(a,b) (s[1][a] * s[2][b] - s[2][a] * s[1][b]) - return s[0][0] * SUB (1,2) - s[0][1] * SUB (0,2) + s[0][2] * SUB (0,1); -#undef SUB - } - } - - matrix_4x4 matrix_4x4::adjoint() const - { - return { minor_size (*this, 0, 0), -minor_size (*this, 0, 1), minor_size (*this, 0, 2), -minor_size (*this, 0, 3) - , -minor_size (*this, 1, 0), minor_size (*this, 1, 1), -minor_size (*this, 1, 2), minor_size (*this, 1, 3) - , minor_size (*this, 2, 0), -minor_size (*this, 2, 1), minor_size (*this, 2, 2), -minor_size (*this, 2, 3) - , -minor_size (*this, 3, 0), minor_size (*this, 3, 1), -minor_size (*this, 3, 2), minor_size (*this, 3, 3) - }; - } - - matrix_4x4& matrix_4x4::operator* (float f) - { - for (std::size_t i (0); i < 16; ++i) - { - _data[i] *= f; - } - return *this; - } - matrix_4x4& matrix_4x4::operator/ (float f) - { - return *this * (1 / f); - } - - namespace - { - float determinant (matrix_4x4 const& mat) - { -#define SUB(a, b) (mat (2, a) * mat (3, b) - mat (3, a) * mat (2, b)) - return mat (0, 0) * (mat (1, 1) * SUB (2, 3) - mat (1, 2) * SUB (1, 3) + mat (1, 3) * SUB (1, 2)) - - mat (0, 1) * (mat (1, 0) * SUB (2, 3) - mat (1, 2) * SUB (0, 3) + mat (1, 3) * SUB (0, 2)) - + mat (0, 2) * (mat (1, 0) * SUB (1, 3) - mat (1, 1) * SUB (0, 3) + mat (1, 3) * SUB (0, 1)) - - mat (0, 3) * (mat (1, 0) * SUB (1, 2) - mat (1, 1) * SUB (0, 2) + mat (1, 2) * SUB (0, 1)); -#undef SUB - } - } - - matrix_4x4 matrix_4x4::inverted() const - { - return adjoint() / determinant (*this); - } - - glm::mat4x4 matrix_4x4::Convert() const - { - return { _m[0][0], _m[1][0], _m[2][0], _m[3][0] - , _m[0][1], _m[1][1], _m[2][1], _m[3][1] - , _m[0][2], _m[1][2], _m[2][2], _m[3][2] - , _m[0][3], _m[1][3], _m[2][3], _m[3][3] - }; - } - - glm::mat4x4 matrix_4x4::ConvertX() const - { - return { _m[0][0] , _m[0][1] , _m[0][2] , _m[0][3], - _m[1][0] , _m[1][1] , _m[1][2] , _m[1][3] , - _m[2][0] , _m[2][1] , _m[2][2] , _m[2][3] , - _m[3][0] , _m[3][1] , _m[3][2] , _m[3][3] - }; - } - - matrix_4x4 matrix_4x4::transposed() const - { - return { _m[0][0], _m[1][0], _m[2][0], _m[3][0] - , _m[0][1], _m[1][1], _m[2][1], _m[3][1] - , _m[0][2], _m[1][2], _m[2][2], _m[3][2] - , _m[0][3], _m[1][3], _m[2][3], _m[3][3] - }; - } -} diff --git a/src/math/matrix_4x4.hpp b/src/math/matrix_4x4.hpp deleted file mode 100644 index 966f9c5b..00000000 --- a/src/math/matrix_4x4.hpp +++ /dev/null @@ -1,140 +0,0 @@ -// This file is part of Noggit3, licensed under GNU General Public License (version 3). - -#pragma once -#include -#include -#include -#include - -namespace math -{ - struct vector_3d; - - struct matrix_4x4 - { - public: - matrix_4x4 () {} - - static struct uninitialized_t {} uninitialized; - matrix_4x4 (uninitialized_t) {} - - static struct zero_t {} zero; - matrix_4x4 (zero_t) - { - std::fill (_data, _data + 16, 0.f); - } - - static struct unit_t {} unit; - matrix_4x4 (unit_t) : matrix_4x4 (zero) - { - _m[0][0] = _m[1][1] = _m[2][2] = _m[3][3] = 1.0f; - } - - matrix_4x4 ( float m00, float m01, float m02, float m03 - , float m10, float m11, float m12, float m13 - , float m20, float m21, float m22, float m23 - , float m30, float m31, float m32, float m33 - ) - { - _m[0][0] = m00; _m[0][1] = m01; _m[0][2] = m02; _m[0][3] = m03; - _m[1][0] = m10; _m[1][1] = m11; _m[1][2] = m12; _m[1][3] = m13; - _m[2][0] = m20; _m[2][1] = m21; _m[2][2] = m22; _m[2][3] = m23; - _m[3][0] = m30; _m[3][1] = m31; _m[3][2] = m32; _m[3][3] = m33; - } - - static struct translation_t {} translation; - matrix_4x4 (translation_t, glm::vec3 const& tr) - : matrix_4x4 ( 1.0f, 0.0f, 0.0f, tr.x - , 0.0f, 1.0f, 0.0f, tr.y - , 0.0f, 0.0f, 1.0f, tr.z - , 0.0f, 0.0f, 0.0f, 1.0f - ) - {} - - static struct scale_t {} scale; - matrix_4x4 (scale_t, glm::vec3 const& sc) - : matrix_4x4 ( sc.x, 0.0f, 0.0f, 0.0f - , 0.0f, sc.y, 0.0f, 0.0f - , 0.0f, 0.0f, sc.z, 0.0f - , 0.0f, 0.0f, 0.0f, 1.0f - ) - {} - matrix_4x4 (scale_t, float sc) - : matrix_4x4 (scale, {sc, sc, sc}) - {} - - static struct rotation_t {} rotation; - matrix_4x4 (rotation_t, glm::quat const& q); - - static struct rotation_xyz_t {} rotation_xyz; - matrix_4x4 (rotation_xyz_t, degrees::vec3 const&); - static struct rotation_yzx_t {} rotation_yzx; - matrix_4x4 (rotation_yzx_t, degrees::vec3 const&); - - static struct rotation_yxz_t {} rotation_yxz; - matrix_4x4(rotation_yxz_t, degrees::vec3 const&); - - float operator() (std::size_t const& j, std::size_t const& i) const - { - return _m[j][i]; - } - float operator() (std::size_t const& j, std::size_t const& i, float value) - { - return _m[j][i] = value; - } - - glm::vec3 operator* (glm::vec3 const&) const; - glm::vec4 operator* (glm::vec4 const&) const; - matrix_4x4 operator* (matrix_4x4 const&) const; - std::vector operator*(std::vector points) const; - - matrix_4x4& operator* (float); - matrix_4x4& operator/ (float); - - matrix_4x4 adjoint() const; - matrix_4x4 inverted() const; - matrix_4x4 transposed() const; - glm::mat4x4 Convert() const; - glm::mat4x4 ConvertX() const; - - inline matrix_4x4& operator*= (matrix_4x4 const& p) - { - return *this = operator* (p); - } - - inline operator float*() - { - return _data; - } - inline operator const float*() const - { - return _data; - } - - template - glm::vec4 column() const - { - return {_m[0][i], _m[1][i], _m[2][i], _m[3][i]}; - } - - bool operator== (matrix_4x4 const& rhs) - { - for (std::size_t i (0); i < 4; ++i) - for (std::size_t j (0); j < 4; ++j) - { - if (_m[i][j] != rhs._m[i][j]) - { - return false; - } - } - - return true; - } - - union - { - float _m[4][4]; - float _data[16]; - }; - }; -} diff --git a/src/math/ray.hpp b/src/math/ray.hpp index ca3da67d..2c556d4d 100644 --- a/src/math/ray.hpp +++ b/src/math/ray.hpp @@ -1,6 +1,6 @@ // This file is part of Noggit3, licensed under GNU General Public License (version 3). #pragma once -#include +#include #include namespace math diff --git a/src/noggit/Model.h b/src/noggit/Model.h index cf011d43..6038094e 100644 --- a/src/noggit/Model.h +++ b/src/noggit/Model.h @@ -3,7 +3,7 @@ #pragma once #include -#include +#include #include #include // Animation::M2Value #include // AsyncObject diff --git a/src/noggit/Red/AssetBrowser/ModelView.hpp b/src/noggit/Red/AssetBrowser/ModelView.hpp index b5c3bd2e..08f06fd1 100644 --- a/src/noggit/Red/AssetBrowser/ModelView.hpp +++ b/src/noggit/Red/AssetBrowser/ModelView.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/src/noggit/Red/PreviewRenderer/PreviewRenderer.hpp b/src/noggit/Red/PreviewRenderer/PreviewRenderer.hpp index bfae3021..93749418 100644 --- a/src/noggit/Red/PreviewRenderer/PreviewRenderer.hpp +++ b/src/noggit/Red/PreviewRenderer/PreviewRenderer.hpp @@ -1,7 +1,6 @@ #ifndef NOGGIT_PREVIEWRENDERER_HPP #define NOGGIT_PREVIEWRENDERER_HPP -#include #include #include #include diff --git a/src/noggit/Red/ViewportGizmo/ViewportGizmo.hpp b/src/noggit/Red/ViewportGizmo/ViewportGizmo.hpp index 33f309d5..75bcf87f 100644 --- a/src/noggit/Red/ViewportGizmo/ViewportGizmo.hpp +++ b/src/noggit/Red/ViewportGizmo/ViewportGizmo.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include diff --git a/src/noggit/SceneObject.hpp b/src/noggit/SceneObject.hpp index 6fc2cdc5..b41db6af 100644 --- a/src/noggit/SceneObject.hpp +++ b/src/noggit/SceneObject.hpp @@ -3,7 +3,7 @@ #ifndef NOGGIT_3DOBJECT_HPP #define NOGGIT_3DOBJECT_HPP -#include +#include #include #include #include diff --git a/src/noggit/camera.hpp b/src/noggit/camera.hpp index 2335d4fb..6a973f6c 100644 --- a/src/noggit/camera.hpp +++ b/src/noggit/camera.hpp @@ -1,8 +1,8 @@ // This file is part of Noggit3, licensed under GNU General Public License (version 3). #pragma once - -#include +#include +#include "math/trig.hpp" namespace noggit { diff --git a/src/noggit/cursor_render.cpp b/src/noggit/cursor_render.cpp index 97df6997..296089f1 100644 --- a/src/noggit/cursor_render.cpp +++ b/src/noggit/cursor_render.cpp @@ -1,7 +1,7 @@ // This file is part of Noggit3, licensed under GNU General Public License (version 3). #include - +#include "math/trig.hpp" #include namespace noggit diff --git a/src/noggit/cursor_render.hpp b/src/noggit/cursor_render.hpp index ed4c1234..8041b5dc 100644 --- a/src/noggit/cursor_render.hpp +++ b/src/noggit/cursor_render.hpp @@ -1,7 +1,6 @@ // This file is part of Noggit3, licensed under GNU General Public License (version 3). #pragma once -#include #include #include diff --git a/src/opengl/types.hpp b/src/opengl/types.hpp index c55aa8c2..f664e312 100644 --- a/src/opengl/types.hpp +++ b/src/opengl/types.hpp @@ -3,7 +3,7 @@ #pragma once #include -#include +#include #include #include