PerspectiveCamera - Verge3D User Manual - Soft8Soft
Description: Learn how to use PerspectiveCamera in your interactive 3D apps made with Verge3D

Object3D → Camera →

# PerspectiveCamera

Camera that uses perspective projection.

This projection mode is designed to mimic the way the human eye sees. It is the most common projection mode used for rendering a 3D scene.

## Code Example

`const aspect = app.getWidth() / app.getHeight(); const camera = new v3d.PerspectiveCamera(45, aspect, 1, 1000); camera.position.z = 5; app.scene.add(camera); app.setCamera(camera);`

## Constructor

### PerspectiveCamera(fov : Float, aspect : Float, near : Float, far : Float)

- fov — camera frustum vertical field of view
- aspect — camera frustum aspect ratio
- near — camera frustum near plane
- far — camera frustum far plane

Together these define the camera's viewing frustum.

## Properties

See the base Camera class for inherited properties. Note that after making changes to most of these properties you will have to call .updateProjectionMatrix for the changes to take effect.

### # .aspect : Float

Camera frustum aspect ratio, usually the canvas width / canvas height. Default is `1` (square canvas).

### # .far : Float

Camera frustum far plane. Default is `2000`.

Must be greater than the current value of near plane.

### # .filmGauge : Float

Film size used for the larger axis. Default is `35` (millimeters). This parameter does not influence the projection matrix unless .filmOffset is set to a nonzero value.

### # .filmOffset : Float

Horizontal off-center offset in the same unit as `.filmGauge`. Default is `0`.

### # .focus : Float

Object distance used for stereoscopy and depth-of-field effects. This parameter does not influence the projection matrix unless a StereoCamera is being used. Default is `10`.

### # .fov : Float

Camera frustum vertical field of view, from bottom to top of view, in degrees. Default is `50`.

### # .isPerspectiveCamera : Boolean

Read-only flag to check if a given object is of type PerspectiveCamera.

### # .near : Float

Camera frustum near plane. Default is `0.1`.

The valid range is greater than 0 and less than the current value of the far plane. Note that, unlike for the OrthographicCamera, `0` is not a valid value for a PerspectiveCamera's near plane.

### # .view : Object

Frustum window specification or `null`. This is set using the .setViewOffset method and cleared using .clearViewOffset.

### # .zoom : Float

Gets or sets the zoom factor of the camera. Default is `1`.

## Methods

See the base Camera class for inherited methods.

### # .clearViewOffset()

Removes any offset set by the .setViewOffset method.

### # .getEffectiveFOV() → Float

Returns the current vertical field of view angle in degrees considering .zoom.

### # .getFilmHeight() → Float

Returns the height of the image on the film. If .aspect is less than or equal to one (portrait format), the result equals .filmGauge.

### # .getFilmWidth() → Float

Returns the width of the image on the film. If .aspect is greater than or equal to one (landscape format), the result equals .filmGauge.

### # .getFocalLength() → Float

Returns the focal length of the current .fov in respect to .filmGauge.

### # .setFocalLength(focalLength : Float)

Sets the FOV by focal length in respect to the current .filmGauge.

By default, the focal length is specified for a 35mm (full frame) camera.

### # .setViewOffset(fullWidth : Float, fullHeight : Float, x : Float, y : Float, width : Float, height : Float)

- [page:Float fullWidth — full width of multiview setup
- [page:Float fullHeight — full height of multiview setup
- [page:Float x — horizontal offset of subcamera
- [page:Float y — vertical offset of subcamera
- [page:Float width — width of subcamera
- [page:Float height — height of subcamera

Sets an offset in a larger frustum. This is useful for multi-window or multi-monitor/multi-machine setups.

For example, if you have 3x2 monitors and each monitor is 1920x1080 and the monitors are in grid like this:

        +---+---+---+
        | A | B | C |
        +---+---+---+
        | D | E | F |
        +---+---+---+

then for each monitor you would call it like this:

`const w = 1920; const h = 1080; const fullWidth = w * 3; const fullHeight = h * 2; // A camera.setViewOffset(fullWidth, fullHeight, w * 0, h * 0, w, h); // B camera.setViewOffset(fullWidth, fullHeight, w * 1, h * 0, w, h); // C camera.setViewOffset(fullWidth, fullHeight, w * 2, h * 0, w, h); // D camera.setViewOffset(fullWidth, fullHeight, w * 0, h * 1, w, h); // E camera.setViewOffset(fullWidth, fullHeight, w * 1, h * 1, w, h); // F camera.setViewOffset(fullWidth, fullHeight, w * 2, h * 1, w, h);`

Note there is no reason monitors have to be the same size or in a grid.

### # .updateProjectionMatrix()

Updates the camera projection matrix. Must be called after any change of parameters.

## Puzzles

There are numerous camera puzzles to manage your camera with no coding.

## Source

For more info on how to obtain the source code of this module see this page.