Files
Seele/src/Engine/Math/Matrix.h
T

68 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <glm/mat2x2.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat4x4.hpp>
2024-06-09 12:20:04 +02:00
namespace Seele {
2020-04-12 15:47:19 +02:00
typedef glm::mat2 Matrix2;
typedef glm::mat3 Matrix3;
typedef glm::mat4 Matrix4;
2025-08-14 11:06:43 +02:00
static Matrix4 perspectiveProjection(float fov, float aspect, float nearPlane, float farPlane) {
const float e = 1.0f / std::tan(fov * 0.5f);
return {
{
e / aspect,
0.0f,
0.0f,
0.0f,
},
{
0.0f,
-e,
0.0f,
0.0f,
},
{
0.0f,
0.0f,
2025-08-23 18:09:01 +02:00
nearPlane / (nearPlane - farPlane),
2025-08-14 11:06:43 +02:00
-1.0f,
},
{
0.0f,
0.0f,
(farPlane * nearPlane) / (nearPlane - farPlane),
0.0f,
},
};
}
static Matrix4 orthographicProjection(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
return Matrix4{
{
2.0f / (right - left),
0.0f,
0.0f,
0.0f,
},
{
0.0f,
2.0f / (top - bottom),
0.0f,
0.0f,
},
{
0.0f,
0.0f,
2025-08-23 18:09:01 +02:00
-2.0f / (nearPlane - farPlane),
2025-08-14 11:06:43 +02:00
0.0f,
},
{
-(right + left) / (right - left),
-(top + bottom) / (top - bottom),
2025-08-23 18:09:01 +02:00
-(nearPlane + farPlane) / (nearPlane - farPlane),
2025-08-14 11:06:43 +02:00
1.0f,
},
};
}
2020-04-12 15:47:19 +02:00
} // namespace Seele