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-05 14:23:01 +03:30
|
|
|
: m_orthographic_specification { 1000.0f, -1.0f, 10000.0f }
|
|
|
|
, m_perspective_specification { glm::radians(45.0f), 0.01f, 10000.0f }
|
|
|
|
, m_aspect_ratio(16.0f / 9.0f)
|
|
|
|
, m_projection_type(ProjectionType::Orthographic)
|
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-05 14:23:01 +03:30
|
|
|
m_aspect_ratio = width / (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-05 15:36:53 +03:30
|
|
|
void SceneCamera::set_projection_type(ProjectionType projectionType)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_projection_type = projectionType;
|
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-05 15:36:53 +03:30
|
|
|
void SceneCamera::set_orthographic_far_plane(float farPlane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_orthographic_specification.farPlane = farPlane;
|
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_near_plane(float nearPlane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_orthographic_specification.nearPlane = nearPlane;
|
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_perspective_vertical_fov(float verticalFOV)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_perspective_specification.verticalFOV = verticalFOV;
|
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_perspective_far_plane(float farPlane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_perspective_specification.farPlane = farPlane;
|
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_perspective_near_plane(float nearPlane)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_perspective_specification.nearPlane = nearPlane;
|
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,
|
|
|
|
m_orthographic_specification.farPlane,
|
|
|
|
m_orthographic_specification.nearPlane
|
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(
|
|
|
|
m_perspective_specification.verticalFOV,
|
|
|
|
m_aspect_ratio,
|
|
|
|
m_perspective_specification.nearPlane,
|
|
|
|
m_perspective_specification.farPlane
|
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
|