| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>PerspectiveCamera - Three.js Docs</title>
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <script src="../scripts/highlight.min.js"></script>
- <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
- <link type="text/css" rel="stylesheet" href="../styles/page.css">
- </head>
- <body>
- <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → <a href="Camera.html">Camera</a> → </p>
- <h1 translate="no">PerspectiveCamera</h1>
- <section>
- <header>
- <div class="class-description"><p>Camera that uses <a href="https://en.wikipedia.org/wiki/Perspective_(graphical)" target="_blank" rel="noopener">perspective projection</a>.</p>
- <p>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.</p></div>
- <h2>Code Example</h2>
- <div translate="no"><pre><code class="language-js">const camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
- scene.add( camera );
- </code></pre></div>
- </header>
- <article>
- <div class="container-overview">
- <h2>Constructor</h2>
- <h3 class="name name-method" id="PerspectiveCamera" translate="no">new <a href="#PerspectiveCamera">PerspectiveCamera</a><span class="signature">( fov : <span class="param-type">number</span>, aspect : <span class="param-type">number</span>, near : <span class="param-type">number</span>, far : <span class="param-type">number</span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Constructs a new perspective camera.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>fov</strong>
- </td>
- <td class="description last">
- <p>The vertical field of view.</p>
- <p>Default is <code>50</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>aspect</strong>
- </td>
- <td class="description last">
- <p>The aspect ratio.</p>
- <p>Default is <code>1</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>near</strong>
- </td>
- <td class="description last">
- <p>The camera's near plane.</p>
- <p>Default is <code>0.1</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>far</strong>
- </td>
- <td class="description last">
- <p>The camera's far plane.</p>
- <p>Default is <code>2000</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <h2 class="subsection-title">Properties</h2>
- <div class="member">
- <h3 class="name" id="aspect" translate="no">.<a href="#aspect">aspect</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The aspect ratio, usually the canvas width / canvas height.</p>
- <p>Default is <code>1</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="far" translate="no">.<a href="#far">far</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The camera's far plane. Must be greater than the
- current value of <a href="PerspectiveCamera.html#near">PerspectiveCamera#near</a>.</p>
- <p>Default is <code>2000</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="filmGauge" translate="no">.<a href="#filmGauge">filmGauge</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Film size used for the larger axis. Default is <code>35</code> (millimeters). This
- parameter does not influence the projection matrix unless <a href="PerspectiveCamera.html#filmOffset">PerspectiveCamera#filmOffset</a>
- is set to a nonzero value.</p>
- <p>Default is <code>35</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="filmOffset" translate="no">.<a href="#filmOffset">filmOffset</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Horizontal off-center offset in the same unit as <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
- <p>Default is <code>0</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="focus" translate="no">.<a href="#focus">focus</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Object distance used for stereoscopy and depth-of-field effects. This
- parameter does not influence the projection matrix unless a
- <a href="StereoCamera.html">StereoCamera</a> is being used.</p>
- <p>Default is <code>10</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="fov" translate="no">.<a href="#fov">fov</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The vertical field of view, from bottom to top of view,
- in degrees.</p>
- <p>Default is <code>50</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="isPerspectiveCamera" translate="no">.<a href="#isPerspectiveCamera">isPerspectiveCamera</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
- <div class="description">
- <p>This flag can be used for type testing.</p>
- <p>Default is <code>true</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="near" translate="no">.<a href="#near">near</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The camera's near plane. The valid range is greater than <code>0</code>
- and less than the current value of <a href="PerspectiveCamera.html#far">PerspectiveCamera#far</a>.</p>
- <p>Note that, unlike for the <a href="OrthographicCamera.html">OrthographicCamera</a>, <code>0</code> is <em>not</em> a
- valid value for a perspective camera's near plane.</p>
- <p>Default is <code>0.1</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="view" translate="no">.<a href="#view">view</a><span class="type-signature"> : Object</span> </h3>
- <div class="description">
- <p>Represents the frustum window specification. This property should not be edited
- directly but via <a href="PerspectiveCamera.html#setViewOffset">PerspectiveCamera#setViewOffset</a> and <a href="PerspectiveCamera.html#clearViewOffset">PerspectiveCamera#clearViewOffset</a>.</p>
- <p>Default is <code>null</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="zoom" translate="no">.<a href="#zoom">zoom</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The zoom factor of the camera.</p>
- <p>Default is <code>1</code>.</p>
- </div>
- </div>
- <h2 class="subsection-title">Methods</h2>
- <h3 class="name name-method" id="clearViewOffset" translate="no">.<a href="#clearViewOffset">clearViewOffset</a><span class="signature">()</span> </h3>
- <div class="method">
- <div class="description">
- <p>Removes the view offset from the projection matrix.</p>
- </div>
- </div>
- <h3 class="name name-method" id="getEffectiveFOV" translate="no">.<a href="#getEffectiveFOV">getEffectiveFOV</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the current vertical field of view angle in degrees considering <a href="PerspectiveCamera.html#zoom">PerspectiveCamera#zoom</a>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The effective FOV.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="getFilmHeight" translate="no">.<a href="#getFilmHeight">getFilmHeight</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the height of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
- equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="getFilmWidth" translate="no">.<a href="#getFilmWidth">getFilmWidth</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the width of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
- equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="getFocalLength" translate="no">.<a href="#getFocalLength">getFocalLength</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the focal length from the current <a href="PerspectiveCamera.html#fov">PerspectiveCamera#fov</a> and
- <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The computed focal length.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="getViewBounds" translate="no">.<a href="#getViewBounds">getViewBounds</a><span class="signature">( distance : <span class="param-type">number</span>, minTarget : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, maxTarget : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
- Sets <code>minTarget</code> and <code>maxTarget</code> to the coordinates of the lower-left and upper-right corners of the view rectangle.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>distance</strong>
- </td>
- <td class="description last">
- <p>The viewing distance.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>minTarget</strong>
- </td>
- <td class="description last">
- <p>The lower-left corner of the view rectangle is written into this vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>maxTarget</strong>
- </td>
- <td class="description last">
- <p>The upper-right corner of the view rectangle is written into this vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <h3 class="name name-method" id="getViewSize" translate="no">.<a href="#getViewSize">getViewSize</a><span class="signature">( distance : <span class="param-type">number</span>, target : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>distance</strong>
- </td>
- <td class="description last">
- <p>The viewing distance.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store result where x is width and y is height.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The view size.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="setFocalLength" translate="no">.<a href="#setFocalLength">setFocalLength</a><span class="signature">( focalLength : <span class="param-type">number</span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Sets the FOV by focal length in respect to the current <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
- <p>The default film gauge is 35, so that the focal length can be specified for
- a 35mm (full frame) camera.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>focalLength</strong>
- </td>
- <td class="description last">
- <p>Values for focal length and film gauge must have the same unit.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <h3 class="name name-method" id="setViewOffset" translate="no">.<a href="#setViewOffset">setViewOffset</a><span class="signature">( fullWidth : <span class="param-type">number</span>, fullHeight : <span class="param-type">number</span>, x : <span class="param-type">number</span>, y : <span class="param-type">number</span>, width : <span class="param-type">number</span>, height : <span class="param-type">number</span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Sets an offset in a larger frustum. This is useful for multi-window or
- multi-monitor/multi-machine setups.</p>
- <p>For example, if you have 3x2 monitors and each monitor is 1920x1080 and
- the monitors are in grid like this</p>
- <pre class="prettyprint source"><code> +---+---+---+
- | A | B | C |
- +---+---+---+
- | D | E | F |
- +---+---+---+
- </code></pre>
- <p>then for each monitor you would call it like this:</p>
- <pre><code class="language-js">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 );
- </code></pre>
- <p>Note there is no reason monitors have to be the same size or in a grid.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>fullWidth</strong>
- </td>
- <td class="description last">
- <p>The full width of multiview setup.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>fullHeight</strong>
- </td>
- <td class="description last">
- <p>The full height of multiview setup.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>x</strong>
- </td>
- <td class="description last">
- <p>The horizontal offset of the subcamera.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>y</strong>
- </td>
- <td class="description last">
- <p>The vertical offset of the subcamera.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>width</strong>
- </td>
- <td class="description last">
- <p>The width of subcamera.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>height</strong>
- </td>
- <td class="description last">
- <p>The height of subcamera.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <h3 class="name name-method" id="updateProjectionMatrix" translate="no">.<a href="#updateProjectionMatrix">updateProjectionMatrix</a><span class="signature">()</span> </h3>
- <div class="method">
- <div class="description">
- <p>Updates the camera's projection matrix. Must be called after any change of
- camera properties.</p>
- </div>
- </div>
- <h2 class="subsection-title">Source</h2>
- <p>
- <a href="https://github.com/mrdoob/three.js/blob/master/src/cameras/PerspectiveCamera.js" translate="no" target="_blank" rel="noopener">src/cameras/PerspectiveCamera.js</a>
- </p>
- </article>
- </section>
- <script src="../scripts/linenumber.js"></script>
- <script src="../scripts/page.js"></script>
- </body>
- </html>
|