diff options
| author | Mel <einebeere@gmail.com> | 2022-10-26 04:05:47 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-26 04:05:47 +0200 |
| commit | e66f7011fb23e3509ad95accec581f6269813266 (patch) | |
| tree | 2535a617d10f76318dc4a3ae923258186fd9bac5 /src/Math | |
| parent | dc2af6a6fb7ae3cf1b9f917058889329d4652491 (diff) | |
| download | meowcraft-e66f7011fb23e3509ad95accec581f6269813266.tar.zst meowcraft-e66f7011fb23e3509ad95accec581f6269813266.zip | |
Fixed attribute double free
Diffstat (limited to 'src/Math')
| -rw-r--r-- | src/Math/MVP.cpp | 20 | ||||
| -rw-r--r-- | src/Math/MVP.hpp | 3 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/Math/MVP.cpp b/src/Math/MVP.cpp index de9f2ee..754c656 100644 --- a/src/Math/MVP.cpp +++ b/src/Math/MVP.cpp @@ -18,7 +18,7 @@ Matrix<4, 4> view(Vector<3> position, Rotation angles) { return rotation * transformation; } -Matrix<4, 4> projection(float aspect, float fov, float near, float far) { +Matrix<4, 4> perspective_projection(float aspect, float fov, float near, float far) { auto fov_radians = Math::radians(fov); float x_scale = 1.0f / (tan(fov_radians / 2.0f) * aspect); @@ -38,4 +38,22 @@ Matrix<4, 4> projection(float aspect, float fov, float near, float far) { return projection; } +Matrix<4, 4> orthographic_projection(float width, float height, float near, float far) { + float x_scale = 2.0f / width; + float y_scale = 2.0f / -height; + + float frustum_length = far - near; + float z_near = -(far + near) / frustum_length; + float z_far = -2 / frustum_length; + + Matrix<4, 4> projection{ + x_scale, 0.0f, 0.0f, -1.0f, + 0.0f, y_scale, 0.0f, 1.0f, + 0.0f, 0.0f, z_near, z_far, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + + return projection; +} + } diff --git a/src/Math/MVP.hpp b/src/Math/MVP.hpp index c3fb64f..0abad66 100644 --- a/src/Math/MVP.hpp +++ b/src/Math/MVP.hpp @@ -6,6 +6,7 @@ namespace Math::MVP { Matrix<4, 4> model(Vector<3> position, Rotation angles); Matrix<4, 4> view(Vector<3> position, Rotation angles); -Matrix<4, 4> projection(float aspect, float fov, float near, float far); +Matrix<4, 4> perspective_projection(float aspect, float fov, float near, float far); +Matrix<4, 4> orthographic_projection(float width, float height, float near, float far); } |
