Capítulo 19 de 859

Chapter 19: PerspectiveCamera

Core Idea

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.

Key Concepts

  • aspect : number: The aspect ratio, usually the canvas width / canvas height.
  • far : number: The camera's far plane. Must be greater than the current value of PerspectiveCamera#near.
  • filmGauge : number: Film size used for the larger axis. Default is 35 (millimeters). This parameter does not influence the projection matrix unless [Perspect…
  • filmOffset : number: Horizontal off-center offset in the same unit as PerspectiveCamera#filmGauge.
  • focus : number: Object distance used for stereoscopy and depth-of-field effects. This parameter does not influence the projection matrix unless a [StereoCa…
  • fov : number: The vertical field of view, from bottom to top of view, in degrees.
  • isPerspectiveCamera : boolean (readonly): This flag can be used for type testing.
  • near : number: The camera's near plane. The valid range is greater than 0 and less than the current value of [PerspectiveCamera#far](PerspectiveCamera.h…
  • view : Object: Represents the frustum window specification. This property should not be edited directly but via [PerspectiveCamera#setViewOffset](Perspect…
  • zoom : number: The zoom factor of the camera.

Code Examples

const camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
scene.add( camera );
  • What it demonstrates: Typical usage of PerspectiveCamera.

Reference Tables

Constructor

Signature
new PerspectiveCamera( fov : number, aspect : number, near : number, far : number )

Properties

PropertyDescription
.aspect : numberThe aspect ratio, usually the canvas width / canvas height.
.far : numberThe camera's far plane. Must be greater than the current value of PerspectiveCamera#near.
.filmGauge : numberFilm size used for the larger axis. Default is 35 (millimeters). This parameter does not influence the projection matrix unless PerspectiveCamera#filmOffset is …
.filmOffset : numberHorizontal off-center offset in the same unit as PerspectiveCamera#filmGauge.
.focus : numberObject distance used for stereoscopy and depth-of-field effects. This parameter does not influence the projection matrix unless a StereoCamera is being used.
.fov : numberThe vertical field of view, from bottom to top of view, in degrees.
.isPerspectiveCamera : boolean (readonly)This flag can be used for type testing.
.near : numberThe camera's near plane. The valid range is greater than 0 and less than the current value of PerspectiveCamera#far.
.view : ObjectRepresents the frustum window specification. This property should not be edited directly but via PerspectiveCamera#setViewOffset and [PerspectiveCamera#clearVi…
.zoom : numberThe zoom factor of the camera.

Methods

MethodDescription
.clearViewOffset()Removes the view offset from the projection matrix.
.getEffectiveFOV() : numberReturns the current vertical field of view angle in degrees considering PerspectiveCamera#zoom.
.getFilmHeight() : numberReturns the height of the image on the film. If PerspectiveCamera#aspect is greater than or equal to one (landscape format), the result equals [PerspectiveCamera#film…
.getFilmWidth() : numberReturns the width of the image on the film. If PerspectiveCamera#aspect is greater than or equal to one (landscape format), the result equals [PerspectiveCamera#filmG…
.getFocalLength() : numberReturns the focal length from the current PerspectiveCamera#fov and PerspectiveCamera#filmGauge.
.getViewBounds( distance : number, minTarget : Vector2, maxTarget : Vector2 )Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction. Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corner…
.getViewSize( distance : number, target : Vector2 ) : Vector2Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
.setFocalLength( focalLength : number )Sets the FOV by focal length in respect to the current PerspectiveCamera#filmGauge.
.setViewOffset( fullWidth : number, fullHeight : number, x : number, y : number, width : number, height : number )Sets an offset in a larger frustum. This is useful for multi-window or multi-monitor/multi-machine setups.
.updateProjectionMatrix()Updates the camera's projection matrix. Must be called after any change of camera properties.

Key Takeaways

  1. PerspectiveCamera extends: EventDispatcher → Object3D → Camera
  2. Most relevant properties: aspect, far, filmGauge, filmOffset.
  3. Key methods: clearViewOffset, getEffectiveFOV, getFilmHeight, getFilmWidth.

Connects To