|
@@ -5,12 +5,12 @@
|
|
|
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
|
|
|
*/
|
|
|
|
|
|
-THREE.DeviceOrientationControls = function( object ) {
|
|
|
+THREE.DeviceOrientationControls = function ( object ) {
|
|
|
|
|
|
var scope = this;
|
|
|
|
|
|
this.object = object;
|
|
|
- this.object.rotation.reorder( "YXZ" );
|
|
|
+ this.object.rotation.reorder( 'YXZ' );
|
|
|
|
|
|
this.enabled = true;
|
|
|
|
|
@@ -19,13 +19,13 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
this.alphaOffset = 0; // radians
|
|
|
|
|
|
- var onDeviceOrientationChangeEvent = function( event ) {
|
|
|
+ var onDeviceOrientationChangeEvent = function ( event ) {
|
|
|
|
|
|
scope.deviceOrientation = event;
|
|
|
|
|
|
};
|
|
|
|
|
|
- var onScreenOrientationChangeEvent = function() {
|
|
|
+ var onScreenOrientationChangeEvent = function () {
|
|
|
|
|
|
scope.screenOrientation = window.orientation || 0;
|
|
|
|
|
@@ -33,7 +33,7 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
|
|
|
|
|
|
- var setObjectQuaternion = function() {
|
|
|
+ var setObjectQuaternion = function () {
|
|
|
|
|
|
var zee = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
|
@@ -43,7 +43,7 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
|
|
|
|
|
|
- return function( quaternion, alpha, beta, gamma, orient ) {
|
|
|
+ return function ( quaternion, alpha, beta, gamma, orient ) {
|
|
|
|
|
|
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
|
|
|
|
|
@@ -53,11 +53,11 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
}();
|
|
|
|
|
|
- this.connect = function() {
|
|
|
+ this.connect = function () {
|
|
|
|
|
|
onScreenOrientationChangeEvent(); // run once on load
|
|
|
|
|
@@ -68,7 +68,7 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.disconnect = function() {
|
|
|
+ this.disconnect = function () {
|
|
|
|
|
|
window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
|
|
|
window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
|
|
@@ -77,7 +77,7 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.update = function() {
|
|
|
+ this.update = function () {
|
|
|
|
|
|
if ( scope.enabled === false ) return;
|
|
|
|
|
@@ -100,7 +100,7 @@ THREE.DeviceOrientationControls = function( object ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.dispose = function() {
|
|
|
+ this.dispose = function () {
|
|
|
|
|
|
scope.disconnect();
|
|
|
|