babylon.oculusController.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.OculusController = function (scene, target) {
  5. BABYLON.inputController.call(this, scene, target);
  6. this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
  7. this._tempOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
  8. this._relativeOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
  9. window.addEventListener("deviceorientation", this._deviceOrientationHandler);
  10. };
  11. BABYLON.OculusController.prototype = Object.create(BABYLON.inputController.prototype);
  12. BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
  13. this._tempOrientation.yaw = ev.alpha / 180 * Math.PI;
  14. this._tempOrientation.pitch = ev.beta / 180 * Math.PI;
  15. this._tempOrientation.roll = ev.gamma / 180 * Math.PI;
  16. if (!this._lastOrientation) {
  17. this._lastOrientation = Object.create(this._tempOrientation);
  18. }
  19. else {
  20. this._relativeOrientation.yaw = this._tempOrientation.yaw - this._lastOrientation.yaw;
  21. this._relativeOrientation.pitch = this._tempOrientation.pitch - this._lastOrientation.pitch;
  22. this._relativeOrientation.roll = this._tempOrientation.roll - this._lastOrientation.roll;
  23. var temp = this._tempOrientation;
  24. this._tempOrientation = this._lastOrientation;
  25. this._lastOrientation = temp;
  26. this.target.rotateRelative(this._relativeOrientation);
  27. }
  28. };
  29. BABYLON.OculusController.prototype.dispose = function () {
  30. window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
  31. };
  32. BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric = {
  33. HResolution: 1280,
  34. VResolution: 800,
  35. HScreenSize: 0.149759993,
  36. VScreenSize: 0.0935999975,
  37. VScreenCenter: 0.0467999987,
  38. EyeToScreenDistance: 0.0410000011,
  39. LensSeparationDistance: 0.0635000020,
  40. InterpupillaryDistance: 0.0640000030,
  41. DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
  42. ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
  43. PostProcessScaleFactor: 1.714605507808412,
  44. LensCenterOffset: 0.151976421
  45. };
  46. })();