PointerLockControls.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. <h2>Methods</h2>
  74. <p>See the base [page:EventDispatcher] class for common methods.</p>
  75. <h3>[method:null connect] ()</h3>
  76. <p>
  77. Adds the event listeners of the controls.
  78. </p>
  79. <h3>[method:null disconnect] ()</h3>
  80. <p>
  81. Removes the event listeners of the controls.
  82. </p>
  83. <h3>[method:Vector3 getDirection] ( [param:Vector3 target] )</h3>
  84. <p>
  85. <p>
  86. [page:Vector3 target]: The target vector.
  87. </p>
  88. <p>
  89. Returns the look direction of the camera.
  90. </p>
  91. </p>
  92. <h3>[method:null lock] ()</h3>
  93. <p>
  94. Activates the pointer lock.
  95. </p>
  96. <h3>[method:null moveForward] ( [param:Number distance] )</h3>
  97. <p>
  98. <p>
  99. [page:Number distance]: The signed distance.
  100. </p>
  101. <p>
  102. Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.
  103. </p>
  104. </p>
  105. <h3>[method:null moveRight] ( [param:Number distance] )</h3>
  106. <p>
  107. <p>
  108. [page:Number distance]: The signed distance.
  109. </p>
  110. <p>
  111. Moves the camera sidewards parallel to the xz-plane.
  112. </p>
  113. </p>
  114. <h3>[method:null unlock] ()</h3>
  115. <p>
  116. Exits the pointer lock.
  117. </p>
  118. <h2>Source</h2>
  119. <p>
  120. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js examples/jsm/controls/PointerLockControls.js]
  121. </p>
  122. </body>
  123. </html>