light/modules/camera/private/scene.cpp

84 lines
2.1 KiB
C++
Raw Normal View History

#include <camera/scene.hpp>
#include <math/algebra.hpp>
#include <math/trig.hpp>
2025-07-11 00:05:48 +03:30
namespace lt {
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 = math::radians(45.0f),
2025-07-07 15:13:05 +03:30
.near_plane = 0.01f,
.far_plane = 10000.0f }
, m_aspect_ratio(16.0f / 9.0f)
2025-07-07 15:13:05 +03:30
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
{
2025-07-07 15:13:05 +03:30
m_aspect_ratio = static_cast<float>(width) / static_cast<float>(height);
calculate_projection();
2022-03-08 21:19:19 +03: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;
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
}
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;
calculate_projection();
2022-03-08 21:19:19 +03: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;
calculate_projection();
2022-03-08 21:19:19 +03: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;
calculate_projection();
2022-03-08 21:19:19 +03: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;
calculate_projection();
2022-03-08 21:19:19 +03: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;
calculate_projection();
2022-03-08 21:19:19 +03:30
}
void SceneCamera::calculate_projection()
2022-03-08 21:19:19 +03:30
{
// TODO(Light): implement ortho perspective
if (m_projection_type == ProjectionType::Orthographic)
{
// throw std::runtime_error { "ortho perspective not supported yet" };
}
// defaults to perspective for now...
m_projection = math::perspective(
m_perspective_specification.vertical_fov,
m_aspect_ratio,
m_perspective_specification.near_plane,
m_perspective_specification.far_plane
);
2022-03-08 21:19:19 +03:30
}
2025-07-11 00:05:48 +03:30
} // namespace lt