diff options
| author | Mel <einebeere@gmail.com> | 2022-10-05 18:27:19 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-05 18:27:19 +0200 |
| commit | f66811b772c81fc182e353308b1c1a3667201e9b (patch) | |
| tree | cae289545b06c032060508352ae2ffc53daea9ed /src/Math/MVP.cpp | |
| parent | 0631fb666d2a28a6eb9b8d1578675699b41a5de6 (diff) | |
| download | meowcraft-f66811b772c81fc182e353308b1c1a3667201e9b.tar.zst meowcraft-f66811b772c81fc182e353308b1c1a3667201e9b.zip | |
Non-camera relative movement
Diffstat (limited to 'src/Math/MVP.cpp')
| -rw-r--r-- | src/Math/MVP.cpp | 51 |
1 files changed, 5 insertions, 46 deletions
diff --git a/src/Math/MVP.cpp b/src/Math/MVP.cpp index 37675b4..146b208 100644 --- a/src/Math/MVP.cpp +++ b/src/Math/MVP.cpp @@ -1,62 +1,21 @@ #include <cmath> -#include <glm/glm.hpp> -#include <glm/gtc/matrix_transform.hpp> -#include <glm/gtc/type_ptr.hpp> -#include <glm/gtx/string_cast.hpp> #include "MVP.hpp" #include "Math.hpp" namespace Math::MVP { -Matrix<4, 4> transformation_matrix(Vector<3> position) { - return { - 1.0f, 0.0f, 0.0f, position.x(), - 0.0f, 1.0f, 0.0f, position.y(), - 0.0f, 0.0f, 1.0f, position.z(), - 0.0f, 0.0f, 0.0f, 1.0f - }; -} - -Matrix<4, 4> rotation_matrix(Rotation angles) { - auto c = angles.vector.apply(cos); - auto s = angles.vector.apply(sin); - - Matrix<4, 4> rotation_x{ - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, c.x(), -s.x(), 0.0f, - 0.0f, s.x(), c.x(), 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f, - }; - - Matrix<4, 4> rotation_y{ - c.y(), 0.0f, s.y(), 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - -s.y(), 0.0f, c.y(), 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f, - }; - - Matrix<4, 4> rotation_z{ - c.z(), -s.z(), 0.0f, 0.0f, - s.z(), c.z(), 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f, - }; - - return rotation_x * rotation_y * rotation_z; -} - Matrix<4, 4> model(Vector<3> position, Rotation angles) { - auto transformation = transformation_matrix(position); - auto rotation = rotation_matrix(angles); + auto transformation = Matrix<4, 4>::transformation(position); + auto rotation = Matrix<4, 4>::rotation(angles); return transformation * rotation; } Matrix<4, 4> view(Vector<3> position, Rotation angles) { - auto transformation = transformation_matrix(position); - auto rotation = rotation_matrix(angles); + auto rotation = Matrix<4, 4>::rotation(angles); + auto transformation = Matrix<4, 4>::transformation(-position); - return transformation * rotation; + return rotation * transformation; } Matrix<4, 4> projection(float aspect, float fov, float near, float far) { |
