babylon.deviceOrientationCamera.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module BABYLON {
  2. // We're mainly based on the logic defined into the FreeCamera code
  3. export class DeviceOrientationCamera extends FreeCamera {
  4. // private _offsetX: number = null;
  5. // private _offsetY: number = null;
  6. // private _orientationGamma: number = 0;
  7. // private _orientationBeta: number = 0;
  8. // private _initialOrientationGamma: number = 0;
  9. // private _initialOrientationBeta: number = 0;
  10. // private _attachedCanvas: HTMLCanvasElement;
  11. // private _orientationChanged: (e: DeviceOrientationEvent) => any;
  12. //
  13. // @serialize()
  14. // public angularSensibility: number = 10000.0;
  15. //
  16. // @serialize()
  17. // public moveSensibility: number = 50.0;
  18. constructor(name: string, position: Vector3, scene: Scene) {
  19. super(name, position, scene);
  20. this.inputs.addDeviceOrientation();
  21. // window.addEventListener("resize", () => {
  22. // this._initialOrientationGamma = null;
  23. // }, false);
  24. }
  25. // public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
  26. // if (this._attachedCanvas) {
  27. // return;
  28. // }
  29. // this._attachedCanvas = canvas;
  30. //
  31. // if (!this._orientationChanged) {
  32. // this._orientationChanged = (evt) => {
  33. //
  34. // if (!this._initialOrientationGamma) {
  35. // this._initialOrientationGamma = evt.gamma;
  36. // this._initialOrientationBeta = evt.beta;
  37. // }
  38. //
  39. // this._orientationGamma = evt.gamma;
  40. // this._orientationBeta = evt.beta;
  41. //
  42. // this._offsetY = (this._initialOrientationBeta - this._orientationBeta);
  43. // this._offsetX = (this._initialOrientationGamma - this._orientationGamma);
  44. // };
  45. // }
  46. //
  47. // window.addEventListener("deviceorientation", this._orientationChanged);
  48. // }
  49. //
  50. // public detachControl(canvas: HTMLCanvasElement): void {
  51. // if (this._attachedCanvas !== canvas) {
  52. // return;
  53. // }
  54. //
  55. // window.removeEventListener("deviceorientation", this._orientationChanged);
  56. //
  57. // this._attachedCanvas = null;
  58. // this._orientationGamma = 0;
  59. // this._orientationBeta = 0;
  60. // this._initialOrientationGamma = 0;
  61. // this._initialOrientationBeta = 0;
  62. // }
  63. //
  64. // public _checkInputs(): void {
  65. // if (!this._offsetX) {
  66. // return;
  67. // }
  68. // this.cameraRotation.y -= this._offsetX / this.angularSensibility;
  69. //
  70. // var speed = this._computeLocalCameraSpeed();
  71. // var direction = new Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
  72. //
  73. // Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
  74. // this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
  75. //
  76. // super._checkInputs();
  77. // }
  78. public getTypeName(): string {
  79. return "DeviceOrientationCamera";
  80. }
  81. }
  82. }