From 71286b108c488d9711d9168980fb7ee09785172b Mon Sep 17 00:00:00 2001 From: eduardodoria Date: Mon, 14 Oct 2024 20:32:15 -0300 Subject: [PATCH] Fixed camera direction --- engine/core/object/Camera.cpp | 8 ++++---- engine/core/subsystem/RenderSystem.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/core/object/Camera.cpp b/engine/core/object/Camera.cpp index c53a701c..dad75125 100644 --- a/engine/core/object/Camera.cpp +++ b/engine/core/object/Camera.cpp @@ -402,7 +402,7 @@ void Camera::zoom(float distance){ CameraComponent& camera = getComponent(); Transform& transf = getComponent(); - transf.position = transf.position + (camera.direction * distance); + transf.position = transf.position - (camera.direction * distance); transf.needUpdate = true; } @@ -426,8 +426,8 @@ void Camera::slideForward(float distance){ CameraComponent& camera = getComponent(); Transform& transf = getComponent(); - camera.target = camera.target + (camera.direction * distance); - transf.position = transf.position + (camera.direction * distance); + camera.target = camera.target - (camera.direction * distance); + transf.position = transf.position - (camera.direction * distance); transf.needUpdate = true; camera.needUpdate = true; @@ -439,7 +439,7 @@ void Camera::slideUp(float distance){ CameraComponent& camera = getComponent(); Transform& transf = getComponent(); - Vector3 slideVector = camera.right.crossProduct(camera.direction); + Vector3 slideVector = camera.direction.crossProduct(camera.right); slideVector.normalize(); camera.target = camera.target + (slideVector * distance); diff --git a/engine/core/subsystem/RenderSystem.cpp b/engine/core/subsystem/RenderSystem.cpp index 492e13ee..f3e9aae6 100644 --- a/engine/core/subsystem/RenderSystem.cpp +++ b/engine/core/subsystem/RenderSystem.cpp @@ -1789,9 +1789,9 @@ void RenderSystem::updateCamera(CameraComponent& camera, Transform& transform){ camera.projectionMatrix = Matrix4::perspectiveMatrix(camera.yfov, camera.aspect, camera.nearClip, camera.farClip); } - camera.direction = (camera.target - transform.position).normalize(); - camera.right = (camera.direction.crossProduct(camera.up)).normalize(); - //camera.up = right.crossProduct(direction); // no need to align, keep "up" always same + camera.direction = (transform.position - camera.target).normalize(); + camera.right = (camera.up.crossProduct(camera.direction)).normalize(); + //camera.up = camera.direction.crossProduct(camera.right); // no need to align, keep "up" always same if (transform.parent != NULL_ENTITY){ camera.worldTarget = transform.modelMatrix * (camera.target - transform.position); @@ -1808,7 +1808,7 @@ void RenderSystem::updateCamera(CameraComponent& camera, Transform& transform){ camera.viewMatrix = Matrix4::lookAtMatrix(transform.worldPosition, camera.worldTarget, camera.worldUp); } - camera.worldDirection = Vector3(-camera.viewMatrix[0][2], -camera.viewMatrix[1][2], -camera.viewMatrix[2][2]); + camera.worldDirection = Vector3(camera.viewMatrix[0][2], camera.viewMatrix[1][2], camera.viewMatrix[2][2]); camera.worldRight = Vector3(camera.viewMatrix[0][0], camera.viewMatrix[1][0], camera.viewMatrix[2][0]); //Update ViewProjectionMatrix