PointerLockControls.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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" target="_blank" rel="noopener">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" rel="noopener">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"><a href="Camera.html">Camera</a></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">
  44. <strong>camera</strong>
  45. </td>
  46. <td class="description last">
  47. <p>The camera that is managed by the controls.</p>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td class="name">
  52. <strong>domElement</strong>
  53. </td>
  54. <td class="description last">
  55. <p>The HTML element used for event listeners.</p>
  56. <p>Default is <code>null</code>.</p>
  57. </td>
  58. </tr>
  59. </tbody>
  60. </table>
  61. </div>
  62. </div>
  63. <h2 class="subsection-title">Properties</h2>
  64. <div class="member">
  65. <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>
  66. <div class="description">
  67. <p>Whether the controls are locked or not.</p>
  68. <p>Default is <code>false</code>.</p>
  69. </div>
  70. </div>
  71. <div class="member">
  72. <h3 class="name" id="maxPolarAngle" translate="no">.<a href="#maxPolarAngle">maxPolarAngle</a><span class="type-signature"> : number</span> </h3>
  73. <div class="description">
  74. <p>Camera pitch, upper limit. Range is '[0, Math.PI]' in radians.</p>
  75. <p>Default is <code>Math.PI</code>.</p>
  76. </div>
  77. </div>
  78. <div class="member">
  79. <h3 class="name" id="minPolarAngle" translate="no">.<a href="#minPolarAngle">minPolarAngle</a><span class="type-signature"> : number</span> </h3>
  80. <div class="description">
  81. <p>Camera pitch, lower limit. Range is '[0, Math.PI]' in radians.</p>
  82. <p>Default is <code>0</code>.</p>
  83. </div>
  84. </div>
  85. <div class="member">
  86. <h3 class="name" id="pointerSpeed" translate="no">.<a href="#pointerSpeed">pointerSpeed</a><span class="type-signature"> : number</span> </h3>
  87. <div class="description">
  88. <p>Multiplier for how much the pointer movement influences the camera rotation.</p>
  89. <p>Default is <code>1</code>.</p>
  90. </div>
  91. </div>
  92. <h2 class="subsection-title">Methods</h2>
  93. <h3 class="name name-method" id="getDirection" translate="no">.<a href="#getDirection">getDirection</a><span class="signature">( v : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  94. <div class="method">
  95. <div class="description">
  96. <p>Returns the look direction of the camera.</p>
  97. </div>
  98. <table class="params">
  99. <tbody>
  100. <tr>
  101. <td class="name">
  102. <strong>v</strong>
  103. </td>
  104. <td class="description last">
  105. <p>The target vector that is used to store the method's result.</p>
  106. </td>
  107. </tr>
  108. </tbody>
  109. </table>
  110. <dl class="details">
  111. <dt class="tag-returns"><strong>Returns:</strong> The normalized direction vector.</dt>
  112. </dl>
  113. </div>
  114. <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>
  115. <div class="method">
  116. <div class="description">
  117. <p>Activates the pointer lock.</p>
  118. </div>
  119. <table class="params">
  120. <tbody>
  121. <tr>
  122. <td class="name">
  123. <strong>unadjustedMovement</strong>
  124. </td>
  125. <td class="description last">
  126. <p>Disables OS-level adjustment for mouse acceleration, and accesses raw mouse input instead.
  127. Setting it to true will disable mouse acceleration.</p>
  128. <p>Default is <code>false</code>.</p>
  129. </td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. </div>
  134. <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>
  135. <div class="method">
  136. <div class="description">
  137. <p>Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.</p>
  138. </div>
  139. <table class="params">
  140. <tbody>
  141. <tr>
  142. <td class="name">
  143. <strong>distance</strong>
  144. </td>
  145. <td class="description last">
  146. <p>The signed distance.</p>
  147. </td>
  148. </tr>
  149. </tbody>
  150. </table>
  151. </div>
  152. <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>
  153. <div class="method">
  154. <div class="description">
  155. <p>Moves the camera sidewards parallel to the xz-plane.</p>
  156. </div>
  157. <table class="params">
  158. <tbody>
  159. <tr>
  160. <td class="name">
  161. <strong>distance</strong>
  162. </td>
  163. <td class="description last">
  164. <p>The signed distance.</p>
  165. </td>
  166. </tr>
  167. </tbody>
  168. </table>
  169. </div>
  170. <h3 class="name name-method" id="unlock" translate="no">.<a href="#unlock">unlock</a><span class="signature">()</span> </h3>
  171. <div class="method">
  172. <div class="description">
  173. <p>Exits the pointer lock.</p>
  174. </div>
  175. </div>
  176. <h2 class="subsection-title">Events</h2>
  177. <h3 class="name name-method" id="event:change" translate="no">.<a href="#event:change">change</a> </h3>
  178. <div class="method">
  179. <div class="description">
  180. <p>Fires when the user moves the mouse.</p>
  181. </div>
  182. <h5>Type:</h5>
  183. <ul>
  184. <li>
  185. <span class="param-type">Object</span>
  186. </li>
  187. </ul>
  188. </div>
  189. <h3 class="name name-method" id="event:lock" translate="no">.<a href="#event:lock">lock</a> </h3>
  190. <div class="method">
  191. <div class="description">
  192. <p>Fires when the pointer lock status is &quot;locked&quot; (in other words: the mouse is captured).</p>
  193. </div>
  194. <h5>Type:</h5>
  195. <ul>
  196. <li>
  197. <span class="param-type">Object</span>
  198. </li>
  199. </ul>
  200. </div>
  201. <h3 class="name name-method" id="event:unlock" translate="no">.<a href="#event:unlock">unlock</a> </h3>
  202. <div class="method">
  203. <div class="description">
  204. <p>Fires when the pointer lock status is &quot;unlocked&quot; (in other words: the mouse is not captured anymore).</p>
  205. </div>
  206. <h5>Type:</h5>
  207. <ul>
  208. <li>
  209. <span class="param-type">Object</span>
  210. </li>
  211. </ul>
  212. </div>
  213. <h2 class="subsection-title">Source</h2>
  214. <p>
  215. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js" translate="no" target="_blank" rel="noopener">examples/jsm/controls/PointerLockControls.js</a>
  216. </p>
  217. </article>
  218. </section>
  219. <script src="../scripts/linenumber.js"></script>
  220. <script src="../scripts/page.js"></script>
  221. </body>
  222. </html>
粤ICP备19079148号