Fixing iOS Safari Javascript 'deviceorientation' event irregularity? -
i've been using 'deviceorientation' my project , when testing on iphone/ipad, behaves in landscape mode, has irregularity in portrait mode.
here steps repeat:
open jsfiddle on ipad/iphone in portrait mode -
move device though looking through camera , panning looking @ feet, looking @ horizon, looking @ sky
event.beta go 0 -> +/-90 -> 0
notice how event.gamma jumps when device reaches horizon, around when event.beta = 90
q1: how can adjust behaviour?
q2: there way definitive value (eg. 0-180) movement in direction, ground sky?
html
<b>e.alpha :</b> <span id='alpha'></span><br/> <b>e.beta :</b> <span id='beta'></span><br/> <b>e.gamma :</b> <span id='gamma'></span><br/>
js
function deviceorientationhandler(e){ var = document.getelementbyid('alpha'); var b = document.getelementbyid('beta'); var g = document.getelementbyid('gamma'); a.innertext = e.alpha; b.innertext = e.beta; g.innertext = e.gamma; } if (window.deviceorientationevent) { window.addeventlistener('deviceorientation', deviceorientationhandler, false); }else{ console.error('device orientation not supported in browser.'); }
the alpha, beta , gamma values when combined produce direction vector indicates in direction device 'pointing'.
in example, when event.beta
value tips on +/-90 degrees event.alpha
value invert itself. event.alpha
heading of device pointing out of the top of screen heading of device flips when hit horizon. when event.alpha
inverts angle inversion must simultaneously applied 1 of other angles ensure direction vector continues point in right direction.
let's use worked example , our starting deviceorientation {alpha: 270, beta: 89.9, gamma: 0}
. can determine direction vector first rotating around alpha
value, beta
value , gamma
value. if rotate device above horizon, according instructions provided above, heading of device flip 270 degrees 90 degrees.
in new orientation data can not {alpha: 90, beta: 89.9, gamma: 0}
because if use these values determine direction vector (in same way did above) notice direction vector points in opposite direction should be. thus, implementations perform simultaneous flip of axis account flip of 1 axis ensure direction vector continues 'point' in right direction.
the ios implementation sets data in new orientation {alpha: 90, beta: 89.9, gamma: 180}
, direction vector continues point in correct direction.
this reason have observed flip on raw event.gamma
value , correct behaviour , not irregularity.
Comments
Post a Comment