Skip to content

Commit

Permalink
fix: Camera target calculated from new position
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoAize authored and hugolafis committed Jun 26, 2023
1 parent 87e6f62 commit 02b22e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions viewer/packages/camera-manager/src/CameraManagerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class CameraManagerHelper {
static calculateNewTargetFromRotation(
camera: THREE.PerspectiveCamera,
rotation: THREE.Quaternion,
currentTarget: THREE.Vector3
currentTarget: THREE.Vector3,
position: THREE.Vector3
): THREE.Vector3 {
const distToTarget = currentTarget.clone().sub(camera.position);
const tempCam = camera.clone();
Expand All @@ -54,7 +55,7 @@ export class CameraManagerHelper {
.getWorldDirection(new THREE.Vector3())
.normalize()
.multiplyScalar(distToTarget.length())
.add(tempCam.position);
.add(position);

return newTarget;
}
Expand Down
3 changes: 2 additions & 1 deletion viewer/packages/camera-manager/src/DefaultCameraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ export class DefaultCameraManager implements CameraManager {
? CameraManagerHelper.calculateNewTargetFromRotation(
this._camera,
state.rotation,
this._controls.getState().target
this._controls.getState().target,
newPosition
)
: this._controls.getState().target);

Expand Down

0 comments on commit 02b22e5

Please sign in to comment.