babylon.arcrotatecamera.input.vrdeviceorientation.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var ArcRotateCameraVRDeviceOrientationInput = (function () {
  4. function ArcRotateCameraVRDeviceOrientationInput() {
  5. this.alphaCorrection = 1;
  6. this.betaCorrection = 1;
  7. this.gammaCorrection = 1;
  8. this._alpha = 0;
  9. this._beta = 0;
  10. this._gamma = 0;
  11. this._dirty = false;
  12. this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
  13. }
  14. ArcRotateCameraVRDeviceOrientationInput.prototype.attachControl = function (element, noPreventDefault) {
  15. this.camera.attachControl(element, noPreventDefault);
  16. window.addEventListener("deviceorientation", this._deviceOrientationHandler);
  17. };
  18. ArcRotateCameraVRDeviceOrientationInput.prototype._onOrientationEvent = function (evt) {
  19. var camera = this.camera;
  20. this._alpha = +evt.alpha | 0;
  21. this._beta = +evt.beta | 0;
  22. this._gamma = +evt.gamma | 0;
  23. this._dirty = true;
  24. };
  25. ArcRotateCameraVRDeviceOrientationInput.prototype.checkInputs = function () {
  26. if (this._dirty) {
  27. this._dirty = false;
  28. if (this._gamma < 0) {
  29. this._gamma = 180 + this._gamma;
  30. }
  31. this.camera.alpha = (-this._alpha / 180.0 * Math.PI) % Math.PI * 2;
  32. this.camera.beta = (this._gamma / 180.0 * Math.PI);
  33. }
  34. };
  35. ArcRotateCameraVRDeviceOrientationInput.prototype.detachControl = function (element) {
  36. window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
  37. };
  38. ArcRotateCameraVRDeviceOrientationInput.prototype.getTypeName = function () {
  39. return "ArcRotateCameraVRDeviceOrientationInput";
  40. };
  41. ArcRotateCameraVRDeviceOrientationInput.prototype.getSimpleName = function () {
  42. return "VRDeviceOrientation";
  43. };
  44. return ArcRotateCameraVRDeviceOrientationInput;
  45. }());
  46. BABYLON.ArcRotateCameraVRDeviceOrientationInput = ArcRotateCameraVRDeviceOrientationInput;
  47. BABYLON.CameraInputTypes["ArcRotateCameraVRDeviceOrientationInput"] = ArcRotateCameraVRDeviceOrientationInput;
  48. })(BABYLON || (BABYLON = {}));