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 13:28:41 +03:30
|
|
|
: m_OrthographicSpecification { 1000.0f, -1.0f, 10000.0f }
|
|
|
|
, m_PerspectiveSpecification { glm::radians(45.0f), 0.01f, 10000.0f }
|
|
|
|
, m_AspectRatio(16.0f / 9.0f)
|
|
|
|
, m_ProjectionType(ProjectionType::Orthographic)
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-07-30 14:40:34 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetViewportSize(unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
m_AspectRatio = width / (float)height;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-07-30 14:40:34 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetProjectionType(ProjectionType projectionType)
|
|
|
|
{
|
|
|
|
m_ProjectionType = projectionType;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetOrthographicSize(float size)
|
|
|
|
{
|
|
|
|
m_OrthographicSpecification.size = size;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetOrthographicFarPlane(float farPlane)
|
|
|
|
{
|
|
|
|
m_OrthographicSpecification.farPlane = farPlane;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetOrthographicNearPlane(float nearPlane)
|
|
|
|
{
|
|
|
|
m_OrthographicSpecification.nearPlane = nearPlane;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetPerspectiveVerticalFOV(float verticalFOV)
|
|
|
|
{
|
|
|
|
m_PerspectiveSpecification.verticalFOV = verticalFOV;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetPerspectiveFarPlane(float farPlane)
|
|
|
|
{
|
|
|
|
m_PerspectiveSpecification.farPlane = farPlane;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
2021-08-02 12:18:00 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneCamera::SetPerspectiveNearPlane(float nearPlane)
|
|
|
|
{
|
|
|
|
m_PerspectiveSpecification.nearPlane = nearPlane;
|
|
|
|
CalculateProjection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneCamera::CalculateProjection()
|
|
|
|
{
|
|
|
|
if (m_ProjectionType == ProjectionType::Orthographic)
|
2021-08-02 12:18:00 +04:30
|
|
|
{
|
2025-07-05 13:28:41 +03:30
|
|
|
m_Projection = glm::ortho(
|
|
|
|
-m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
|
|
|
m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
|
|
|
-m_OrthographicSpecification.size * 0.5f,
|
|
|
|
m_OrthographicSpecification.size * 0.5f,
|
|
|
|
m_OrthographicSpecification.farPlane,
|
|
|
|
m_OrthographicSpecification.nearPlane
|
|
|
|
);
|
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 13:28:41 +03:30
|
|
|
m_Projection = glm::perspective(
|
|
|
|
m_PerspectiveSpecification.verticalFOV,
|
|
|
|
m_AspectRatio,
|
|
|
|
m_PerspectiveSpecification.nearPlane,
|
|
|
|
m_PerspectiveSpecification.farPlane
|
|
|
|
);
|
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
|