refactor: remove ortho camera & move camera component to camera module
This commit is contained in:
parent
10d4a523eb
commit
eca1bc91e6
9 changed files with 9 additions and 111 deletions
|
@ -1,3 +1,3 @@
|
||||||
add_library_module(camera camera.cpp ortho.cpp scene.cpp)
|
add_library_module(camera camera.cpp scene.cpp)
|
||||||
|
|
||||||
target_link_libraries(camera PUBLIC glm::glm)
|
target_link_libraries(camera PUBLIC glm::glm)
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class OrthographicCamera
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OrthographicCamera(
|
|
||||||
const glm::vec2 &position,
|
|
||||||
float aspectRatio,
|
|
||||||
float zoomLevel,
|
|
||||||
const glm::vec4 &clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f)
|
|
||||||
);
|
|
||||||
|
|
||||||
void calculate_view();
|
|
||||||
|
|
||||||
void calculate_projection();
|
|
||||||
|
|
||||||
void on_resize(const glm::vec2 &size);
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_view() const -> const glm::mat4 &
|
|
||||||
{
|
|
||||||
return m_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_projection() const -> const glm::mat4 &
|
|
||||||
{
|
|
||||||
return m_projection;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_clear_color() const -> const glm::vec4 &
|
|
||||||
{
|
|
||||||
return m_clear_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void move(const glm::vec2 &position);
|
|
||||||
|
|
||||||
private:
|
|
||||||
glm::vec2 m_position;
|
|
||||||
|
|
||||||
float m_aspect_ratio;
|
|
||||||
|
|
||||||
float m_zoom_level;
|
|
||||||
|
|
||||||
const glm::vec3 m_up;
|
|
||||||
|
|
||||||
glm::mat4 m_projection {};
|
|
||||||
|
|
||||||
glm::mat4 m_view {};
|
|
||||||
|
|
||||||
glm::vec4 m_clear_color;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Light
|
|
|
@ -1,49 +0,0 @@
|
||||||
#include <camera/ortho.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include <glm/matrix.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
OrthographicCamera::OrthographicCamera(
|
|
||||||
const glm::vec2 &position,
|
|
||||||
float aspect_ratio,
|
|
||||||
float zoom_level,
|
|
||||||
const glm::vec4 &clear_color /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */
|
|
||||||
)
|
|
||||||
: m_up(0.0f, 1.0f, 0.0f)
|
|
||||||
, m_position(position)
|
|
||||||
, m_aspect_ratio(aspect_ratio)
|
|
||||||
, m_zoom_level(zoom_level)
|
|
||||||
, m_clear_color(clear_color)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::calculate_view()
|
|
||||||
{
|
|
||||||
m_view = glm::lookAt(glm::vec3(m_position, 100.0f), glm::vec3(m_position, 0.0f), m_up);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::calculate_projection()
|
|
||||||
{
|
|
||||||
m_projection = glm::ortho(
|
|
||||||
-m_zoom_level * m_aspect_ratio,
|
|
||||||
+m_zoom_level * m_aspect_ratio,
|
|
||||||
-m_zoom_level,
|
|
||||||
+m_zoom_level,
|
|
||||||
FLT_MAX,
|
|
||||||
FLT_MIN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::on_resize(const glm::vec2 &size)
|
|
||||||
{
|
|
||||||
m_aspect_ratio = size.x / size.y;
|
|
||||||
calculate_projection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::move(const glm::vec2 &position)
|
|
||||||
{
|
|
||||||
m_position += position;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Light
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <engine/scene/components/camera.hpp>
|
|
||||||
#include <engine/scene/components/native_script.hpp>
|
#include <engine/scene/components/native_script.hpp>
|
||||||
#include <engine/scene/components/sprite_renderer.hpp>
|
#include <engine/scene/components/sprite_renderer.hpp>
|
||||||
#include <engine/scene/components/tag.hpp>
|
#include <engine/scene/components/tag.hpp>
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include <renderer/renderer.hpp>
|
#include <camera/component.hpp>
|
||||||
#include <engine/scene/components.hpp>
|
#include <engine/scene/components.hpp>
|
||||||
#include <engine/scene/entity.hpp>
|
#include <engine/scene/entity.hpp>
|
||||||
#include <engine/scene/scene.hpp>
|
#include <engine/scene/scene.hpp>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <renderer/renderer.hpp>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include <renderer/texture.hpp>
|
|
||||||
#include <engine/scene/components.hpp>
|
|
||||||
#include <asset_manager/asset_manager.hpp>
|
#include <asset_manager/asset_manager.hpp>
|
||||||
|
#include <camera/component.hpp>
|
||||||
|
#include <engine/scene/components.hpp>
|
||||||
#include <engine/utils/serializer.hpp>
|
#include <engine/utils/serializer.hpp>
|
||||||
|
#include <renderer/texture.hpp>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <asset_manager/asset_manager.hpp>
|
#include <asset_manager/asset_manager.hpp>
|
||||||
|
#include <camera/component.hpp>
|
||||||
#include <engine/utils/serializer.hpp>
|
#include <engine/utils/serializer.hpp>
|
||||||
#include <input/key_codes.hpp>
|
#include <input/key_codes.hpp>
|
||||||
#include <mirror/editor_layer.hpp>
|
#include <mirror/editor_layer.hpp>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <engine/scene/components.hpp>
|
|
||||||
#include <asset_manager/asset_manager.hpp>
|
#include <asset_manager/asset_manager.hpp>
|
||||||
|
#include <camera/component.hpp>
|
||||||
|
#include <engine/scene/components.hpp>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
Loading…
Add table
Reference in a new issue