DeviceOrientationControls.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @author richt / http://richt.me
  3. * @author WestLangley / http://github.com/WestLangley
  4. *
  5. * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
  6. */
  7. import THREE from '../../node_modules/three/build/three.module';
  8. console.log(THREE)
  9. // THREE.DeviceOrientationControls = function ( object ) {
  10. // var scope = this;
  11. // this.object = object;
  12. // this.object.rotation.reorder( 'YXZ' );
  13. // this.enabled = true;
  14. // this.deviceOrientation = {};
  15. // this.screenOrientation = 0;
  16. // this.alphaOffset = 0; // radians
  17. // var onDeviceOrientationChangeEvent = function ( event ) {
  18. // scope.deviceOrientation = event;
  19. // };
  20. // var onScreenOrientationChangeEvent = function () {
  21. // scope.screenOrientation = window.orientation || 0;
  22. // };
  23. // // The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
  24. // var setObjectQuaternion = function () {
  25. // var zee = new THREE.Vector3( 0, 0, 1 );
  26. // var euler = new THREE.Euler();
  27. // var q0 = new THREE.Quaternion();
  28. // var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
  29. // return function ( quaternion, alpha, beta, gamma, orient ) {
  30. // euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
  31. // quaternion.setFromEuler( euler ); // orient the device
  32. // quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
  33. // quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
  34. // };
  35. // }();
  36. // this.connect = function () {
  37. // onScreenOrientationChangeEvent(); // run once on load
  38. // window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
  39. // window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
  40. // scope.enabled = true;
  41. // };
  42. // this.disconnect = function () {
  43. // window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
  44. // window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
  45. // scope.enabled = false;
  46. // };
  47. // this.update = function () {
  48. // if ( scope.enabled === false ) return;
  49. // var device = scope.deviceOrientation;
  50. // if ( device ) {
  51. // var alpha = device.alpha ? THREE.Math.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
  52. // var beta = device.beta ? THREE.Math.degToRad( device.beta ) : 0; // X'
  53. // var gamma = device.gamma ? THREE.Math.degToRad( device.gamma ) : 0; // Y''
  54. // var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
  55. // setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
  56. // }
  57. // };
  58. // this.dispose = function () {
  59. // scope.disconnect();
  60. // };
  61. // this.connect();
  62. // };