Skip to content

Commit

Permalink
fov fix
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck committed Nov 5, 2024
1 parent fb50fa5 commit e3042fa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ class Camera extends Element {
}

get fovFactor() {
return Math.sin(this.fov * math.DEG_TO_RAD * 0.5);
// we set the fov of the longer axis. here we get the fov of the other (smaller) axis so framing
// doesn't cut off the scene.
const { width, height } = this.scene.targetSize;
const aspect = (width && height) ? this.entity.camera.horizontalFov ? height / width : width / height : 1;
const fov = 2 * Math.atan(Math.tan(this.fov * math.DEG_TO_RAD * 0.5) * aspect);
return Math.sin(fov * 0.5);
}

// intersect the scene at the given screen coordinate and focus the camera on this location
Expand Down

0 comments on commit e3042fa

Please sign in to comment.