2023-11-17 00:02:04 -06:00

64 lines
1.4 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "assert/assert.hpp"
#include "Camera.hpp"
#include "game/Game.hpp"
using namespace Dawn;
void Camera::onInit() {
if(renderTarget == nullptr) {
this->setRenderTarget(
getGame()->renderHost.backBufferRenderTarget
);
}
}
void Camera::onDispose() {
renderTarget = nullptr;
}
std::shared_ptr<RenderTarget> Camera::getRenderTarget() {
return this->renderTarget;
}
glm::mat4 Camera::getProjection() {
switch(this->type) {
case CameraType::ORTHOGONAL:
return glm::ortho(
(float_t)this->orthoLeft,
(float_t)this->orthoRight,
(float_t)this->orthoBottom,
(float_t)this->orthoTop,
(float_t)this->clipNear,
(float_t)this->clipFar
);
case CameraType::PERSPECTIVE:
return glm::perspective(
(float_t)this->fov,
this->getAspect(),
(float_t)this->clipNear,
(float_t)this->clipFar
);
}
assertUnreachable("Invalid Camera Type!");
return glm::mat4(1.0f);
}
float_t Camera::getAspect() {
auto rt = this->getRenderTarget();
if(rt == nullptr) rt = getGame()->renderHost.getBackBufferRenderTarget();
return rt->getWidth() / rt->getHeight();
}
void Camera::setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) {
if(this->renderTarget != nullptr) {
}
this->renderTarget = renderTarget;
}