universalCamera.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { TouchCamera } from "./touchCamera.js";
  2. import { Node } from "../node.js";
  3. import { Vector3 } from "../Maths/math.vector.js";
  4. import { Camera } from "./camera.js";
  5. import "../Gamepads/gamepadSceneComponent.js";
  6. Node.AddNodeConstructor("FreeCamera", (name, scene) => {
  7. // Forcing to use the Universal camera
  8. return () => new UniversalCamera(name, Vector3.Zero(), scene);
  9. });
  10. /**
  11. * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,
  12. * which still works and will still be found in many Playgrounds.
  13. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera
  14. */
  15. export class UniversalCamera extends TouchCamera {
  16. /**
  17. * Defines the gamepad rotation sensibility.
  18. * This is the threshold from when rotation starts to be accounted for to prevent jittering.
  19. */
  20. get gamepadAngularSensibility() {
  21. const gamepad = this.inputs.attached["gamepad"];
  22. if (gamepad) {
  23. return gamepad.gamepadAngularSensibility;
  24. }
  25. return 0;
  26. }
  27. set gamepadAngularSensibility(value) {
  28. const gamepad = this.inputs.attached["gamepad"];
  29. if (gamepad) {
  30. gamepad.gamepadAngularSensibility = value;
  31. }
  32. }
  33. /**
  34. * Defines the gamepad move sensibility.
  35. * This is the threshold from when moving starts to be accounted for to prevent jittering.
  36. */
  37. get gamepadMoveSensibility() {
  38. const gamepad = this.inputs.attached["gamepad"];
  39. if (gamepad) {
  40. return gamepad.gamepadMoveSensibility;
  41. }
  42. return 0;
  43. }
  44. set gamepadMoveSensibility(value) {
  45. const gamepad = this.inputs.attached["gamepad"];
  46. if (gamepad) {
  47. gamepad.gamepadMoveSensibility = value;
  48. }
  49. }
  50. /**
  51. * The Universal Camera is the one to choose for first person shooter type games, and works with all the keyboard, mouse, touch and gamepads. This replaces the earlier Free Camera,
  52. * which still works and will still be found in many Playgrounds.
  53. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera
  54. * @param name Define the name of the camera in the scene
  55. * @param position Define the start position of the camera in the scene
  56. * @param scene Define the scene the camera belongs to
  57. */
  58. constructor(name, position, scene) {
  59. super(name, position, scene);
  60. this.inputs.addGamepad();
  61. }
  62. /**
  63. * Gets the current object class name.
  64. * @returns the class name
  65. */
  66. getClassName() {
  67. return "UniversalCamera";
  68. }
  69. }
  70. Camera._CreateDefaultParsedCamera = (name, scene) => {
  71. return new UniversalCamera(name, Vector3.Zero(), scene);
  72. };
  73. //# sourceMappingURL=universalCamera.js.map