@@ -36,6 +36,7 @@ class DeviceOrientationControls extends EventDispatcher {
3636 this . screenOrientation = 0 ;
3737
3838 this . alphaOffset = 0 ; // radians
39+ this . initialOffset = null ; // used in fix provided in issue #466, iOS related
3940
4041 this . TWO_PI = 2 * Math . PI ;
4142 this . HALF_PI = 0.5 * Math . PI ;
@@ -142,6 +143,7 @@ class DeviceOrientationControls extends EventDispatcher {
142143 ) ;
143144
144145 scope . enabled = false ;
146+ scope . initialOffset = false ;
145147 scope . deviceOrientation = null ;
146148 } ;
147149
@@ -164,17 +166,17 @@ class DeviceOrientationControls extends EventDispatcher {
164166 : 0 ; // O
165167
166168 if ( isIOS ) {
167- const currentQuaternion = new THREE . Quaternion ( ) ;
169+ const currentQuaternion = new Quaternion ( ) ;
168170 setObjectQuaternion ( currentQuaternion , alpha , beta , gamma , orient ) ;
169171 // Extract the Euler angles from the quaternion and add the heading angle to the Y-axis rotation of the Euler angles
170172 // (If we replace only the alpha value of the quaternion without using Euler angles, the camera will rotate unexpectedly. This is because a quaternion does not represent rotation values individually but rather through a combination of rotation axes and weights.)
171- const currentEuler = new THREE . Euler ( ) . setFromQuaternion (
173+ const currentEuler = new Euler ( ) . setFromQuaternion (
172174 currentQuaternion ,
173175 "YXZ" ,
174176 ) ;
175177 console . log ( currentEuler . x , currentEuler . y , currentEuler . z ) ;
176178 // Replace the current alpha value of the Euler angles and reset the quaternion
177- currentEuler . y = THREE . MathUtils . degToRad (
179+ currentEuler . y = MathUtils . degToRad (
178180 360 - device . webkitCompassHeading ,
179181 ) ;
180182 currentQuaternion . setFromEuler ( currentEuler ) ;
@@ -219,7 +221,8 @@ class DeviceOrientationControls extends EventDispatcher {
219221 ) ;
220222 }
221223
222- // NB - NOT present in IOS fixed version
224+ // NB - NOT present in IOS fixed version issue #466
225+ // Is it needed?
223226 if ( 8 * ( 1 - lastQuaternion . dot ( scope . object . quaternion ) ) > EPS ) {
224227 lastQuaternion . copy ( scope . object . quaternion ) ;
225228 scope . dispatchEvent ( _changeEvent ) ;
@@ -256,10 +259,29 @@ class DeviceOrientationControls extends EventDispatcher {
256259 return newangle ;
257260 } ;
258261
262+ // Provided in fix on issue #466 - iOS related
263+ this . updateAlphaOffset = function ( ) {
264+ scope . initialOffset = false ;
265+ } ;
266+
259267 this . dispose = function ( ) {
260268 scope . disconnect ( ) ;
261269 } ;
262270
271+ // provided with fix on issue #466
272+ this . getAlpha = function ( ) {
273+ const { deviceOrientation : device } = scope ;
274+ return device && device . alpha
275+ ? MathUtils . degToRad ( device . alpha ) + scope . alphaOffset
276+ : 0 ;
277+ } ;
278+
279+ // provided with fix on issue #466
280+ this . getBeta = function ( ) {
281+ const { deviceOrientation : device } = scope ;
282+ return device && device . beta ? MathUtils . degToRad ( device . beta ) : 0 ;
283+ } ;
284+
263285 this . connect ( ) ;
264286 }
265287}
0 commit comments