Re-add orthographic camera implementation
This commit is contained in:
@@ -23,11 +23,17 @@ namespace Inferno {
|
|||||||
cameraSystem->initialize();
|
cameraSystem->initialize();
|
||||||
CameraSystem::the().setRegistry(m_registry);
|
CameraSystem::the().setRegistry(m_registry);
|
||||||
|
|
||||||
|
#if 1
|
||||||
Entity camera = createEntity("Camera Entity");
|
Entity camera = createEntity("Camera Entity");
|
||||||
camera.add<PerspectiveCameraComponent>();
|
camera.add<PerspectiveCameraComponent>();
|
||||||
auto& cameraTransform = camera.get<TransformComponent>();
|
auto& cameraTransform = camera.get<TransformComponent>();
|
||||||
cameraTransform.translate.z = 1.0f;
|
cameraTransform.translate.z = 1.0f;
|
||||||
cameraTransform.rotate.z = -1.0f;
|
#else
|
||||||
|
Entity camera = createEntity("Camera Entity");
|
||||||
|
camera.add<OrthographicCameraComponment>();
|
||||||
|
auto& cameraTransform = camera.get<TransformComponent>();
|
||||||
|
cameraTransform.translate.z = -1.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
RenderSystem* renderSystem = new RenderSystem();
|
RenderSystem* renderSystem = new RenderSystem();
|
||||||
renderSystem->initialize();
|
renderSystem->initialize();
|
||||||
|
|||||||
@@ -64,7 +64,80 @@ namespace Inferno {
|
|||||||
|
|
||||||
void CameraSystem::updateOrthographic(TransformComponent& transform, OrthographicCameraComponment& orthographic)
|
void CameraSystem::updateOrthographic(TransformComponent& transform, OrthographicCameraComponment& orthographic)
|
||||||
{
|
{
|
||||||
|
// Update camera rotation
|
||||||
|
|
||||||
|
float cameraRotateSpeed = ROTATE_SPEED * (1.0f/ 60.0f);
|
||||||
|
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_Q"))) {
|
||||||
|
transform.rotate.z += cameraRotateSpeed;
|
||||||
|
}
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_E"))) {
|
||||||
|
transform.rotate.z -= cameraRotateSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transform.rotate.z > 180.0f) {
|
||||||
|
transform.rotate.z -= 360.0f;
|
||||||
|
}
|
||||||
|
else if (transform.rotate.z <= -180.0f) {
|
||||||
|
transform.rotate.z += 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera translation
|
||||||
|
|
||||||
|
float cameraTranslateSpeed = TRANSLATE_SPEED * (1.0f / 60.0f);
|
||||||
|
|
||||||
|
// WASD movement
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_W"))) {
|
||||||
|
transform.translate.x += -sin(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
transform.translate.y += cos(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
}
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_S"))) {
|
||||||
|
transform.translate.x -= -sin(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
transform.translate.y -= cos(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
}
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_A"))) {
|
||||||
|
transform.translate.x -= cos(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
transform.translate.y -= sin(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
}
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_D"))) {
|
||||||
|
transform.translate.x += cos(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
transform.translate.y += sin(glm::radians(transform.rotate.z)) * cameraTranslateSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera zoom
|
||||||
|
|
||||||
|
float zoomSpeed = ZOOM_SENSITIVITY * (1.0f / 60.0f);
|
||||||
|
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_EQUAL"))) {
|
||||||
|
orthographic.zoomLevel -= zoomSpeed;
|
||||||
|
}
|
||||||
|
if (Input::isKeyPressed(KeyCode("GLFW_KEY_MINUS"))) {
|
||||||
|
orthographic.zoomLevel += zoomSpeed;
|
||||||
|
}
|
||||||
|
orthographic.zoomLevel = std::max(orthographic.zoomLevel, 0.25f);
|
||||||
|
orthographic.zoomLevel = std::min(orthographic.zoomLevel, 10.0f);
|
||||||
|
|
||||||
|
// Update camera matrix
|
||||||
|
|
||||||
|
// Local space -> World space: model matrix
|
||||||
|
// Is done in Object::update()
|
||||||
|
|
||||||
|
// World space -> View space: view matrix
|
||||||
|
transform.transform = {
|
||||||
|
glm::translate(glm::mat4(1.0f), transform.translate) *
|
||||||
|
glm::rotate(glm::mat4(1.0f), glm::radians(transform.rotate.z), orthographic.rotateAxis)
|
||||||
|
};
|
||||||
|
transform.transform = { glm::inverse(transform.transform) };
|
||||||
|
|
||||||
|
// View space -> Clip space: projection matrix
|
||||||
|
float aspectRatio = Application::the().getWindow().getAspect();
|
||||||
|
orthographic.projection = {
|
||||||
|
glm::ortho(-aspectRatio * orthographic.zoomLevel, aspectRatio * orthographic.zoomLevel,
|
||||||
|
-orthographic.zoomLevel, orthographic.zoomLevel, -1.0f, 1.0f)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clip space -> Screen space: viewport transform
|
||||||
|
// Is done in the fragment shader using the settings of glViewport
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraSystem::updatePerspective(TransformComponent& transform, PerspectiveCameraComponent& perspective)
|
void CameraSystem::updatePerspective(TransformComponent& transform, PerspectiveCameraComponent& perspective)
|
||||||
|
|||||||
Reference in New Issue
Block a user