light/modules/engine/src/camera/scene.cpp

88 lines
2.2 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#include <engine/camera/scene.hpp>
#include <glm/gtc/matrix_transform.hpp>
namespace Light {
2022-03-08 21:19:19 +03:30
SceneCamera::SceneCamera()
: 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
{
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_viewport_size(unsigned int width, unsigned int height)
2022-03-08 21:19:19 +03:30
{
m_aspect_ratio = width / (float)height;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_projection_type(ProjectionType projectionType)
2022-03-08 21:19:19 +03:30
{
m_projection_type = projectionType;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_orthographic_size(float size)
2022-03-08 21:19:19 +03:30
{
m_orthographic_specification.size = size;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_orthographic_far_plane(float farPlane)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
m_orthographic_specification.far_plane = farPlane;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_orthographic_near_plane(float nearPlane)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
m_orthographic_specification.near_plane = nearPlane;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_perspective_vertical_fov(float verticalFOV)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
m_perspective_specification.vertical_fov = verticalFOV;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_perspective_far_plane(float farPlane)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
m_perspective_specification.far_plane = farPlane;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::set_perspective_near_plane(float nearPlane)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
m_perspective_specification.near_plane = nearPlane;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::calculate_projection()
2022-03-08 21:19:19 +03:30
{
if (m_projection_type == ProjectionType::Orthographic)
{
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
);
}
2022-03-08 21:19:19 +03:30
else // perspective
{
m_projection = glm::perspective(
2025-07-06 14:02:50 +03:30
m_perspective_specification.vertical_fov,
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
);
}
2022-03-08 21:19:19 +03:30
}
2025-07-05 13:28:41 +03:30
} // namespace Light