Skip to content

Commit

Permalink
Fix accumulating camera rotation drift
Browse files Browse the repository at this point in the history
  • Loading branch information
yzrmn committed Apr 17, 2024
1 parent ee1b1dc commit 2da160b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/redgeometry-app/src/parts/gpu-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ function cameraMoveSystem(world: World): void {
return;
}

const camRot = transform.rotation;
const camPos = transform.translation;
let camRot = transform.rotation;
let camPos = transform.translation;

if (mouse.isPressing(MouseButtons.Mouse3)) {
let dx = 0;
Expand All @@ -316,6 +316,8 @@ function cameraMoveSystem(world: World): void {

camRot.rotateXPre(sens * dy);
camRot.rotateY(sens * dx);

camRot = camRot.unit();
}

let vel = 0.005;
Expand All @@ -337,9 +339,12 @@ function cameraMoveSystem(world: World): void {
v = v.unitOrZero().mul(delta * vel);
v = camRot.mulVec(v);

transform.translation = camPos.add(v);
camPos = camPos.add(v);
}

transform.rotation = camRot;
transform.translation = camPos;

world.updateComponent<TransformComponent>(mainCamera, "transform");

const fovRad = fov * (Math.PI / 180);
Expand Down

0 comments on commit 2da160b

Please sign in to comment.