Files
Seele/src/Engine/Graphics/Window.cpp
T

56 lines
1.8 KiB
C++
Raw Normal View History

2023-11-16 22:58:47 +01:00
#include "Window.h"
using namespace Seele;
using namespace Seele::Gfx;
2024-06-09 12:20:04 +02:00
Window::Window() {}
2023-11-16 22:58:47 +01:00
2024-06-09 12:20:04 +02:00
Window::~Window() {}
2023-11-16 22:58:47 +01:00
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo)
2025-04-04 14:44:53 +02:00
: sizeX(viewportInfo.dimensions.size.x), sizeY(viewportInfo.dimensions.size.y), offsetX(viewportInfo.dimensions.offset.x),
2025-05-06 19:36:43 +02:00
offsetY(viewportInfo.dimensions.offset.y), fieldOfView(viewportInfo.fieldOfView), orthoLeft(viewportInfo.left),
2025-05-10 22:52:46 +02:00
orthoRight(viewportInfo.right), orthoTop(viewportInfo.top), orthoBottom(viewportInfo.bottom), owner(owner) {
2025-04-06 09:57:47 +02:00
if (owner != nullptr) {
sizeX = std::min(owner->getFramebufferWidth(), sizeX);
sizeY = std::min(owner->getFramebufferHeight(), sizeY);
}
}
2023-11-16 22:58:47 +01:00
2024-06-09 12:20:04 +02:00
Viewport::~Viewport() {}
2023-11-16 22:58:47 +01:00
2025-05-06 19:36:43 +02:00
Matrix4 Viewport::getProjectionMatrix(float nearPlane, float farPlane) const {
2025-05-07 16:08:12 +02:00
Matrix4 correctionMatrix = Matrix4(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1 / 2.f, 0, 0, 0, 1 / 2.f, 1);
2024-06-09 12:20:04 +02:00
if (fieldOfView > 0.0f) {
2025-05-10 22:52:46 +02:00
const float aspect = static_cast<float>(sizeX) / sizeY;
const float e = 1.0f / std::tan(fieldOfView * 0.5f);
return {
{
e / aspect,
0.0f,
0.0f,
0.0f,
},
{
0.0f,
-e,
0.0f,
0.0f,
},
{
0.0f,
0.0f,
0.5f * (farPlane + nearPlane) / (nearPlane - farPlane),
-1.0f,
},
{
0.0f,
0.0f,
(farPlane * nearPlane) / (nearPlane - farPlane),
0.0f,
},
};
2024-06-09 12:20:04 +02:00
} else {
2025-05-09 23:05:47 +02:00
return correctionMatrix * glm::ortho(orthoLeft, orthoRight, orthoBottom, orthoTop, nearPlane, farPlane);
2024-06-09 12:20:04 +02:00
}
2023-11-16 22:58:47 +01:00
}