PointerLockControls.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>PointerLockControls - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Controls.html">Controls</a> → </p>
  13. <h1 translate="no">PointerLockControls</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>The implementation of this class is based on the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API">Pointer Lock API</a>.
  17. <code>PointerLockControls</code> is a perfect choice for first person 3D games.</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">const controls = new PointerLockControls( camera, document.body );
  20. // add event listener to show/hide a UI (e.g. the game's menu)
  21. controls.addEventListener( 'lock', function () {
  22. menu.style.display = 'none';
  23. } );
  24. controls.addEventListener( 'unlock', function () {
  25. menu.style.display = 'block';
  26. } );
  27. </code></pre></div>
  28. </header>
  29. <article>
  30. <h2 class="subsection-title">Import</h2>
  31. <p><span translate="no">PointerLockControls</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  32. <pre><code class="language-js">import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';</code></pre>
  33. <div class="container-overview">
  34. <h2>Constructor</h2>
  35. <h3 class="name name-method" id="PointerLockControls" translate="no">new <a href="#PointerLockControls">PointerLockControls</a><span class="signature">( camera : <span class="param-type">Camera</span>, domElement : <span class="param-type">HTMLElement</span> )</span> </h3>
  36. <div class="method">
  37. <div class="description">
  38. <p>Constructs a new controls instance.</p>
  39. </div>
  40. <table class="params">
  41. <tbody>
  42. <tr>
  43. <td class="name"><code>camera</code></td>
  44. <td class="description last"><p>The camera that is managed by the controls.</p></td>
  45. </tr>
  46. <tr>
  47. <td class="name"><code>domElement</code></td>
  48. <td class="description last"><p>The HTML element used for event listeners.<br/>Default is <code>null</code>.</p></td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. </div>
  54. <h2 class="subsection-title">Properties</h2>
  55. <div class="member">
  56. <h3 class="name" id="isLocked" translate="no">.<a href="#isLocked">isLocked</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  57. <div class="description">
  58. <p>Whether the controls are locked or not.<br/>Default is <code>false</code>.</p>
  59. </div>
  60. </div>
  61. <div class="member">
  62. <h3 class="name" id="maxPolarAngle" translate="no">.<a href="#maxPolarAngle">maxPolarAngle</a><span class="type-signature"> : number</span> </h3>
  63. <div class="description">
  64. <p>Camera pitch, upper limit. Range is '[0, Math.PI]' in radians.<br/>Default is <code>Math.PI</code>.</p>
  65. </div>
  66. </div>
  67. <div class="member">
  68. <h3 class="name" id="minPolarAngle" translate="no">.<a href="#minPolarAngle">minPolarAngle</a><span class="type-signature"> : number</span> </h3>
  69. <div class="description">
  70. <p>Camera pitch, lower limit. Range is '[0, Math.PI]' in radians.<br/>Default is <code>0</code>.</p>
  71. </div>
  72. </div>
  73. <div class="member">
  74. <h3 class="name" id="pointerSpeed" translate="no">.<a href="#pointerSpeed">pointerSpeed</a><span class="type-signature"> : number</span> </h3>
  75. <div class="description">
  76. <p>Multiplier for how much the pointer movement influences the camera rotation.<br/>Default is <code>1</code>.</p>
  77. </div>
  78. </div>
  79. <h2 class="subsection-title">Methods</h2>
  80. <h3 class="name name-method" id="getDirection" translate="no">.<a href="#getDirection">getDirection</a><span class="signature">( v : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  81. <div class="method">
  82. <div class="description">
  83. <p>Returns the look direction of the camera.</p>
  84. </div>
  85. <table class="params">
  86. <tbody>
  87. <tr>
  88. <td class="name"><code>v</code></td>
  89. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  90. </tr>
  91. </tbody>
  92. </table>
  93. <dl class="details">
  94. <dt class="tag-returns"><strong>Returns:</strong> The normalized direction vector.</dt>
  95. </dl>
  96. </div>
  97. <h3 class="name name-method" id="lock" translate="no">.<a href="#lock">lock</a><span class="signature">( unadjustedMovement : <span class="param-type">boolean</span> )</span> </h3>
  98. <div class="method">
  99. <div class="description">
  100. <p>Activates the pointer lock.</p>
  101. </div>
  102. <table class="params">
  103. <tbody>
  104. <tr>
  105. <td class="name"><code>unadjustedMovement</code></td>
  106. <td class="description last"><p>Disables OS-level adjustment for mouse acceleration, and accesses raw mouse input instead.
  107. Setting it to true will disable mouse acceleration.<br/>Default is <code>false</code>.</p></td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. </div>
  112. <h3 class="name name-method" id="moveForward" translate="no">.<a href="#moveForward">moveForward</a><span class="signature">( distance : <span class="param-type">number</span> )</span> </h3>
  113. <div class="method">
  114. <div class="description">
  115. <p>Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.</p>
  116. </div>
  117. <table class="params">
  118. <tbody>
  119. <tr>
  120. <td class="name"><code>distance</code></td>
  121. <td class="description last"><p>The signed distance.</p></td>
  122. </tr>
  123. </tbody>
  124. </table>
  125. </div>
  126. <h3 class="name name-method" id="moveRight" translate="no">.<a href="#moveRight">moveRight</a><span class="signature">( distance : <span class="param-type">number</span> )</span> </h3>
  127. <div class="method">
  128. <div class="description">
  129. <p>Moves the camera sidewards parallel to the xz-plane.</p>
  130. </div>
  131. <table class="params">
  132. <tbody>
  133. <tr>
  134. <td class="name"><code>distance</code></td>
  135. <td class="description last"><p>The signed distance.</p></td>
  136. </tr>
  137. </tbody>
  138. </table>
  139. </div>
  140. <h3 class="name name-method" id="unlock" translate="no">.<a href="#unlock">unlock</a><span class="signature">()</span> </h3>
  141. <div class="method">
  142. <div class="description">
  143. <p>Exits the pointer lock.</p>
  144. </div>
  145. </div>
  146. <h2 class="subsection-title">Events</h2>
  147. <h3 class="name name-method" id="event:change" translate="no">.<a href="#event:change">change</a> </h3>
  148. <div class="method">
  149. <div class="description">
  150. <p>Fires when the user moves the mouse.</p>
  151. </div>
  152. <h5>Type:</h5>
  153. <ul>
  154. <li>
  155. <span class="param-type">Object</span>
  156. </li>
  157. </ul>
  158. </div>
  159. <h3 class="name name-method" id="event:lock" translate="no">.<a href="#event:lock">lock</a> </h3>
  160. <div class="method">
  161. <div class="description">
  162. <p>Fires when the pointer lock status is &quot;locked&quot; (in other words: the mouse is captured).</p>
  163. </div>
  164. <h5>Type:</h5>
  165. <ul>
  166. <li>
  167. <span class="param-type">Object</span>
  168. </li>
  169. </ul>
  170. </div>
  171. <h3 class="name name-method" id="event:unlock" translate="no">.<a href="#event:unlock">unlock</a> </h3>
  172. <div class="method">
  173. <div class="description">
  174. <p>Fires when the pointer lock status is &quot;unlocked&quot; (in other words: the mouse is not captured anymore).</p>
  175. </div>
  176. <h5>Type:</h5>
  177. <ul>
  178. <li>
  179. <span class="param-type">Object</span>
  180. </li>
  181. </ul>
  182. </div>
  183. <h2 class="subsection-title">Source</h2>
  184. <p>
  185. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js" target="_blank" rel="noopener" translate="no">examples/jsm/controls/PointerLockControls.js</a>
  186. </p>
  187. </article>
  188. </section>
  189. <script src="../scripts/linenumber.js"></script>
  190. <script src="../scripts/page.js"></script>
  191. </body>
  192. </html>
粤ICP备19079148号