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

88 lines
2.1 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
{
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetViewportSize(unsigned int width, unsigned int height)
{
m_aspect_ratio = width / (float)height;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetProjectionType(ProjectionType projectionType)
{
m_projection_type = projectionType;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetOrthographicSize(float size)
{
m_orthographic_specification.size = size;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetOrthographicFarPlane(float farPlane)
{
m_orthographic_specification.farPlane = farPlane;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetOrthographicNearPlane(float nearPlane)
{
m_orthographic_specification.nearPlane = nearPlane;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetPerspectiveVerticalFOV(float verticalFOV)
{
m_perspective_specification.verticalFOV = verticalFOV;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetPerspectiveFarPlane(float farPlane)
{
m_perspective_specification.farPlane = farPlane;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
2022-03-08 21:19:19 +03:30
void SceneCamera::SetPerspectiveNearPlane(float nearPlane)
{
m_perspective_specification.nearPlane = nearPlane;
2022-03-08 21:19:19 +03:30
CalculateProjection();
}
void SceneCamera::CalculateProjection()
{
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,
m_orthographic_specification.farPlane,
m_orthographic_specification.nearPlane
2025-07-05 13:28:41 +03:30
);
}
2022-03-08 21:19:19 +03:30
else // perspective
{
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
);
}
2022-03-08 21:19:19 +03:30
}
2025-07-05 13:28:41 +03:30
} // namespace Light