PerspectiveCamera.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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)" target="_blank" rel="noopener">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">
  36. <strong>fov</strong>
  37. </td>
  38. <td class="description last">
  39. <p>The vertical field of view.</p>
  40. <p>Default is <code>50</code>.</p>
  41. </td>
  42. </tr>
  43. <tr>
  44. <td class="name">
  45. <strong>aspect</strong>
  46. </td>
  47. <td class="description last">
  48. <p>The aspect ratio.</p>
  49. <p>Default is <code>1</code>.</p>
  50. </td>
  51. </tr>
  52. <tr>
  53. <td class="name">
  54. <strong>near</strong>
  55. </td>
  56. <td class="description last">
  57. <p>The camera's near plane.</p>
  58. <p>Default is <code>0.1</code>.</p>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td class="name">
  63. <strong>far</strong>
  64. </td>
  65. <td class="description last">
  66. <p>The camera's far plane.</p>
  67. <p>Default is <code>2000</code>.</p>
  68. </td>
  69. </tr>
  70. </tbody>
  71. </table>
  72. </div>
  73. </div>
  74. <h2 class="subsection-title">Properties</h2>
  75. <div class="member">
  76. <h3 class="name" id="aspect" translate="no">.<a href="#aspect">aspect</a><span class="type-signature"> : number</span> </h3>
  77. <div class="description">
  78. <p>The aspect ratio, usually the canvas width / canvas height.</p>
  79. <p>Default is <code>1</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <h3 class="name" id="far" translate="no">.<a href="#far">far</a><span class="type-signature"> : number</span> </h3>
  84. <div class="description">
  85. <p>The camera's far plane. Must be greater than the
  86. current value of <a href="PerspectiveCamera.html#near">PerspectiveCamera#near</a>.</p>
  87. <p>Default is <code>2000</code>.</p>
  88. </div>
  89. </div>
  90. <div class="member">
  91. <h3 class="name" id="filmGauge" translate="no">.<a href="#filmGauge">filmGauge</a><span class="type-signature"> : number</span> </h3>
  92. <div class="description">
  93. <p>Film size used for the larger axis. Default is <code>35</code> (millimeters). This
  94. parameter does not influence the projection matrix unless <a href="PerspectiveCamera.html#filmOffset">PerspectiveCamera#filmOffset</a>
  95. is set to a nonzero value.</p>
  96. <p>Default is <code>35</code>.</p>
  97. </div>
  98. </div>
  99. <div class="member">
  100. <h3 class="name" id="filmOffset" translate="no">.<a href="#filmOffset">filmOffset</a><span class="type-signature"> : number</span> </h3>
  101. <div class="description">
  102. <p>Horizontal off-center offset in the same unit as <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  103. <p>Default is <code>0</code>.</p>
  104. </div>
  105. </div>
  106. <div class="member">
  107. <h3 class="name" id="focus" translate="no">.<a href="#focus">focus</a><span class="type-signature"> : number</span> </h3>
  108. <div class="description">
  109. <p>Object distance used for stereoscopy and depth-of-field effects. This
  110. parameter does not influence the projection matrix unless a
  111. <a href="StereoCamera.html">StereoCamera</a> is being used.</p>
  112. <p>Default is <code>10</code>.</p>
  113. </div>
  114. </div>
  115. <div class="member">
  116. <h3 class="name" id="fov" translate="no">.<a href="#fov">fov</a><span class="type-signature"> : number</span> </h3>
  117. <div class="description">
  118. <p>The vertical field of view, from bottom to top of view,
  119. in degrees.</p>
  120. <p>Default is <code>50</code>.</p>
  121. </div>
  122. </div>
  123. <div class="member">
  124. <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>
  125. <div class="description">
  126. <p>This flag can be used for type testing.</p>
  127. <p>Default is <code>true</code>.</p>
  128. </div>
  129. </div>
  130. <div class="member">
  131. <h3 class="name" id="near" translate="no">.<a href="#near">near</a><span class="type-signature"> : number</span> </h3>
  132. <div class="description">
  133. <p>The camera's near plane. The valid range is greater than <code>0</code>
  134. and less than the current value of <a href="PerspectiveCamera.html#far">PerspectiveCamera#far</a>.</p>
  135. <p>Note that, unlike for the <a href="OrthographicCamera.html">OrthographicCamera</a>, <code>0</code> is <em>not</em> a
  136. valid value for a perspective camera's near plane.</p>
  137. <p>Default is <code>0.1</code>.</p>
  138. </div>
  139. </div>
  140. <div class="member">
  141. <h3 class="name" id="view" translate="no">.<a href="#view">view</a><span class="type-signature"> : Object</span> </h3>
  142. <div class="description">
  143. <p>Represents the frustum window specification. This property should not be edited
  144. directly but via <a href="PerspectiveCamera.html#setViewOffset">PerspectiveCamera#setViewOffset</a> and <a href="PerspectiveCamera.html#clearViewOffset">PerspectiveCamera#clearViewOffset</a>.</p>
  145. <p>Default is <code>null</code>.</p>
  146. </div>
  147. </div>
  148. <div class="member">
  149. <h3 class="name" id="zoom" translate="no">.<a href="#zoom">zoom</a><span class="type-signature"> : number</span> </h3>
  150. <div class="description">
  151. <p>The zoom factor of the camera.</p>
  152. <p>Default is <code>1</code>.</p>
  153. </div>
  154. </div>
  155. <h2 class="subsection-title">Methods</h2>
  156. <h3 class="name name-method" id="clearViewOffset" translate="no">.<a href="#clearViewOffset">clearViewOffset</a><span class="signature">()</span> </h3>
  157. <div class="method">
  158. <div class="description">
  159. <p>Removes the view offset from the projection matrix.</p>
  160. </div>
  161. </div>
  162. <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>
  163. <div class="method">
  164. <div class="description">
  165. <p>Returns the current vertical field of view angle in degrees considering <a href="PerspectiveCamera.html#zoom">PerspectiveCamera#zoom</a>.</p>
  166. </div>
  167. <dl class="details">
  168. <dt class="tag-returns"><strong>Returns:</strong> The effective FOV.</dt>
  169. </dl>
  170. </div>
  171. <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>
  172. <div class="method">
  173. <div class="description">
  174. <p>Returns the height of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
  175. equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  176. </div>
  177. <dl class="details">
  178. <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
  179. </dl>
  180. </div>
  181. <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>
  182. <div class="method">
  183. <div class="description">
  184. <p>Returns the width of the image on the film. If <a href="PerspectiveCamera.html#aspect">PerspectiveCamera#aspect</a> is greater than or
  185. equal to one (landscape format), the result equals <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  186. </div>
  187. <dl class="details">
  188. <dt class="tag-returns"><strong>Returns:</strong> The film width.</dt>
  189. </dl>
  190. </div>
  191. <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>
  192. <div class="method">
  193. <div class="description">
  194. <p>Returns the focal length from the current <a href="PerspectiveCamera.html#fov">PerspectiveCamera#fov</a> and
  195. <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  196. </div>
  197. <dl class="details">
  198. <dt class="tag-returns"><strong>Returns:</strong> The computed focal length.</dt>
  199. </dl>
  200. </div>
  201. <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>
  202. <div class="method">
  203. <div class="description">
  204. <p>Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  205. Sets <code>minTarget</code> and <code>maxTarget</code> to the coordinates of the lower-left and upper-right corners of the view rectangle.</p>
  206. </div>
  207. <table class="params">
  208. <tbody>
  209. <tr>
  210. <td class="name">
  211. <strong>distance</strong>
  212. </td>
  213. <td class="description last">
  214. <p>The viewing distance.</p>
  215. </td>
  216. </tr>
  217. <tr>
  218. <td class="name">
  219. <strong>minTarget</strong>
  220. </td>
  221. <td class="description last">
  222. <p>The lower-left corner of the view rectangle is written into this vector.</p>
  223. </td>
  224. </tr>
  225. <tr>
  226. <td class="name">
  227. <strong>maxTarget</strong>
  228. </td>
  229. <td class="description last">
  230. <p>The upper-right corner of the view rectangle is written into this vector.</p>
  231. </td>
  232. </tr>
  233. </tbody>
  234. </table>
  235. </div>
  236. <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>
  237. <div class="method">
  238. <div class="description">
  239. <p>Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.</p>
  240. </div>
  241. <table class="params">
  242. <tbody>
  243. <tr>
  244. <td class="name">
  245. <strong>distance</strong>
  246. </td>
  247. <td class="description last">
  248. <p>The viewing distance.</p>
  249. </td>
  250. </tr>
  251. <tr>
  252. <td class="name">
  253. <strong>target</strong>
  254. </td>
  255. <td class="description last">
  256. <p>The target vector that is used to store result where x is width and y is height.</p>
  257. </td>
  258. </tr>
  259. </tbody>
  260. </table>
  261. <dl class="details">
  262. <dt class="tag-returns"><strong>Returns:</strong> The view size.</dt>
  263. </dl>
  264. </div>
  265. <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>
  266. <div class="method">
  267. <div class="description">
  268. <p>Sets the FOV by focal length in respect to the current <a href="PerspectiveCamera.html#filmGauge">PerspectiveCamera#filmGauge</a>.</p>
  269. <p>The default film gauge is 35, so that the focal length can be specified for
  270. a 35mm (full frame) camera.</p>
  271. </div>
  272. <table class="params">
  273. <tbody>
  274. <tr>
  275. <td class="name">
  276. <strong>focalLength</strong>
  277. </td>
  278. <td class="description last">
  279. <p>Values for focal length and film gauge must have the same unit.</p>
  280. </td>
  281. </tr>
  282. </tbody>
  283. </table>
  284. </div>
  285. <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>
  286. <div class="method">
  287. <div class="description">
  288. <p>Sets an offset in a larger frustum. This is useful for multi-window or
  289. multi-monitor/multi-machine setups.</p>
  290. <p>For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  291. the monitors are in grid like this</p>
  292. <pre class="prettyprint source"><code> +---+---+---+
  293. | A | B | C |
  294. +---+---+---+
  295. | D | E | F |
  296. +---+---+---+
  297. </code></pre>
  298. <p>then for each monitor you would call it like this:</p>
  299. <pre><code class="language-js">const w = 1920;
  300. const h = 1080;
  301. const fullWidth = w * 3;
  302. const fullHeight = h * 2;
  303. // --A--
  304. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  305. // --B--
  306. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  307. // --C--
  308. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  309. // --D--
  310. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  311. // --E--
  312. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  313. // --F--
  314. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  315. </code></pre>
  316. <p>Note there is no reason monitors have to be the same size or in a grid.</p>
  317. </div>
  318. <table class="params">
  319. <tbody>
  320. <tr>
  321. <td class="name">
  322. <strong>fullWidth</strong>
  323. </td>
  324. <td class="description last">
  325. <p>The full width of multiview setup.</p>
  326. </td>
  327. </tr>
  328. <tr>
  329. <td class="name">
  330. <strong>fullHeight</strong>
  331. </td>
  332. <td class="description last">
  333. <p>The full height of multiview setup.</p>
  334. </td>
  335. </tr>
  336. <tr>
  337. <td class="name">
  338. <strong>x</strong>
  339. </td>
  340. <td class="description last">
  341. <p>The horizontal offset of the subcamera.</p>
  342. </td>
  343. </tr>
  344. <tr>
  345. <td class="name">
  346. <strong>y</strong>
  347. </td>
  348. <td class="description last">
  349. <p>The vertical offset of the subcamera.</p>
  350. </td>
  351. </tr>
  352. <tr>
  353. <td class="name">
  354. <strong>width</strong>
  355. </td>
  356. <td class="description last">
  357. <p>The width of subcamera.</p>
  358. </td>
  359. </tr>
  360. <tr>
  361. <td class="name">
  362. <strong>height</strong>
  363. </td>
  364. <td class="description last">
  365. <p>The height of subcamera.</p>
  366. </td>
  367. </tr>
  368. </tbody>
  369. </table>
  370. </div>
  371. <h3 class="name name-method" id="updateProjectionMatrix" translate="no">.<a href="#updateProjectionMatrix">updateProjectionMatrix</a><span class="signature">()</span> </h3>
  372. <div class="method">
  373. <div class="description">
  374. <p>Updates the camera's projection matrix. Must be called after any change of
  375. camera properties.</p>
  376. </div>
  377. </div>
  378. <h2 class="subsection-title">Source</h2>
  379. <p>
  380. <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>
  381. </p>
  382. </article>
  383. </section>
  384. <script src="../scripts/linenumber.js"></script>
  385. <script src="../scripts/page.js"></script>
  386. </body>
  387. </html>
粤ICP备19079148号