I'm trying to smooth the compass movement of an app using the HTML5 Compass API.
I understood I need to make a low-pass filter, I found this wich seems to be perfect http://ift.tt/1DAaQjA :
onSensorChanged(angle) {
lastSin = smoothingFactor * lastSin + (1-smoothingFactor) * sin(angle)
lastCos = smoothingFactor * lastCos + (1-smoothingFactor) * cos(angle)
}
getAngle() {
return atan2(lastSin, lastCos)
}
but I can't make it work using javascript.
Currently I have something like that :
var compass = document.getElementById('compass');
if(window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', function(event) {
alpha = event.alpha;
compass.style.Transform = 'rotate(' + alpha + 'deg)';
}
}
Any suggestions appreciated.
Aucun commentaire:
Enregistrer un commentaire