| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //
- // matrix.cxx
- // graphics
- //
- // Created by Sam Jaffe on 5/24/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #include "matrix.hpp"
- #include "game/math/angle.hpp"
- #include "matrix/matrix.hpp"
- namespace graphics {
- math::matr4 orthogonal_view(float left, float right, float bottom, float top,
- float near, float far) {
- math::matr4 matrix;
- matrix(0, 0) = 2.f / (right - left);
- matrix(1, 1) = 2.f / (top - bottom);
- matrix(2, 2) = -2.f / (far - near);
- matrix(0, 3) = -(right + left) / (right - left);
- matrix(1, 3) = -(top + bottom) / (top - bottom);
- matrix(2, 3) = -(far + near) / (far - near);
- matrix(3, 3) = 1.f;
- return matrix;
- }
- math::matr4 frustum_view(float left, float right, float bottom, float top,
- float near, float far) {
- math::matr4 matrix;
- matrix(0, 0) = 2.f * near / (right - left);
- matrix(1, 1) = 2.f * near / (top - bottom);
- matrix(2, 0) = (right + left) / (right - left);
- matrix(2, 1) = (top + bottom) / (top - bottom);
- matrix(2, 2) = -(far + near) / (far - near);
- matrix(2, 3) = -1.f;
- matrix(3, 2) = -(2.f * far * near) / (far - near);
- matrix(3, 3) = 0.f;
- return matrix;
- }
- math::matr4 perspective(math::degree fovY, float aspect, float front,
- float back) {
- float tangent = tan(fovY);
- float height = front * tangent;
- float width = height * aspect;
- return frustum_view(-width, width, -height, height, front, back);
- }
- }
|