Working on RenderTarget example
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
|
||||
#include "SceneItemComponent.hpp"
|
||||
#include "SceneItem.hpp"
|
||||
#include "Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -12,6 +14,14 @@ SceneItemComponent::SceneItemComponent(std::weak_ptr<SceneItem> item) {
|
||||
this->item = item;
|
||||
}
|
||||
|
||||
std::shared_ptr<Scene> SceneItemComponent::getScene() {
|
||||
return this->item.lock()->scene.lock();
|
||||
}
|
||||
|
||||
std::shared_ptr<DawnGame> SceneItemComponent::getGame() {
|
||||
return this->item.lock()->scene.lock()->game.lock();
|
||||
}
|
||||
|
||||
SceneItemComponent::~SceneItemComponent() {
|
||||
|
||||
}
|
@ -8,6 +8,8 @@
|
||||
|
||||
namespace Dawn {
|
||||
class SceneItem;
|
||||
class Scene;
|
||||
class DawnGame;
|
||||
|
||||
class SceneItemComponent {
|
||||
public:
|
||||
@ -17,6 +19,9 @@ namespace Dawn {
|
||||
|
||||
virtual void start() = 0;
|
||||
|
||||
std::shared_ptr<Scene> getScene();
|
||||
std::shared_ptr<DawnGame> getGame();
|
||||
|
||||
virtual ~SceneItemComponent();
|
||||
};
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Camera.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -34,8 +36,17 @@ void Camera::updateProjection() {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderTarget> Camera::getRenderTarget() {
|
||||
if(this->target == nullptr) {
|
||||
return this->getGame()->renderManager.getBackBuffer();
|
||||
}
|
||||
|
||||
return this->target;
|
||||
}
|
||||
|
||||
float_t Camera::getAspect() {
|
||||
return 16.0f / 9.0f;
|
||||
auto target = this->getRenderTarget();
|
||||
return target->getWidth() / target->getHeight();
|
||||
}
|
||||
|
||||
void Camera::start() {
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
@ -15,6 +16,7 @@ namespace Dawn {
|
||||
class Camera : public SceneItemComponent {
|
||||
public:
|
||||
glm::mat4 projection;
|
||||
std::shared_ptr<RenderTarget> target = nullptr;
|
||||
|
||||
// Perspective
|
||||
enum CameraType type = CAMERA_TYPE_PERSPECTIVE;
|
||||
@ -42,6 +44,8 @@ namespace Dawn {
|
||||
*/
|
||||
void updateProjection();
|
||||
|
||||
std::shared_ptr<RenderTarget> getRenderTarget();
|
||||
|
||||
/**
|
||||
* Returs the aspect ratio of the camera.
|
||||
*
|
||||
|
Reference in New Issue
Block a user