diff options
Diffstat (limited to 'src/Math/MVP.cpp')
| -rw-r--r-- | src/Math/MVP.cpp | 20 |
1 files changed, 19 insertions, 1 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; +} + } |
