Skip to content

Commit

Permalink
fix(camera): fresh context for each actor, not just machine
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jan 31, 2024
1 parent cfe5406 commit ab5836a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/viewer/src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export const cameraMachine = setup({
}).createMachine({
id: 'camera',
initial: 'active',
context: {
context: () => ({
pose: createPose(),
enableRotation: true,
parallelScaleRatio: 1,
verticalFieldOfView: 50,
poseWatchers: [],
},
}),
states: {
active: {
on: {
Expand Down Expand Up @@ -195,8 +195,8 @@ export const reset3d = (
// compute the radius of the enclosing sphere
radius = Math.sqrt(radius) * 0.5;

const angle = verticalFieldOfView * (Math.PI / 180); // to radians
const distance = radius / Math.sin(angle * 0.5);
const radians = verticalFieldOfView * (Math.PI / 180);
const distance = radius / Math.sin(radians * 0.5);

return { center, rotation: pose.rotation, distance };
};
Expand Down Expand Up @@ -227,10 +227,11 @@ export const reset2d = (

const xLength = getLength(viewBounds, 0);
const yLength = getLength(viewBounds, 1);
// compute half the width or height of the viewport
const parallelScale = 0.5 * Math.max(yLength, xLength / aspect);

const angle = verticalFieldOfView * (Math.PI / 180); // to radians
const distance = parallelScale / Math.tan(angle * 0.5);
const radians = verticalFieldOfView * (Math.PI / 180);
const distance = parallelScale / Math.tan(radians * 0.5);

return { center, rotation: pose.rotation, distance, parallelScale };
};

0 comments on commit ab5836a

Please sign in to comment.