Skip to content

Commit

Permalink
Fixed camera direction
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Oct 14, 2024
1 parent 948a894 commit 71286b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions engine/core/object/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void Camera::zoom(float distance){
CameraComponent& camera = getComponent<CameraComponent>();
Transform& transf = getComponent<Transform>();

transf.position = transf.position + (camera.direction * distance);
transf.position = transf.position - (camera.direction * distance);

transf.needUpdate = true;
}
Expand All @@ -426,8 +426,8 @@ void Camera::slideForward(float distance){
CameraComponent& camera = getComponent<CameraComponent>();
Transform& transf = getComponent<Transform>();

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;
Expand All @@ -439,7 +439,7 @@ void Camera::slideUp(float distance){
CameraComponent& camera = getComponent<CameraComponent>();
Transform& transf = getComponent<Transform>();

Vector3 slideVector = camera.right.crossProduct(camera.direction);
Vector3 slideVector = camera.direction.crossProduct(camera.right);
slideVector.normalize();

camera.target = camera.target + (slideVector * distance);
Expand Down
8 changes: 4 additions & 4 deletions engine/core/subsystem/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 71286b1

Please sign in to comment.