New scene items system
This commit is contained in:
12
src/dawn/component/CMakeLists.txt
Normal file
12
src/dawn/component/CMakeLists.txt
Normal 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)
|
9
src/dawn/component/display/CMakeLists.txt
Normal file
9
src/dawn/component/display/CMakeLists.txt
Normal 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
|
||||
)
|
37
src/dawn/component/display/Camera.cpp
Normal file
37
src/dawn/component/display/Camera.cpp
Normal 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);
|
||||
}
|
48
src/dawn/component/display/Camera.hpp
Normal file
48
src/dawn/component/display/Camera.hpp
Normal 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();
|
||||
};
|
||||
}
|
16
src/dawn/component/display/MeshRenderer.hpp
Normal file
16
src/dawn/component/display/MeshRenderer.hpp
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user