#pragma once #include "Common.hpp" namespace Math::MVP { template Matrix<4, 4, T> model(Vector<3> position, Vector<3> size, Rotation angles) { auto transformation = Matrix<4, 4, T>::transformation(position); auto scale = Matrix<4, 4, T>::scale(size); auto rotation = Matrix<4, 4, T>::rotation(angles); return transformation * rotation * scale; } template Matrix<4, 4, T> view(Vector<3> position, Rotation angles) { auto rotation = Matrix<4, 4, T>::rotation(angles); auto transformation = Matrix<4, 4, T>::transformation(-position); return rotation * transformation; } template Matrix<4, 4, T> perspective_projection(Real aspect, Real fov, Real near, Real far) { auto fov_radians = radians(fov); Real x_scale = 1.0 / (tan(fov_radians / 2.0) * aspect); Real y_scale = 1.0 / tan(fov_radians / 2.0); Real frustum_length = far - near; Real z_near = -(far + near) / frustum_length; Real z_far = -(2 * far * near) / frustum_length; Matrix<4, 4, T> projection{ x_scale, 0.0f, 0.0f, 0.0f, 0.0f, y_scale, 0.0f, 0.0f, 0.0f, 0.0f, z_near, z_far, 0.0f, 0.0f, -1.0f, 0.0f, }; return projection; } template Matrix<4, 4, T> orthographic_projection(Real width, Real height, Real near, Real far) { Real x_scale = 2.0f / width; Real y_scale = 2.0f / -height; Real frustum_length = far - near; Real z_near = -(far + near) / frustum_length; Real z_far = -2 / frustum_length; Matrix<4, 4, T> 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; } }