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

31 lines
1.2 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),
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-06 19:36:43 +02:00
Matrix4 projectionMatrix = glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), nearPlane, farPlane);
2025-04-13 14:41:42 +02:00
return correctionMatrix * projectionMatrix;
2024-06-09 12:20:04 +02:00
} else {
2025-05-07 16:08:12 +02:00
return correctionMatrix * glm::ortho(orthoLeft, orthoRight, orthoTop, orthoBottom, farPlane, nearPlane);
2024-06-09 12:20:04 +02:00
}
2023-11-16 22:58:47 +01:00
}