removing remain matrix4x4 includes and files

This commit is contained in:
Alister
2021-11-27 20:48:33 +00:00
parent 618d2f4e8d
commit a9d091329a
13 changed files with 8 additions and 392 deletions

View File

@@ -1,8 +1,7 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include <array>
namespace math

View File

@@ -1,239 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <math/matrix_4x4.hpp>
#include <cmath>
#include <cstring> // memcpy, memset
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>
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<axis a>
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<x>(degrees(angle.x));
*this *= rotate_axis<y>(degrees(angle.y));
*this *= rotate_axis<z>(degrees(angle.z));
}
matrix_4x4::matrix_4x4 (rotation_yzx_t, degrees::vec3 const& angle)
: matrix_4x4 (unit)
{
*this *= rotate_axis<y> (degrees(angle.y));
*this *= rotate_axis<z> (degrees(angle.z));
*this *= rotate_axis<x> (degrees(angle.x));
}
matrix_4x4::matrix_4x4(rotation_yxz_t, degrees::vec3 const& angle)
: matrix_4x4(unit)
{
*this *= rotate_axis<y>(degrees(angle.y));
*this *= rotate_axis<x>(degrees(angle.x));
*this *= rotate_axis<z>(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<glm::vec3> matrix_4x4::operator* (std::vector<glm::vec3> points) const
{
auto adjustedPoints = std::vector<glm::vec3>();
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]
};
}
}

View File

@@ -1,140 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <math/trig.hpp>
#include <algorithm>
#include <vector>
#include <glm/gtc/quaternion.hpp>
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<glm::vec3> operator*(std::vector<glm::vec3> 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<std::size_t i>
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];
};
};
}

View File

@@ -1,6 +1,6 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include <boost/optional/optional.hpp>
namespace math

View File

@@ -3,7 +3,7 @@
#pragma once
#include <math/frustum.hpp>
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include <math/ray.hpp>
#include <noggit/Animated.h> // Animation::M2Value
#include <noggit/AsyncObject.h> // AsyncObject

View File

@@ -12,7 +12,6 @@
#include <QElapsedTimer>
#include <QTimer>
#include <QStringList>
#include <math/matrix_4x4.hpp>
#include <noggit/camera.hpp>
#include <noggit/WMOInstance.h>
#include <noggit/Selection.h>

View File

@@ -1,7 +1,6 @@
#ifndef NOGGIT_PREVIEWRENDERER_HPP
#define NOGGIT_PREVIEWRENDERER_HPP
#include <math/matrix_4x4.hpp>
#include <noggit/camera.hpp>
#include <noggit/WMOInstance.h>
#include <noggit/ModelInstance.h>

View File

@@ -5,7 +5,6 @@
#include <external/qtimgui/imgui/imgui.h>
#include <external/imguizmo/ImGuizmo.h>
#include <noggit/Selection.h>
#include <math/matrix_4x4.hpp>
#include <noggit/World.h>

View File

@@ -3,7 +3,7 @@
#ifndef NOGGIT_3DOBJECT_HPP
#define NOGGIT_3DOBJECT_HPP
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include <math/ray.hpp>
#include <noggit/Selection.h>
#include <noggit/ContextObject.hpp>

View File

@@ -1,8 +1,8 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include "math/trig.hpp"
namespace noggit
{

View File

@@ -1,7 +1,7 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/cursor_render.hpp>
#include "math/trig.hpp"
#include <opengl/shader.hpp>
namespace noggit

View File

@@ -1,7 +1,6 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <math/matrix_4x4.hpp>
#include <opengl/scoped.hpp>
#include <opengl/shader.fwd.hpp>

View File

@@ -3,7 +3,7 @@
#pragma once
#include <QtGui/QOpenGLContext>
#include <math/matrix_4x4.hpp>
#include <glm/mat4x4.hpp>
#include <cstdint>
#include <array>