@@ -150,53 +150,57 @@ define(function (require){
150150 * </code>
151151 * </div>
152152 */
153+ p5 . prototype . ondeviceorientation = function ( e ) {
154+ this . _setProperty ( 'accelerationX' , e . beta ) ;
155+ this . _setProperty ( 'accelerationY' , e . gamma ) ;
156+ this . _setProperty ( 'accelerationZ' , e . alpha ) ;
157+ this . _handleMotion ( ) ;
158+ } ;
153159 p5 . prototype . ondevicemotion = function ( e ) {
154- this . _setProperty ( 'accelerationX' , e . accelerationIncludingGravity . x ) ;
155- this . _setProperty ( 'accelerationY' , e . accelerationIncludingGravity . y ) ;
156- this . _setProperty ( 'accelerationZ' , e . accelerationIncludingGravity . z ) ;
157-
158- //sets orientation property
159- //device is horizontal
160- if ( window . orientation === 90 || window . orientation === - 90 ) {
160+ this . _setProperty ( 'accelerationX' , e . acceleration . x * 2 ) ;
161+ this . _setProperty ( 'accelerationY' , e . acceleration . y * 2 ) ;
162+ this . _setProperty ( 'accelerationZ' , e . acceleration . z * 2 ) ;
163+ this . _handleMotion ( ) ;
164+ } ;
165+ p5 . prototype . onMozOrientation = function ( e ) {
166+ this . _setProperty ( 'accelerationX' , e . x ) ;
167+ this . _setProperty ( 'accelerationY' , e . y ) ;
168+ this . _setProperty ( 'accelerationZ' , e . z ) ;
169+ this . _handleMotion ( ) ;
170+ } ;
171+ p5 . prototype . _handleMotion = function ( ) {
172+ if ( window . orientation === 90 || window . orientation === - 90 ) {
161173 this . _setProperty ( 'deviceOrientation' , 'landscape' ) ;
162- }
163- else if ( window . orientation === 0 ) { //device is vertical
174+ } else if ( window . orientation === 0 ) {
164175 this . _setProperty ( 'deviceOrientation' , 'portrait' ) ;
165- }
166- else if ( window . orientation === undefined ) {
167- //In case the device doesn't support this function
176+ } else if ( window . orientation === undefined ) {
168177 this . _setProperty ( 'deviceOrientation' , 'undefined' ) ;
169178 }
170-
171179 var onDeviceMove = this . onDeviceMove || window . onDeviceMove ;
172180 if ( typeof onDeviceMove === 'function' ) {
173- if ( Math . abs ( this . accelerationX - this . pAccelerationX ) > move_threshold ||
174- Math . abs ( this . accelerationY - this . pAccelerationY ) > move_threshold ||
175- Math . abs ( this . accelerationZ - this . pAccelerationZ ) > move_threshold ) {
181+ if ( Math . abs ( this . accelerationX - this . pAccelerationX ) > move_threshold ||
182+ Math . abs ( this . accelerationY - this . pAccelerationY ) > move_threshold ||
183+ Math . abs ( this . accelerationZ - this . pAccelerationZ ) > move_threshold ) {
176184 onDeviceMove ( ) ;
177185 }
178186 }
179-
180187 var onDeviceTurn = this . onDeviceTurn || window . onDeviceTurn ;
181188 if ( typeof onDeviceTurn === 'function' ) {
182- //set current_max_axis
183189 var max_val = 0 ;
184- if ( Math . abs ( this . accelerationX ) > max_val ) {
190+ if ( Math . abs ( this . accelerationX ) > max_val ) {
185191 max_val = this . accelerationX ;
186192 new_max_axis = 'x' ;
187193 }
188- if ( Math . abs ( this . accelerationY ) > max_val ) {
194+ if ( Math . abs ( this . accelerationY ) > max_val ) {
189195 max_val = this . accelerationY ;
190196 new_max_axis = 'y' ;
191197 }
192- if ( Math . abs ( this . accelerationZ ) > max_val ) {
193- new_max_axis = 'z' ; //max_val is now irrelevant
198+ if ( Math . abs ( this . accelerationZ ) > max_val ) {
199+ new_max_axis = 'z' ;
194200 }
195-
196- if ( old_max_axis !== '' && old_max_axis !== new_max_axis ) {
201+ if ( old_max_axis !== '' && old_max_axis !== new_max_axis ) {
197202 onDeviceTurn ( new_max_axis ) ;
198203 }
199-
200204 old_max_axis = new_max_axis ;
201205 }
202206 } ;
0 commit comments