babylon.vrDeviceOrientationCamera.ts 838 B

1234567891011121314151617181920212223242526272829
  1. module BABYLON {
  2. export class VRDeviceOrientationCamera extends BABYLON.OculusCamera {
  3. public _alpha = 0;
  4. public _beta = 0;
  5. public _gamma = 0;
  6. constructor(name: string, position: Vector3, scene: Scene) {
  7. super(name, position, scene);
  8. }
  9. private _onOrientationEvent(evt: DeviceOrientationEvent): void {
  10. this._alpha = +evt.alpha|0;
  11. this._beta = +evt.beta|0;
  12. this._gamma = +evt.gamma|0;
  13. if (this._gamma < 0) {
  14. this._gamma = 90 + this._gamma;
  15. }
  16. else {
  17. // Incline it in the correct angle.
  18. this._gamma = 270 - this._gamma;
  19. }
  20. this.rotation.x = this._gamma / 180.0 * Math.PI;
  21. this.rotation.y = -this._alpha / 180.0 * Math.PI;
  22. this.rotation.z = this._beta / 180.0 * Math.PI;
  23. }
  24. }
  25. }