PointerLockControls.html 3.5 KB

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