babylon.deviceOrientationCamera.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 DeviceOrientationCamera = (function (_super) {
  10. __extends(DeviceOrientationCamera, _super);
  11. function DeviceOrientationCamera(name, position, scene) {
  12. _super.call(this, name, position, scene);
  13. this.inputs.addDeviceOrientation();
  14. }
  15. DeviceOrientationCamera.prototype.getTypeName = function () {
  16. return "DeviceOrientationCamera";
  17. };
  18. DeviceOrientationCamera.prototype._checkInputs = function () {
  19. _super.prototype._checkInputs.call(this);
  20. if (this._initialQuaternion) {
  21. this._quaternionCache.copyFrom(this.rotationQuaternion);
  22. this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
  23. }
  24. };
  25. DeviceOrientationCamera.prototype.resetToCurrentRotation = function (axis) {
  26. var _this = this;
  27. if (axis === void 0) { axis = BABYLON.Axis.Y; }
  28. //can only work if this camera has a rotation quaternion already.
  29. if (!this.rotationQuaternion)
  30. return;
  31. if (!this._initialQuaternion) {
  32. this._initialQuaternion = new BABYLON.Quaternion();
  33. }
  34. this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);
  35. ['x', 'y', 'z'].forEach(function (axisName) {
  36. if (!axis[axisName]) {
  37. _this._initialQuaternion[axisName] = 0;
  38. }
  39. else {
  40. _this._initialQuaternion[axisName] *= -1;
  41. }
  42. });
  43. this._initialQuaternion.normalize();
  44. };
  45. return DeviceOrientationCamera;
  46. }(BABYLON.FreeCamera));
  47. BABYLON.DeviceOrientationCamera = DeviceOrientationCamera;
  48. })(BABYLON || (BABYLON = {}));