2025-07-05 13:28:41 +03:30
|
|
|
#include <engine/camera/scene.hpp>
|
2021-07-30 14:40:34 +04:30
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
SceneCamera::SceneCamera()
|
2025-07-07 15:13:05 +03:30
|
|
|
: m_orthographic_specification { .size = 1000.0f, .near_plane = -1.0f, .far_plane = 10000.0f }
|
|
|
|
, m_perspective_specification { .vertical_fov = glm::radians(45.0f),
|
|
|
|
.near_plane = 0.01f,
|
|
|
|
.far_plane = 10000.0f }
|
2025-07-05 14:23:01 +03:30
|
|
|
, m_aspect_ratio(16.0f / 9.0f)
|
2025-07-07 15:13:05 +03:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-07-30 14:40:34 +04:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void SceneCamera::set_viewport_size(unsigned int width, unsigned int height)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_aspect_ratio = static_cast<float>(width) / static_cast<float>(height);
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-07-30 14:40:34 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_projection_type(ProjectionType projection_type)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_projection_type = projection_type;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void SceneCamera::set_orthographic_size(float size)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_orthographic_specification.size = size;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_orthographic_far_plane(float far_plane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_orthographic_specification.far_plane = far_plane;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_orthographic_near_plane(float near_plane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_orthographic_specification.near_plane = near_plane;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_perspective_vertical_fov(float vertical_fov)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_perspective_specification.vertical_fov = vertical_fov;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_perspective_far_plane(float far_plane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_perspective_specification.far_plane = far_plane;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
void SceneCamera::set_perspective_near_plane(float near_plane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
m_perspective_specification.near_plane = near_plane;
|
2025-07-05 15:36:53 +03:30
|
|
|
calculate_projection();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void SceneCamera::calculate_projection()
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
if (m_projection_type == ProjectionType::Orthographic)
|
2021-08-02 12:18:00 +04:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_projection = glm::ortho(
|
|
|
|
-m_orthographic_specification.size * 0.5f * m_aspect_ratio,
|
|
|
|
m_orthographic_specification.size * 0.5f * m_aspect_ratio,
|
|
|
|
-m_orthographic_specification.size * 0.5f,
|
|
|
|
m_orthographic_specification.size * 0.5f,
|
2025-07-06 14:02:50 +03:30
|
|
|
m_orthographic_specification.far_plane,
|
|
|
|
m_orthographic_specification.near_plane
|
2025-07-05 13:28:41 +03:30
|
|
|
);
|
2021-08-02 12:18:00 +04:30
|
|
|
}
|
2022-03-08 21:19:19 +03:30
|
|
|
else // perspective
|
2021-07-30 14:40:34 +04:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_projection = glm::perspective(
|
2025-07-06 14:02:50 +03:30
|
|
|
m_perspective_specification.vertical_fov,
|
2025-07-05 14:23:01 +03:30
|
|
|
m_aspect_ratio,
|
2025-07-06 14:02:50 +03:30
|
|
|
m_perspective_specification.near_plane,
|
|
|
|
m_perspective_specification.far_plane
|
2025-07-05 13:28:41 +03:30
|
|
|
);
|
2021-07-30 14:40:34 +04:30
|
|
|
}
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-07-30 14:40:34 +04:30
|
|
|
|
2025-07-05 13:28:41 +03:30
|
|
|
} // namespace Light
|