touchCamera.ts 2.8 KB

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