Skip to content

Commit ab92ea6

Browse files
deltakoshDavid Catuhe
andauthored
Add new utility function to set a camera FOV based on focal length (#16763)
Co-authored-by: David Catuhe <[email protected]>
1 parent d5726d6 commit ab92ea6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/dev/core/src/Cameras/camera.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ export class Camera extends Node {
261261
@serialize()
262262
public fov = 0.8;
263263

264+
/**
265+
* Sets the camera's field of view in radians based on the focal length and sensor size.
266+
* @param value the focal length of the camera in mm.
267+
* @param sensorSize the sensor width size of the camera in mm. (default is 36mm, which is a full frame sensor)
268+
*/
269+
public setFocalLength(value: number, sensorSize: number = 36) {
270+
this.fov = 2 * Math.atan(sensorSize / (2 * value));
271+
}
272+
264273
/**
265274
* Projection plane tilt around the X axis (horizontal), set in Radians. (default is 0)
266275
* Can be used to make vertical lines in world space actually vertical on the screen.

0 commit comments

Comments
 (0)