PerspectiveCamera.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Object3D] &rarr; [page:Camera] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. Camera that uses
  14. [link:https://en.wikipedia.org/wiki/Perspective_(graphical) perspective projection].<br /><br />
  15. This projection mode is designed to mimic the way the human eye sees. It
  16. is the most common projection mode used for rendering a 3D scene.
  17. </p>
  18. <h2>Code Example</h2>
  19. <code>
  20. const camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
  21. scene.add( camera );
  22. </code>
  23. <h2>Examples</h2>
  24. <p>
  25. [example:webgl_animation_skinning_blending animation / skinning / blending]<br />
  26. [example:webgl_animation_skinning_morph animation / skinning / morph ]<br />
  27. [example:webgl_effects_stereo effects / stereo ]<br />
  28. [example:webgl_interactive_cubes interactive / cubes ]<br />
  29. [example:webgl_loader_collada_skinning loader / collada / skinning ]
  30. </p>
  31. <h2>Constructor</h2>
  32. <h3>[name]( [param:Number fov], [param:Number aspect], [param:Number near], [param:Number far] )</h3>
  33. <p>
  34. fov — Camera frustum vertical field of view.<br />
  35. aspect — Camera frustum aspect ratio.<br />
  36. near — Camera frustum near plane.<br />
  37. far — Camera frustum far plane.<br /><br />
  38. Together these define the camera's
  39. [link:https://en.wikipedia.org/wiki/Viewing_frustum viewing frustum].
  40. </p>
  41. <h2>Properties</h2>
  42. <p>
  43. See the base [page:Camera] class for common properties.<br />
  44. Note that after making changes to most of these properties you will have
  45. to call [page:PerspectiveCamera.updateProjectionMatrix .updateProjectionMatrix] for the changes to take effect.
  46. </p>
  47. <h3>[property:Float aspect]</h3>
  48. <p>
  49. Camera frustum aspect ratio, usually the canvas width / canvas height.
  50. Default is `1` (square canvas).
  51. </p>
  52. <h3>[property:Float far]</h3>
  53. <p>
  54. Camera frustum far plane. Default is `2000`.<br /><br />
  55. Must be greater than the current value of [page:.near near] plane.
  56. </p>
  57. <h3>[property:Float filmGauge]</h3>
  58. <p>
  59. Film size used for the larger axis. Default is `35` (millimeters). This
  60. parameter does not influence the projection matrix unless .filmOffset is
  61. set to a nonzero value.
  62. </p>
  63. <h3>[property:Float filmOffset]</h3>
  64. <p>
  65. Horizontal off-center offset in the same unit as `.filmGauge`. Default is
  66. `0`.
  67. </p>
  68. <h3>[property:Float focus]</h3>
  69. <p>
  70. Object distance used for stereoscopy and depth-of-field effects. This
  71. parameter does not influence the projection matrix unless a
  72. [page:StereoCamera] is being used. Default is `10`.
  73. </p>
  74. <h3>[property:Float fov]</h3>
  75. <p>
  76. Camera frustum vertical field of view, from bottom to top of view, in
  77. degrees. Default is `50`.
  78. </p>
  79. <h3>[property:Boolean isPerspectiveCamera]</h3>
  80. <p>Read-only flag to check if a given object is of type [name].</p>
  81. <h3>[property:Float near]</h3>
  82. <p>
  83. Camera frustum near plane. Default is `0.1`.<br /><br />
  84. The valid range is greater than `0` and less than the current value of the
  85. [page:.far far] plane. Note that, unlike for the
  86. [page:OrthographicCamera], `0` is <em>not</em> a valid value for a
  87. PerspectiveCamera's near plane.
  88. </p>
  89. <h3>[property:Object view]</h3>
  90. <p>
  91. Frustum window specification or null. This is set using the
  92. [page:PerspectiveCamera.setViewOffset .setViewOffset] method and cleared
  93. using [page:PerspectiveCamera.clearViewOffset .clearViewOffset].
  94. </p>
  95. <h3>[property:number zoom]</h3>
  96. <p>Gets or sets the zoom factor of the camera. Default is `1`.</p>
  97. <h2>Methods</h2>
  98. <p>See the base [page:Camera] class for common methods.</p>
  99. <h3>[method:undefined clearViewOffset]()</h3>
  100. <p>Removes any offset set by the [page:PerspectiveCamera.setViewOffset .setViewOffset] method.</p>
  101. <h3>[method:Float getEffectiveFOV]()</h3>
  102. <p>Returns the current vertical field of view angle in degrees considering .zoom.</p>
  103. <h3>[method:Float getFilmHeight]()</h3>
  104. <p>
  105. Returns the height of the image on the film. If .aspect is less than or
  106. equal to one (portrait format), the result equals .filmGauge.
  107. </p>
  108. <h3>[method:Float getFilmWidth]()</h3>
  109. <p>
  110. Returns the width of the image on the film. If .aspect is greater than or
  111. equal to one (landscape format), the result equals .filmGauge.
  112. </p>
  113. <h3>[method:Float getFocalLength]()</h3>
  114. <p>
  115. Returns the focal length of the current .fov in respect to .filmGauge.
  116. </p>
  117. <h3>[method:undefined setFocalLength]( [param:Float focalLength] )</h3>
  118. <p>
  119. Sets the FOV by focal length in respect to the current
  120. [page:PerspectiveCamera.filmGauge .filmGauge].<br /><br />
  121. By default, the focal length is specified for a 35mm (full frame) camera.
  122. </p>
  123. <h3>[method:undefined getViewBounds]( [param:Float distance], [param:Vector2 minTarget], [param:Vector2 maxTarget] )
  124. </h3>
  125. <p>
  126. Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  127. Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  128. </p>
  129. <h3>[method:Vector2 getViewSize]( [param:Float distance], [param:Vector2 target] )</h3>
  130. <p>
  131. Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  132. Copies the result into the target Vector2, where x is width and y is height.
  133. </p>
  134. <h3>[method:undefined setViewOffset]( [param:Float fullWidth], [param:Float fullHeight], [param:Float x], [param:Float y], [param:Float width], [param:Float height] )</h3>
  135. <p>
  136. fullWidth — full width of multiview setup<br />
  137. fullHeight — full height of multiview setup<br />
  138. x — horizontal offset of subcamera<br />
  139. y — vertical offset of subcamera<br />
  140. width — width of subcamera<br />
  141. height — height of subcamera
  142. </p>
  143. <p>
  144. Sets an offset in a larger frustum. This is useful for multi-window or
  145. multi-monitor/multi-machine setups.
  146. </p>
  147. <p>
  148. For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  149. the monitors are in grid like this:<br />
  150. </p>
  151. <pre>
  152. +---+---+---+
  153. | A | B | C |
  154. +---+---+---+
  155. | D | E | F |
  156. +---+---+---+
  157. </pre>
  158. then for each monitor you would call it like this:<br />
  159. <code>const w = 1920;
  160. const h = 1080;
  161. const fullWidth = w * 3;
  162. const fullHeight = h * 2;
  163. // A
  164. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  165. // B
  166. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  167. // C
  168. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  169. // D
  170. camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  171. // E
  172. camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  173. // F
  174. camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  175. </code>
  176. <p>Note there is no reason monitors have to be the same size or in a grid.</p>
  177. <h3>[method:undefined updateProjectionMatrix]()</h3>
  178. <p>
  179. Updates the camera projection matrix. Must be called after any change of
  180. parameters.
  181. </p>
  182. <h3>[method:Object toJSON]([param:Object meta])</h3>
  183. <p>
  184. meta -- object containing metadata such as textures or images in objects'
  185. descendants.<br />
  186. Convert the camera to three.js
  187. [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].
  188. </p>
  189. <h2>Source</h2>
  190. <p>
  191. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  192. </p>
  193. </body>
  194. </html>