touchCamera.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { FreeCamera } from "./freeCamera.js";
  2. import { Vector3 } from "../Maths/math.vector.js";
  3. import { Node } from "../node.js";
  4. Node.AddNodeConstructor("TouchCamera", (name, scene) => {
  5. return () => new TouchCamera(name, Vector3.Zero(), scene);
  6. });
  7. /**
  8. * This represents a FPS type of camera controlled by touch.
  9. * This is like a universal camera minus the Gamepad controls.
  10. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera
  11. */
  12. export class TouchCamera extends FreeCamera {
  13. /**
  14. * Defines the touch sensibility for rotation.
  15. * The higher the faster.
  16. */
  17. get touchAngularSensibility() {
  18. const touch = this.inputs.attached["touch"];
  19. if (touch) {
  20. return touch.touchAngularSensibility;
  21. }
  22. return 0;
  23. }
  24. set touchAngularSensibility(value) {
  25. const touch = this.inputs.attached["touch"];
  26. if (touch) {
  27. touch.touchAngularSensibility = value;
  28. }
  29. }
  30. /**
  31. * Defines the touch sensibility for move.
  32. * The higher the faster.
  33. */
  34. get touchMoveSensibility() {
  35. const touch = this.inputs.attached["touch"];
  36. if (touch) {
  37. return touch.touchMoveSensibility;
  38. }
  39. return 0;
  40. }
  41. set touchMoveSensibility(value) {
  42. const touch = this.inputs.attached["touch"];
  43. if (touch) {
  44. touch.touchMoveSensibility = value;
  45. }
  46. }
  47. /**
  48. * Instantiates a new touch camera.
  49. * This represents a FPS type of camera controlled by touch.
  50. * This is like a universal camera minus the Gamepad controls.
  51. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#universal-camera
  52. * @param name Define the name of the camera in the scene
  53. * @param position Define the start position of the camera in the scene
  54. * @param scene Define the scene the camera belongs to
  55. */
  56. constructor(name, position, scene) {
  57. super(name, position, scene);
  58. this.inputs.addTouch();
  59. this._setupInputs();
  60. }
  61. /**
  62. * Gets the current object class name.
  63. * @returns the class name
  64. */
  65. getClassName() {
  66. return "TouchCamera";
  67. }
  68. /** @internal */
  69. _setupInputs() {
  70. const touch = this.inputs.attached["touch"];
  71. const mouse = this.inputs.attached["mouse"];
  72. if (mouse) {
  73. mouse.touchEnabled = false;
  74. }
  75. else {
  76. touch.allowMouse = true;
  77. }
  78. }
  79. }
  80. //# sourceMappingURL=touchCamera.js.map