SceneCamera Properties
- PropertiesPanel now support SceneCamera component - Added perspective support to SceneCamera
This commit is contained in:
parent
54c195dae0
commit
06c728644f
4 changed files with 169 additions and 14 deletions
|
@ -6,10 +6,10 @@
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
SceneCamera::SceneCamera()
|
SceneCamera::SceneCamera()
|
||||||
: m_OrthoSize(1000.0f),
|
: m_OrthographicSpecification{ 10.0f, -1.0f, 10000.0f },
|
||||||
m_OrthoNearPlane(-1.0f),
|
m_PerspectiveSpecification{ glm::radians(45.0f), 0.01f, 10000.0f },
|
||||||
m_OrthoFarPlane(1.0f),
|
m_AspectRatio(16.0f / 9.0f),
|
||||||
m_AspectRatio(16.0f / 9.0f)
|
m_ProjectionType(ProjectionType::Orthographic)
|
||||||
{
|
{
|
||||||
CalculateProjection();
|
CalculateProjection();
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,66 @@ namespace Light {
|
||||||
CalculateProjection();
|
CalculateProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetProjectionType(ProjectionType projectionType)
|
||||||
|
{
|
||||||
|
m_ProjectionType = projectionType;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicSize(float size)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.size = size;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicFarPlane(float farPlane)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.farPlane = farPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicNearPlane(float nearPlane)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.nearPlane = nearPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveVerticalFOV(float verticalFOV)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.verticalFOV = verticalFOV;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveFarPlane(float farPlane)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.farPlane = farPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveNearPlane(float nearPlane)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.nearPlane = nearPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
void SceneCamera::CalculateProjection()
|
void SceneCamera::CalculateProjection()
|
||||||
{
|
{
|
||||||
m_Projection = glm::ortho(-m_OrthoSize * 0.5f * m_AspectRatio,
|
if(m_ProjectionType == ProjectionType::Orthographic)
|
||||||
m_OrthoSize * 0.5f * m_AspectRatio,
|
{
|
||||||
-m_OrthoSize * 0.5f,
|
m_Projection = glm::ortho(-m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
||||||
m_OrthoSize * 0.5f,
|
m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
||||||
m_OrthoFarPlane,
|
-m_OrthographicSpecification.size * 0.5f,
|
||||||
m_OrthoNearPlane);
|
m_OrthographicSpecification.size * 0.5f,
|
||||||
|
m_OrthographicSpecification.farPlane,
|
||||||
|
m_OrthographicSpecification.nearPlane);
|
||||||
|
}
|
||||||
|
else // perspective
|
||||||
|
{
|
||||||
|
m_Projection = glm::perspective(m_PerspectiveSpecification.verticalFOV,
|
||||||
|
m_AspectRatio,
|
||||||
|
m_PerspectiveSpecification.nearPlane,
|
||||||
|
m_PerspectiveSpecification.farPlane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -8,17 +8,56 @@ namespace Light {
|
||||||
|
|
||||||
class SceneCamera : public Camera
|
class SceneCamera : public Camera
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
float m_OrthoSize;
|
enum class ProjectionType
|
||||||
float m_OrthoNearPlane, m_OrthoFarPlane;
|
{
|
||||||
|
Orthographic = 0,
|
||||||
|
Perspetcive = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct OrthographicSpecification // :#todo use this
|
||||||
|
{
|
||||||
|
float size;
|
||||||
|
float nearPlane, farPlane;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PerspectiveSpecification
|
||||||
|
{
|
||||||
|
float verticalFOV;
|
||||||
|
float nearPlane, farPlane;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
OrthographicSpecification m_OrthographicSpecification;
|
||||||
|
PerspectiveSpecification m_PerspectiveSpecification;
|
||||||
float m_AspectRatio;
|
float m_AspectRatio;
|
||||||
|
|
||||||
|
ProjectionType m_ProjectionType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SceneCamera();
|
SceneCamera();
|
||||||
|
|
||||||
void SetViewportSize(unsigned int width, unsigned int height);
|
void SetViewportSize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
void SetProjectionType(ProjectionType projectionType);
|
||||||
|
|
||||||
|
void SetOrthographicSize(float size);
|
||||||
|
void SetOrthographicFarPlane(float farPlane);
|
||||||
|
void SetOrthographicNearPlane(float nearPlane);
|
||||||
|
|
||||||
|
void SetPerspectiveVerticalFOV(float verticalFov);
|
||||||
|
void SetPerspectiveFarPlane(float farPlane);
|
||||||
|
void SetPerspectiveNearPlane(float nearPlane);
|
||||||
|
|
||||||
|
inline float GetOrthographicSize() const { return m_OrthographicSpecification.size; }
|
||||||
|
inline float GetOrthographicFarPlane() const { return m_OrthographicSpecification.farPlane; }
|
||||||
|
inline float GetOrthographicNearPlane() const { return m_OrthographicSpecification.nearPlane; }
|
||||||
|
|
||||||
|
inline float GetPerspectiveverticalFOV() const { return m_PerspectiveSpecification.verticalFOV; }
|
||||||
|
inline float GetPerspectiveFarPlane() const { return m_PerspectiveSpecification.farPlane; }
|
||||||
|
inline float GetPerspectiveNearPlane() const { return m_PerspectiveSpecification.nearPlane; }
|
||||||
|
|
||||||
|
inline ProjectionType GetProjectionType() const { return m_ProjectionType; }
|
||||||
private:
|
private:
|
||||||
void CalculateProjection();
|
void CalculateProjection();
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace Light {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_CameraEntity = m_Scene->CreateEntity("camera", glm::mat4(1.0f));
|
m_CameraEntity = m_Scene->CreateEntity("camera", glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 1000.0f)));
|
||||||
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
||||||
m_CameraEntity.AddComponent<TagComponent>("Camera");
|
m_CameraEntity.AddComponent<TagComponent>("Camera");
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,70 @@ namespace Light {
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_EntityContext.HasComponent<CameraComponent>())
|
||||||
|
{
|
||||||
|
auto& cameraComp = m_EntityContext.GetComponent<CameraComponent>();
|
||||||
|
auto& camera = cameraComp.camera;
|
||||||
|
|
||||||
|
SceneCamera::ProjectionType projectionType = camera.GetProjectionType();
|
||||||
|
const char* projectionTypesString[] = { "Orthographic", "Perspective" };
|
||||||
|
|
||||||
|
if(ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
const bool isSelected = (int)projectionType == i;
|
||||||
|
if (ImGui::Selectable(projectionTypesString[i], isSelected))
|
||||||
|
{
|
||||||
|
projectionType = (SceneCamera::ProjectionType)i;
|
||||||
|
camera.SetProjectionType(projectionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSelected)
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(projectionType == SceneCamera::ProjectionType::Orthographic)
|
||||||
|
{
|
||||||
|
float orthoSize, nearPlane, farPlane;
|
||||||
|
|
||||||
|
orthoSize = camera.GetOrthographicSize();
|
||||||
|
nearPlane = camera.GetOrthographicNearPlane();
|
||||||
|
farPlane = camera.GetOrthographicFarPlane();
|
||||||
|
|
||||||
|
if(ImGui::DragFloat("Orthographic Size", &orthoSize))
|
||||||
|
camera.SetOrthographicSize(orthoSize);
|
||||||
|
|
||||||
|
if (ImGui::DragFloat("Near Plane", &nearPlane))
|
||||||
|
camera.SetOrthographicNearPlane(nearPlane);
|
||||||
|
|
||||||
|
if(ImGui::DragFloat("Far Plane", &farPlane))
|
||||||
|
camera.SetOrthographicFarPlane(farPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
else // perspective
|
||||||
|
{
|
||||||
|
float verticalFOV, nearPlane, farPlane;
|
||||||
|
|
||||||
|
verticalFOV = glm::degrees(camera.GetPerspectiveverticalFOV());
|
||||||
|
nearPlane = camera.GetPerspectiveNearPlane();
|
||||||
|
farPlane = camera.GetPerspectiveFarPlane();
|
||||||
|
|
||||||
|
if (ImGui::DragFloat("Vertical FOV", &verticalFOV))
|
||||||
|
camera.SetPerspectiveVerticalFOV(glm::radians(verticalFOV));
|
||||||
|
|
||||||
|
if (ImGui::DragFloat("Near Plane", &nearPlane))
|
||||||
|
camera.SetPerspectiveNearPlane(nearPlane);
|
||||||
|
|
||||||
|
if (ImGui::DragFloat("Far Plane", &farPlane))
|
||||||
|
camera.SetPerspectiveFarPlane(farPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
Loading…
Add table
Reference in a new issue