From e3042fae36626cdfbb12cef4dac39a6e62ad6c1c Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 5 Nov 2024 15:33:16 +0000 Subject: [PATCH] fov fix --- src/camera.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/camera.ts b/src/camera.ts index 2658c57..b9bfffc 100644 --- a/src/camera.ts +++ b/src/camera.ts @@ -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