File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,30 @@ THREE.DeviceOrientationControls = function ( object ) {
3131
3232 this . update = function ( ) {
3333
34+ var compassHeading , fixedAlpha ;
3435 var alpha , beta , gamma ;
3536
3637 return function ( ) {
3738
3839 if ( this . freeze ) return ;
3940
40- alpha = this . deviceOrientation . gamma ? THREE . Math . degToRad ( this . deviceOrientation . alpha ) : 0 ; // Z
41+ //
42+ // iOS compass-calibrated 'alpha' fix
43+ // see: http://lists.w3.org/Archives/Public/public-geolocation/2011Jul/0014.html
44+ //
45+ compassHeading = this . deviceOrientation . webkitCompassHeading || this . deviceOrientation . compassHeading ;
46+ if ( compassHeading ) {
47+
48+ // Switch compassHeading back to 'alpha' representation
49+ fixedAlpha = 360 - compassHeading ;
50+
51+ } else {
52+
53+ fixedAlpha = this . deviceOrientation . alpha || 0 ;
54+
55+ }
56+
57+ alpha = THREE . Math . degToRad ( fixedAlpha ) ; // Z
4158 beta = this . deviceOrientation . beta ? THREE . Math . degToRad ( this . deviceOrientation . beta ) : 0 ; // X'
4259 gamma = this . deviceOrientation . gamma ? THREE . Math . degToRad ( this . deviceOrientation . gamma ) : 0 ; // Y''
4360 orient = this . screenOrientation ? THREE . Math . degToRad ( this . screenOrientation ) : 0 ; // O
You can’t perform that action at this time.
0 commit comments