Just making tiny improvements to things.

This commit is contained in:
2023-01-07 14:35:54 -08:00
parent d6b7895cab
commit 19f688afe1
33 changed files with 312 additions and 153 deletions

View File

@ -9,6 +9,7 @@
#include "scene/components/display/MeshHost.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/Material.hpp"
#include "scene/components/display/PixelPerfectCamera.hpp"
#include "scene/components/display/TiledSprite.hpp"
#include "scene/components/example/ExampleSpin.hpp"

View File

@ -11,5 +11,6 @@ target_sources(${DAWN_TARGET_NAME}
Material.cpp
MeshHost.cpp
MeshRenderer.cpp
PixelPerfectCamera.cpp
TiledSprite.cpp
)

View File

@ -0,0 +1,64 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PixelPerfectCamera.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) : SceneItemComponent(i) {
}
std::vector<SceneItemComponent*> PixelPerfectCamera::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->camera = this->item->getComponent<Camera>())
};
}
void PixelPerfectCamera::onRenderTargetResized(
RenderTarget *t, float_t w, float_t h
) {
this->updateDimensions();
}
void PixelPerfectCamera::updateDimensions() {
float_t w, h;
assertNotNull(this->camera);
auto target = this->camera->getRenderTarget();
switch(this->camera->type) {
case CAMERA_TYPE_ORTHONOGRAPHIC:
w = target->getWidth() / 2.0f / this->scale;
h = target->getHeight() / 2.0f / this->scale;
camera->orthoLeft = -w;
camera->orthoRight = w;
camera->orthoTop = h;
camera->orthoBottom = -h;
camera->updateProjection();
break;
case CAMERA_TYPE_PERSPECTIVE:
assertDeprecated();
break;
default:
assertUnreachable();
}
}
void PixelPerfectCamera::onStart() {
assertNotNull(this->camera);
this->updateDimensions();
camera->getRenderTarget()->eventRenderTargetResized
.addListener(this, &PixelPerfectCamera::onRenderTargetResized)
;
}
PixelPerfectCamera::~PixelPerfectCamera() {
camera->getRenderTarget()->eventRenderTargetResized
.removeListener(this, &PixelPerfectCamera::onRenderTargetResized)
;
}

View File

@ -0,0 +1,36 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Camera.hpp"
namespace Dawn {
class PixelPerfectCamera : public SceneItemComponent {
protected:
Camera *camera = nullptr;
/** Event for when the render target is resized. */
void onRenderTargetResized(RenderTarget *target, float_t w, float_t h);
/**
* Updates the underlying camera's projection information.
*/
void updateDimensions();
public:
float_t scale = 4.0f;
/**
* Create a new PixelPerfectCamera Component.
*
* @param item Item that this component belongs to.
*/
PixelPerfectCamera(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override;
void onStart() override;
~PixelPerfectCamera();
};
}