PointerLockControls.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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:EventDispatcher] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. The implementation of this class is based on the [link:https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API Pointer Lock API].
  14. [name] is a perfect choice for first person 3D games.
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. const controls = new PointerLockControls( camera, document.body );
  19. // add event listener to show/hide a UI (e.g. the game's menu)
  20. controls.addEventListener( 'lock', function () {
  21. menu.style.display = 'none';
  22. } );
  23. controls.addEventListener( 'unlock', function () {
  24. menu.style.display = 'block';
  25. } );
  26. </code>
  27. <h2>Examples</h2>
  28. <p>[example:misc_controls_pointerlock misc / controls / pointerlock ]</p>
  29. <h2>Constructor</h2>
  30. <h3>[name]( [param:Camera camera], [param:HTMLDOMElement domElement] )</h3>
  31. <p>
  32. <p>
  33. [page:Camera camera]: The camera of the rendered scene.
  34. </p>
  35. <p>
  36. [page:HTMLDOMElement domElement]: The HTML element used for event listeners.
  37. </p>
  38. <p>
  39. Creates a new instance of [name].
  40. </p>
  41. </p>
  42. <h2>Events</h2>
  43. <h3>change</h3>
  44. <p>
  45. Fires when the user moves the mouse.
  46. </p>
  47. <h3>lock</h3>
  48. <p>
  49. Fires when the pointer lock status is "locked" (in other words: the mouse is captured).
  50. </p>
  51. <h3>unlock</h3>
  52. <p>
  53. Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).
  54. </p>
  55. <h2>Properties</h2>
  56. <h3>[property:HTMLDOMElement domElement]</h3>
  57. <p>
  58. The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will
  59. not set up new event listeners.
  60. </p>
  61. <h3>[property:Boolean isLocked]</h3>
  62. <p>
  63. Whether or not the controls are locked.
  64. </p>
  65. <h3>[property:Float maxPolarAngle]</h3>
  66. <p>
  67. Camera pitch, upper limit. Range is 0 to Math.PI radians. Default is Math.PI.
  68. </p>
  69. <h3>[property:Float minPolarAngle]</h3>
  70. <p>
  71. Camera pitch, lower limit. Range is 0 to Math.PI radians. Default is 0.
  72. </p>
  73. <h3>[property:Float pointerSpeed]</h3>
  74. <p>
  75. Multiplier for how much the pointer movement influences the camera rotation. Default is 1.
  76. </p>
  77. <h2>Methods</h2>
  78. <p>See the base [page:EventDispatcher] class for common methods.</p>
  79. <h3>[method:undefined connect] ()</h3>
  80. <p>
  81. Adds the event listeners of the controls.
  82. </p>
  83. <h3>[method:undefined disconnect] ()</h3>
  84. <p>
  85. Removes the event listeners of the controls.
  86. </p>
  87. <h3>[method:Vector3 getDirection] ( [param:Vector3 target] )</h3>
  88. <p>
  89. <p>
  90. [page:Vector3 target]: The target vector.
  91. </p>
  92. <p>
  93. Returns the look direction of the camera.
  94. </p>
  95. </p>
  96. <h3>[method:undefined lock] ()</h3>
  97. <p>
  98. Activates the pointer lock.
  99. </p>
  100. <h3>[method:undefined moveForward] ( [param:Number distance] )</h3>
  101. <p>
  102. <p>
  103. [page:Number distance]: The signed distance.
  104. </p>
  105. <p>
  106. Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.
  107. </p>
  108. </p>
  109. <h3>[method:undefined moveRight] ( [param:Number distance] )</h3>
  110. <p>
  111. <p>
  112. [page:Number distance]: The signed distance.
  113. </p>
  114. <p>
  115. Moves the camera sidewards parallel to the xz-plane.
  116. </p>
  117. </p>
  118. <h3>[method:undefined unlock] ()</h3>
  119. <p>
  120. Exits the pointer lock.
  121. </p>
  122. <h2>Source</h2>
  123. <p>
  124. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js examples/jsm/controls/PointerLockControls.js]
  125. </p>
  126. </body>
  127. </html>