babylon.touchCamera.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. // We're mainly based on the logic defined into the FreeCamera code
  9. var TouchCamera = (function (_super) {
  10. __extends(TouchCamera, _super);
  11. // private _offsetX: number = null;
  12. // private _offsetY: number = null;
  13. // private _pointerCount:number = 0;
  14. // private _pointerPressed = [];
  15. // private _attachedCanvas: HTMLCanvasElement;
  16. // private _onPointerDown: (e: PointerEvent) => any;
  17. // private _onPointerUp: (e: PointerEvent) => any;
  18. // private _onPointerMove: (e: PointerEvent) => any;
  19. //
  20. // @serialize()
  21. // public touchAngularSensibility: number = 200000.0;
  22. //
  23. // @serialize()
  24. // public touchMoveSensibility: number = 250.0;
  25. function TouchCamera(name, position, scene) {
  26. _super.call(this, name, position, scene);
  27. this.inputs.addTouch();
  28. }
  29. // public _onLostFocus(e: FocusEvent): void {
  30. // this._offsetX = null;
  31. // this._offsetY = null;
  32. // super._onLostFocus(e);
  33. // }
  34. // public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
  35. // var previousPosition;
  36. //
  37. // if (this._attachedCanvas) {
  38. // return;
  39. // }
  40. //
  41. // if (this._onPointerDown === undefined) {
  42. //
  43. // this._onPointerDown = (evt) => {
  44. //
  45. // if (evt.pointerType === "mouse") {
  46. // return;
  47. // }
  48. //
  49. // if (!noPreventDefault) {
  50. // evt.preventDefault();
  51. // }
  52. //
  53. // this._pointerPressed.push(evt.pointerId);
  54. //
  55. // if (this._pointerPressed.length !== 1) {
  56. // return;
  57. // }
  58. //
  59. // previousPosition = {
  60. // x: evt.clientX,
  61. // y: evt.clientY
  62. // };
  63. // };
  64. //
  65. // this._onPointerUp = (evt) => {
  66. //
  67. // if (evt.pointerType === "mouse") {
  68. // return;
  69. // }
  70. //
  71. // if (!noPreventDefault) {
  72. // evt.preventDefault();
  73. // }
  74. //
  75. // var index: number = this._pointerPressed.indexOf(evt.pointerId);
  76. //
  77. // if (index === -1) {
  78. // return;
  79. // }
  80. // this._pointerPressed.splice(index, 1);
  81. //
  82. // if (index != 0) {
  83. // return;
  84. // }
  85. // previousPosition = null;
  86. // this._offsetX = null;
  87. // this._offsetY = null;
  88. // };
  89. //
  90. // this._onPointerMove = (evt) => {
  91. //
  92. // if (evt.pointerType === "mouse") {
  93. // return;
  94. // }
  95. //
  96. // if (!noPreventDefault) {
  97. // evt.preventDefault();
  98. // }
  99. //
  100. // if (!previousPosition) {
  101. // return;
  102. // }
  103. //
  104. // var index: number = this._pointerPressed.indexOf(evt.pointerId);
  105. //
  106. // if (index != 0) {
  107. // return;
  108. // }
  109. //
  110. // this._offsetX = evt.clientX - previousPosition.x;
  111. // this._offsetY = -(evt.clientY - previousPosition.y);
  112. // };
  113. //
  114. //
  115. // }
  116. //
  117. // canvas.addEventListener("pointerdown", this._onPointerDown);
  118. // canvas.addEventListener("pointerup", this._onPointerUp);
  119. // canvas.addEventListener("pointerout", this._onPointerUp);
  120. // canvas.addEventListener("pointermove", this._onPointerMove);
  121. //
  122. // super.attachControl(canvas);
  123. // }
  124. //
  125. // public detachControl(canvas: HTMLCanvasElement): void {
  126. // if (this._attachedCanvas !== canvas) {
  127. // return;
  128. // }
  129. //
  130. // canvas.removeEventListener("pointerdown", this._onPointerDown);
  131. // canvas.removeEventListener("pointerup", this._onPointerUp);
  132. // canvas.removeEventListener("pointerout", this._onPointerUp);
  133. // canvas.removeEventListener("pointermove", this._onPointerMove);
  134. //
  135. // super.detachControl(canvas);
  136. // }
  137. //
  138. // public _checkInputs(): void {
  139. // if (this._offsetX) {
  140. //
  141. // this.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
  142. //
  143. // if (this._pointerPressed.length > 1) {
  144. // this.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
  145. // } else {
  146. // var speed = this._computeLocalCameraSpeed();
  147. // var direction = new Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
  148. //
  149. // Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
  150. // this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
  151. // }
  152. // }
  153. //
  154. // super._checkInputs();
  155. // }
  156. TouchCamera.prototype.getTypeName = function () {
  157. return "TouchCamera";
  158. };
  159. return TouchCamera;
  160. }(BABYLON.FreeCamera));
  161. BABYLON.TouchCamera = TouchCamera;
  162. })(BABYLON || (BABYLON = {}));