OrbitControls.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div class="desc">
  13. Orbit controls allow the camera to orbit around a target.<br>
  14. To use this, as with all files in the /examples directory, you will have to
  15. include the file seperately in your HTML.
  16. </div>
  17. <h2>Example</h2>
  18. <div>[example:misc_controls_orbit misc / controls / orbit ]</div>
  19. <code>
  20. var renderer = new THREE.WebGLRenderer();
  21. renderer.setSize( window.innerWidth, window.innerHeight );
  22. document.body.appendChild( renderer.domElement );
  23. var scene = new THREE.Scene();
  24. var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
  25. var controls = new THREE.OrbitControls( camera );
  26. //controls.update() must be called after any manual changes to the camera's transform
  27. camera.position.set( 0, 20, 100 );
  28. controls.update();
  29. function animate() {
  30. requestAnimationFrame( animate );
  31. // required if controls.enableDamping or controls.autoRotate are set to true
  32. controls.update();
  33. renderer.render( scene, camera );
  34. }
  35. </code>
  36. <h2>Constructor</h2>
  37. <h3>[name]( [page:Camera object], [page:HTMLDOMElement domElement] )</h3>
  38. <div>
  39. [page:Camera object]: (required) The camera to be controlled.<br><br>
  40. [page:HTMLDOMElement domElement]: (optional) The HTML element used for event listeners. By default this is the whole document,
  41. however if you only want to the controls to work over a specific element (e.g. the canvas) you can specify that here.
  42. </div>
  43. <h2>Properties</h2>
  44. <h3>[property:Boolean autoRotate]</h3>
  45. <div>
  46. Set to true to automatically rotate around the target.<br> Note that if this is enabled, you must call [page:.update]
  47. () in your animation loop.
  48. </div>
  49. <h3>[property:Float autoRotateSpeed]</h3>
  50. <div>
  51. How fast to rotate around the target if [property:Boolean autoRotate] is true. Default is 2.0, which equates to 30 seconds
  52. per rotation at 60fps.<br> Note that if [property:Boolean autoRotate] is enabled, you must call [page:.update]
  53. () in your animation loop.
  54. </div>
  55. <h3>
  56. [property:Float dampingFactor]</h3>
  57. <div>
  58. The damping inertia used if [property:Boolean enableDamping] is set to true.<br> Note that for this to work, you must
  59. call [page:.update] () in your animation loop.
  60. </div>
  61. <h3>[property:HTMLDOMElement domElement]</h3>
  62. <div>
  63. The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will
  64. not set up new event listeners. Default is the whole document.
  65. </div>
  66. <h3>[property:Boolean enabled]</h3>
  67. <div>
  68. Whether or not the controls are enabled.
  69. </div>
  70. <h3>[property:Boolean enableDamping]</h3>
  71. <div>
  72. Set to true to enable damping (inertia), which can be used to give a sense of weight to the controls. Default is false.<br> Note that if this is enabled, you must call [page:.update] () in your animation loop.
  73. </div>
  74. <h3>[property:Boolean enableKeys]</h3>
  75. <div>
  76. Enable or disable the use of keyboard controls.
  77. </div>
  78. <h3>[property:Boolean enablePan]</h3>
  79. <div>
  80. Enable or disable camera panning. Default is true.
  81. </div>
  82. <h3>[property:Boolean enableRotate]</h3>
  83. <div>
  84. Enable or disable horizontal and vertical rotation of the camera. Default is true.<br>
  85. Note that it is possible to disable a single axis by setting the min and max of the
  86. [page:.minPolarAngle polar angle] or [page:.minAzimuthAngle azimuth angle] to the same value,
  87. which will cause the vertical or horizontal rotation to be fixed at that value.
  88. </div>
  89. <h3>[property:Boolean enableZoom]</h3>
  90. <div>
  91. Enable or disable zooming (dollying) of the camera.
  92. </div>
  93. <h3>[property:Float keyPanSpeed]</h3>
  94. <div>
  95. How fast to pan the camera when the keyboard is used. Default is 7.0 pixels per keypress.
  96. </div>
  97. <h3>[property:Object keys]</h3>
  98. <div>
  99. This object contains references to the keycodes for controlling camera panning. Default is the 4 arrow keys.
  100. <code>
  101. controls.keys = {
  102. LEFT: 37, //left arrow
  103. UP: 38, // up arrow
  104. RIGHT: 39, // right arrow
  105. BOTTOM: 40 // down arrow
  106. }
  107. </code> See [link:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode this page] for a full
  108. list of keycodes.
  109. </div>
  110. <h3>[property:Float maxAzimuthAngle]</h3>
  111. <div>
  112. How far you can orbit horizontally, upper limit. Range is - Math.PI to Math.PI ( or Infinity for no limit ) and default is
  113. Infinity;
  114. </div>
  115. <h3>[property:Float maxDistance]</h3>
  116. <div>
  117. How far you can dolly out ( [page:PerspectiveCamera] only ). Default is Infinity.
  118. </div>
  119. <h3>[property:Float maxPolarAngle]</h3>
  120. <div>
  121. How far you can orbit vertically, upper limit. Range is 0 to Math.PI radians, and default is Math.PI.
  122. </div>
  123. <h3>[property:Float maxZoom]</h3>
  124. <div>
  125. How far you can zoom out ( [page:OrthographicCamera] only ). Default is Infinity.
  126. </div>
  127. <h3>[property:Float minAzimuthAngle]</h3>
  128. <div>
  129. How far you can orbit horizontally, lower limit. Range is - Math.PI to Math.PI ( or - Infinity for no limit ) and default
  130. is - Infinity;
  131. </div>
  132. <h3>[property:Float minDistance]</h3>
  133. <div>
  134. How far you can dolly in ( [page:PerspectiveCamera] only ). Default is 0.
  135. </div>
  136. <h3>[property:Float minPolarAngle]</h3>
  137. <div>
  138. How far you can orbit vertically, lower limit. Range is 0 to Math.PI radians, and default is 0.
  139. </div>
  140. <h3>[property:Float minZoom]</h3>
  141. <div>
  142. How far you can zoom in ( [page:OrthographicCamera] only ). Default is 0.
  143. </div>
  144. <h3>
  145. [property:Object mouseButtons]</h3>
  146. <div>
  147. This object contains references to the mouse buttons used for the controls.
  148. <code>
  149. controls.mouseButtons = {
  150. ORBIT: THREE.MOUSE.LEFT,
  151. ZOOM: THREE.MOUSE.MIDDLE,
  152. PAN: THREE.MOUSE.RIGHT
  153. }
  154. </code>
  155. </div>
  156. <h3>[property:Camera object]</h3>
  157. <div>
  158. The camera ( or other object ) that is being controlled.
  159. </div>
  160. <h3>[property:Vector3 position0]</h3>
  161. <div>
  162. Used internally by the [method:saveState] and [method:reset] methods.
  163. </div>
  164. <h3>[property:Float rotateSpeed]</h3>
  165. <div>
  166. Speed of rotation. Default is 1.
  167. </div>
  168. <h3>[property:Vector3 target0]</h3>
  169. <div>
  170. Used internally by the [method:saveState] and [method:reset] methods.
  171. </div>
  172. <h3>[property:Vector3 target]</h3>
  173. <div>
  174. The focus point of the controls, the [page:.object] orbits around this. It can be updated manually at any point to change
  175. the focus of the controls.
  176. </div>
  177. <h3>[property:Float zoom0]</h3>
  178. <div>
  179. Used internally by the [method:saveState] and [method:reset] methods.
  180. </div>
  181. <h3>[property:Float zoomSpeed]</h3>
  182. <div>
  183. Speed of zooming / dollying. Default is 1.
  184. </div>
  185. <h2>Methods</h2>
  186. <h3>[method:null dispose] ()</h3>
  187. <div>
  188. Remove all the event listeners.
  189. </div>
  190. <h3>[method:radians getAzimuthalAngle] ()</h3>
  191. <div>
  192. Get the current horizontal rotation, in radians.
  193. </div>
  194. <h3>[method:radians getPolarAngle] ()</h3>
  195. <div>
  196. Get the current vertical rotation, in radians.
  197. </div>
  198. <h3>[method:null reset] ()</h3>
  199. <div>
  200. Reset the controls to their state from either the last time the [page:.saveState] was called, or the initial state.
  201. </div>
  202. <h3>[method:null saveState] ()</h3>
  203. <div>
  204. Save the current state of the controls. This can later be recovered with [page:.reset].
  205. </div>
  206. <h3>[method:false update] ()</h3>
  207. <div>
  208. Update the controls. Must be called after any manual changes to the camera's transform,
  209. or in the update loop if [page:.autoRotate] or [page:.enableDamping] are set.
  210. </div>
  211. <h2>Source</h2>
  212. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/[path].js examples/js/[path].js]
  213. </body>
  214. </html>