PerspectiveCamera.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>PerspectiveCamera - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → <a href="Camera.html">Camera</a> → </p>
  13. <h1 translate="no">PerspectiveCamera</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Camera that uses <a href="https://en.wikipedia.org/wiki/Perspective_(graphical)">perspective projection</a>.</p>
  17. <p>This projection mode is designed to mimic the way the human eye sees. It
  18. is the most common projection mode used for rendering a 3D scene.</p></div>
  19. <h2>Code Example</h2>
  20. <div translate="no"><pre><code class="language-js">const camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
  21. scene.add( camera );
  22. </code></pre></div>
  23. </header>
  24. <article>
  25. <div class="container-overview">
  26. <h2>Constructor</h2>
  27. <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>
  28. <div class="method">
  29. <div class="description">
  30. <p>Constructs a new perspective camera.</p>
  31. </div>
  32. <table class="params">
  33. <tbody>
  34. <tr>
  35. <td class="name"><code>fov</code></td>
  36. <td class="description last"><p>The vertical field of view.<br/>Default is <code>50</code>.</p></td>
  37. </tr>
  38. <tr>
  39. <td class="name"><code>aspect</code></td>
  40. <td class="description last"><p>The aspect ratio.<br/>Default is <code>1</code>.</p></td>
  41. </tr>
  42. <tr>
  43. <td class="name"><code>near</code></td>
  44. <td class="description last"><p>The camera's near plane.<br/>Default is <code>0.1</code>.</p></td>
  45. </tr>
  46. <tr>
  47. <td class="name"><code>far</code></td>
  48. <td class="description last"><p>The camera's far plane.<br/>Default is <code>2000</code>.</p></td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. </div>
  54. <h2 class="subsection-title">Properties</h2>
  55. <div class="member">
  56. <h3 class="name" id="aspect" translate="no">.<a href="#aspect">aspect</a><span class="type-signature"> : number</span> </h3>
  57. <div class="description">
  58. <p>The aspect ratio, usually the canvas width / canvas height.<br/>Default is <code>1</code>.</p>
  59. </div>
  60. </div>
  61. <div class="member">
  62. <h3 class="name" id="far" translate="no">.<a href="#far">far</a><span class="type-signature"> : number</span> </h3>
  63. <div class="description">
  64. <p>The camera's far plane. Must be greater than the
  65. current value of <a href="PerspectiveCamera.html#near">PerspectiveCamera#near</a>.<br/>Default is <code>2000</code>.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="filmGauge" translate="no">.<a href="#filmGauge">filmGauge</a><span class="type-signature"> : number</span> </h3>
  70. <div class="description">
  71. <p>Film size used for the larger axis. Default is <code>35</code> (millimeters). This
  72. parameter does not influence the projection matrix unless <a href="PerspectiveCamera.html#filmOffset">PerspectiveCamera#filmOffset</a>
  73. is set to a nonzero value.<br/>Default is <code>35</code>.</p>
  74. </div>
  75. </div>
  76. <div class="member">
  77. <h3 class="name" id="filmOffset" translate="no">.<a href="#filmOffset">filmOffset</a><span class="type-signature"> : number</span> </h3>
  78. <div class="description">
  79. <p>Horizontal off-center offset in the same unit as <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.<br/>Default is <code>0</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <h3 class="name" id="focus" translate="no">.<a href="#focus">focus</a><span class="type-signature"> : number</span> </h3>
  84. <div class="description">
  85. <p>Object distance used for stereoscopy and depth-of-field effects. This
  86. parameter does not influence the projection matrix unless a
  87. <a href="StereoCamera.html">StereoCamera</a> is being used.<br/>Default is <code>10</code>.</p>
  88. </div>
  89. </div>
  90. <div class="member">
  91. <h3 class="name" id="fov" translate="no">.<a href="#fov">fov</a><span class="type-signature"> : number</span> </h3>
  92. <div class="description">
  93. <p>The vertical field of view, from bottom to top of view,
  94. in degrees.<br/>Default is <code>50</code>.</p>
  95. </div>
  96. </div>
  97. <div class="member">
  98. <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>
  99. <div class="description">
  100. <p>This flag can be used for type testing.<br/>Default is <code>true</code>.</p>
  101. </div>
  102. </div>
  103. <div class="member">
  104. <h3 class="name" id="near" translate="no">.<a href="#near">near</a><span class="type-signature"> : number</span> </h3>
  105. <div class="description">
  106. <p>The camera's near plane. The valid range is greater than <code>0</code>
  107. and less than the current value of <a href="PerspectiveCamera.html#far">PerspectiveCamera#far</a>.</p>
  108. <p>Note that, unlike for the <a href="OrthographicCamera.html">OrthographicCamera</a>, <code>0</code> is <em>not</em> a
  109. valid value for a perspective camera's near plane.<br/>Default is <code>0.1</code>.</p>
  110. </div>
  111. </div>
  112. <div class="member">
  113. <h3 class="name" id="view" translate="no">.<a href="#view">view</a><span class="type-signature"> : Object</span> </h3>
  114. <div class="description">
  115. <p>Represents the frustum window specification. This property should not be edited
  116. directly but via <a href="PerspectiveCamera.html#setViewOffset">PerspectiveCamera#setViewOffset</a> and <a href="PerspectiveCamera.html#clearViewOffset">PerspectiveCamera#clearViewOffset</a>.<br/>Default is <code>null</code>.</p>
  117. </div>
  118. </div>
  119. <div class="member">
  120. <h3 class="name" id="zoom" translate="no">.<a href="#zoom">zoom</a><span class="type-signature"> : number</span> </h3>
  121. <div class="description">
  122. <p>The zoom factor of the camera.<br/>Default is <code>1</code>.</p>
  123. </div>
  124. </div>
  125. <h2 class="subsection-title">Methods</h2>
  126. <h3 class="name name-method" id="clearViewOffset" translate="no">.<a href="#clearViewOffset">clearViewOffset</a><span class="signature">()</span> </h3>
  127. <div class="method">
  128. <div class="description">
  129. <p>Removes the view offset from the projection matrix.</p>
  130. </div>
  131. </div>
  132. <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>
  133. <div class="method">
  134. <div class="description">
  135. <p>Returns the current vertical field of view angle in degrees considering <a href="PerspectiveCamera.html#zoom">PerspectiveCamera#zoom</a>.</p>
  136. </div>
  137. <dl class="details">
  138. <dt class="tag-returns"><strong>Returns:</strong> The effective FOV.</dt>
  139. </dl>
  140. </div>
  141. <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>
  142. <div class="method">
  143. <div class="description">
  144. <p>Returns the height of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
  145. equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  146. </div>
  147. <dl class="details">
  148. <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
  149. </dl>
  150. </div>
  151. <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>
  152. <div class="method">
  153. <div class="description">
  154. <p>Returns the width of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
  155. equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  156. </div>
  157. <dl class="details">
  158. <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
  159. </dl>
  160. </div>
  161. <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>
  162. <div class="method">
  163. <div class="description">
  164. <p>Returns the focal length from the current <a href="PerspectiveCamera.html#fov">PerspectiveCamera#fov</a> and
  165. <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  166. </div>
  167. <dl class="details">
  168. <dt class="tag-returns"><strong>Returns:</strong> The computed focal length.</dt>
  169. </dl>
  170. </div>
  171. <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">Vector2</span>, maxTarget : <span class="param-type">Vector2</span> )</span> </h3>
  172. <div class="method">
  173. <div class="description">
  174. <p>Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  175. Sets <code>minTarget</code> and <code>maxTarget</code> to the coordinates of the lower-left and upper-right corners of the view rectangle.</p>
  176. </div>
  177. <table class="params">
  178. <tbody>
  179. <tr>
  180. <td class="name"><code>distance</code></td>
  181. <td class="description last"><p>The viewing distance.</p></td>
  182. </tr>
  183. <tr>
  184. <td class="name"><code>minTarget</code></td>
  185. <td class="description last"><p>The lower-left corner of the view rectangle is written into this vector.</p></td>
  186. </tr>
  187. <tr>
  188. <td class="name"><code>maxTarget</code></td>
  189. <td class="description last"><p>The upper-right corner of the view rectangle is written into this vector.</p></td>
  190. </tr>
  191. </tbody>
  192. </table>
  193. </div>
  194. <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">Vector2</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  195. <div class="method">
  196. <div class="description">
  197. <p>Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.</p>
  198. </div>
  199. <table class="params">
  200. <tbody>
  201. <tr>
  202. <td class="name"><code>distance</code></td>
  203. <td class="description last"><p>The viewing distance.</p></td>
  204. </tr>
  205. <tr>
  206. <td class="name"><code>target</code></td>
  207. <td class="description last"><p>The target vector that is used to store result where x is width and y is height.</p></td>
  208. </tr>
  209. </tbody>
  210. </table>
  211. <dl class="details">
  212. <dt class="tag-returns"><strong>Returns:</strong> The view size.</dt>
  213. </dl>
  214. </div>
  215. <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>
  216. <div class="method">
  217. <div class="description">
  218. <p>Sets the FOV by focal length in respect to the current <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  219. <p>The default film gauge is 35, so that the focal length can be specified for
  220. a 35mm (full frame) camera.</p>
  221. </div>
  222. <table class="params">
  223. <tbody>
  224. <tr>
  225. <td class="name"><code>focalLength</code></td>
  226. <td class="description last"><p>Values for focal length and film gauge must have the same unit.</p></td>
  227. </tr>
  228. </tbody>
  229. </table>
  230. </div>
  231. <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>
  232. <div class="method">
  233. <div class="description">
  234. <p>Sets an offset in a larger frustum. This is useful for multi-window or
  235. multi-monitor/multi-machine setups.</p>
  236. <p>For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  237. the monitors are in grid like this</p>
  238. <pre class="prettyprint source"><code> +---+---+---+
  239. | A | B | C |
  240. +---+---+---+
  241. | D | E | F |
  242. +---+---+---+
  243. </code></pre>
  244. <p>then for each monitor you would call it like this:</p>
  245. <pre><code class="language-js">const w = 1920;
  246. const h = 1080;
  247. const fullWidth = w * 3;
  248. const fullHeight = h * 2;
  249. // --A--
  250. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  251. // --B--
  252. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  253. // --C--
  254. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  255. // --D--
  256. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  257. // --E--
  258. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  259. // --F--
  260. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  261. </code></pre>
  262. <p>Note there is no reason monitors have to be the same size or in a grid.</p>
  263. </div>
  264. <table class="params">
  265. <tbody>
  266. <tr>
  267. <td class="name"><code>fullWidth</code></td>
  268. <td class="description last"><p>The full width of multiview setup.</p></td>
  269. </tr>
  270. <tr>
  271. <td class="name"><code>fullHeight</code></td>
  272. <td class="description last"><p>The full height of multiview setup.</p></td>
  273. </tr>
  274. <tr>
  275. <td class="name"><code>x</code></td>
  276. <td class="description last"><p>The horizontal offset of the subcamera.</p></td>
  277. </tr>
  278. <tr>
  279. <td class="name"><code>y</code></td>
  280. <td class="description last"><p>The vertical offset of the subcamera.</p></td>
  281. </tr>
  282. <tr>
  283. <td class="name"><code>width</code></td>
  284. <td class="description last"><p>The width of subcamera.</p></td>
  285. </tr>
  286. <tr>
  287. <td class="name"><code>height</code></td>
  288. <td class="description last"><p>The height of subcamera.</p></td>
  289. </tr>
  290. </tbody>
  291. </table>
  292. </div>
  293. <h3 class="name name-method" id="updateProjectionMatrix" translate="no">.<a href="#updateProjectionMatrix">updateProjectionMatrix</a><span class="signature">()</span> </h3>
  294. <div class="method">
  295. <div class="description">
  296. <p>Updates the camera's projection matrix. Must be called after any change of
  297. camera properties.</p>
  298. </div>
  299. </div>
  300. <h2 class="subsection-title">Source</h2>
  301. <p>
  302. <a href="https://github.com/mrdoob/three.js/blob/master/src/cameras/PerspectiveCamera.js" target="_blank" rel="noopener" translate="no">src/cameras/PerspectiveCamera.js</a>
  303. </p>
  304. </article>
  305. </section>
  306. <script src="../scripts/linenumber.js"></script>
  307. <script src="../scripts/page.js"></script>
  308. </body>
  309. </html>
粤ICP备19079148号