New scene items system

This commit is contained in:
2023-11-15 18:56:25 -06:00
parent cda4576a05
commit c544d784a7
38 changed files with 1309 additions and 36 deletions

View File

@ -0,0 +1,12 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# target_sources(${DAWN_TARGET_NAME}
# PRIVATE
# Game.cpp
# )
# Subdirs
add_subdirectory(display)

View File

@ -0,0 +1,9 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Camera.cpp
)

View File

@ -0,0 +1,37 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Camera.hpp"
using namespace Dawn;
void Camera::onInit() {
std::cout << "Camera" << std::endl;
}
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);
}

View File

@ -0,0 +1,48 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItem.hpp"
namespace Dawn {
enum CameraType {
PERSPECTIVE,
ORTHOGONAL
};
class Camera : public SceneComponent {
public:
float_t clipNear = 0.01f;
float_t clipFar = 1000.0f;
enum CameraType type = CameraType::PERSPECTIVE;
float_t fov = 0.785398f;
float_t orthoLeft = -1.0f;
float_t orthoRight = 1.0f;
float_t orthoBottom = -1.0f;
float_t orthoTop = 1.0f;
// std::shared_ptr<RenderTarget> renderTarget;
void onInit() override;
/**
* Returns the aspect ratio that the camera is using. In future I may
* allow you to specify a custom ratio for stylistic reasons but for now I
* just take the ratio of the specific frame buffer.
*
* @return The aspect ratio as a ratio of w/h.
*/
float_t getAspect();
/**
* Returns the projection matrix for this camera.
*
* @return Projection matrix.
*/
glm::mat4 getProjection();
};
}

View File

@ -0,0 +1,16 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItem.hpp"
namespace Dawn {
class MeshRenderer : public SceneComponent {
public:
std::shared_ptr<Mesh> mesh;
void onInit() override;
};
}