flyCamera.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import type { Scene } from "../scene";
  2. import type { Quaternion } from "../Maths/math.vector";
  3. import { Vector3 } from "../Maths/math.vector";
  4. import type { AbstractMesh } from "../Meshes/abstractMesh";
  5. import { TargetCamera } from "./targetCamera";
  6. import { FlyCameraInputsManager } from "./flyCameraInputsManager";
  7. /**
  8. * This is a flying camera, designed for 3D movement and rotation in all directions,
  9. * such as in a 3D Space Shooter or a Flight Simulator.
  10. */
  11. export declare class FlyCamera extends TargetCamera {
  12. /**
  13. * Define the collision ellipsoid of the camera.
  14. * This is helpful for simulating a camera body, like a player's body.
  15. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_collisions#arcrotatecamera
  16. */
  17. ellipsoid: Vector3;
  18. /**
  19. * Define an offset for the position of the ellipsoid around the camera.
  20. * This can be helpful if the camera is attached away from the player's body center,
  21. * such as at its head.
  22. */
  23. ellipsoidOffset: Vector3;
  24. /**
  25. * Enable or disable collisions of the camera with the rest of the scene objects.
  26. */
  27. checkCollisions: boolean;
  28. /**
  29. * Enable or disable gravity on the camera.
  30. */
  31. applyGravity: boolean;
  32. /**
  33. * Define the current direction the camera is moving to.
  34. */
  35. cameraDirection: Vector3;
  36. /**
  37. * Define the current local rotation of the camera as a quaternion to prevent Gimbal lock.
  38. * This overrides and empties cameraRotation.
  39. */
  40. rotationQuaternion: Quaternion;
  41. /**
  42. * Track Roll to maintain the wanted Rolling when looking around.
  43. */
  44. _trackRoll: number;
  45. /**
  46. * Slowly correct the Roll to its original value after a Pitch+Yaw rotation.
  47. */
  48. rollCorrect: number;
  49. /**
  50. * Mimic a banked turn, Rolling the camera when Yawing.
  51. * It's recommended to use rollCorrect = 10 for faster banking correction.
  52. */
  53. bankedTurn: boolean;
  54. /**
  55. * Limit in radians for how much Roll banking will add. (Default: 90°)
  56. */
  57. bankedTurnLimit: number;
  58. /**
  59. * Value of 0 disables the banked Roll.
  60. * Value of 1 is equal to the Yaw angle in radians.
  61. */
  62. bankedTurnMultiplier: number;
  63. /**
  64. * The inputs manager loads all the input sources, such as keyboard and mouse.
  65. */
  66. inputs: FlyCameraInputsManager;
  67. /**
  68. * Gets the input sensibility for mouse input.
  69. * Higher values reduce sensitivity.
  70. */
  71. get angularSensibility(): number;
  72. /**
  73. * Sets the input sensibility for a mouse input.
  74. * Higher values reduce sensitivity.
  75. */
  76. set angularSensibility(value: number);
  77. /**
  78. * Get the keys for camera movement forward.
  79. */
  80. get keysForward(): number[];
  81. /**
  82. * Set the keys for camera movement forward.
  83. */
  84. set keysForward(value: number[]);
  85. /**
  86. * Get the keys for camera movement backward.
  87. */
  88. get keysBackward(): number[];
  89. set keysBackward(value: number[]);
  90. /**
  91. * Get the keys for camera movement up.
  92. */
  93. get keysUp(): number[];
  94. /**
  95. * Set the keys for camera movement up.
  96. */
  97. set keysUp(value: number[]);
  98. /**
  99. * Get the keys for camera movement down.
  100. */
  101. get keysDown(): number[];
  102. /**
  103. * Set the keys for camera movement down.
  104. */
  105. set keysDown(value: number[]);
  106. /**
  107. * Get the keys for camera movement left.
  108. */
  109. get keysLeft(): number[];
  110. /**
  111. * Set the keys for camera movement left.
  112. */
  113. set keysLeft(value: number[]);
  114. /**
  115. * Set the keys for camera movement right.
  116. */
  117. get keysRight(): number[];
  118. /**
  119. * Set the keys for camera movement right.
  120. */
  121. set keysRight(value: number[]);
  122. /**
  123. * Event raised when the camera collides with a mesh in the scene.
  124. */
  125. onCollide: (collidedMesh: AbstractMesh) => void;
  126. private _collider;
  127. private _needMoveForGravity;
  128. private _oldPosition;
  129. private _diffPosition;
  130. private _newPosition;
  131. /** @internal */
  132. _localDirection: Vector3;
  133. /** @internal */
  134. _transformedDirection: Vector3;
  135. /**
  136. * Instantiates a FlyCamera.
  137. * This is a flying camera, designed for 3D movement and rotation in all directions,
  138. * such as in a 3D Space Shooter or a Flight Simulator.
  139. * @param name Define the name of the camera in the scene.
  140. * @param position Define the starting position of the camera in the scene.
  141. * @param scene Define the scene the camera belongs to.
  142. * @param setActiveOnSceneIfNoneActive Defines whether the camera should be marked as active, if no other camera has been defined as active.
  143. */
  144. constructor(name: string, position: Vector3, scene?: Scene, setActiveOnSceneIfNoneActive?: boolean);
  145. /**
  146. * Attach the input controls to a specific dom element to get the input from.
  147. * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
  148. */
  149. attachControl(noPreventDefault?: boolean): void;
  150. /**
  151. * Detach a control from the HTML DOM element.
  152. * The camera will stop reacting to that input.
  153. */
  154. detachControl(): void;
  155. private _collisionMask;
  156. /**
  157. * Get the mask that the camera ignores in collision events.
  158. */
  159. get collisionMask(): number;
  160. /**
  161. * Set the mask that the camera ignores in collision events.
  162. */
  163. set collisionMask(mask: number);
  164. /**
  165. * @internal
  166. */
  167. _collideWithWorld(displacement: Vector3): void;
  168. /**
  169. * @internal
  170. */
  171. private _onCollisionPositionChange;
  172. /** @internal */
  173. _checkInputs(): void;
  174. /**
  175. * Enable movement without a user input. This allows gravity to always be applied.
  176. */
  177. set needMoveForGravity(value: boolean);
  178. /**
  179. * When true, gravity is applied whether there is user input or not.
  180. */
  181. get needMoveForGravity(): boolean;
  182. /** @internal */
  183. _decideIfNeedsToMove(): boolean;
  184. /** @internal */
  185. _updatePosition(): void;
  186. /**
  187. * Restore the Roll to its target value at the rate specified.
  188. * @param rate - Higher means slower restoring.
  189. * @internal
  190. */
  191. restoreRoll(rate: number): void;
  192. /**
  193. * Destroy the camera and release the current resources held by it.
  194. */
  195. dispose(): void;
  196. /**
  197. * Get the current object class name.
  198. * @returns the class name.
  199. */
  200. getClassName(): string;
  201. }