通过event.accelerationIncludingGravity
在Android上使用,它返回一个值
x: -0.2
y: +0.1
z: +9.1
在平坦的表面上休息时。但是,我想在没有重力的情况下获得加速度,但event.acceleration
不支持。有没有办法通过数学转换它?在HTML5Rocks中有一个删除重力因素的示例,但它似乎不起作用。
// Convert the value from acceleration to degrees acceleration. x|y is the
// acceleration according to gravity, we'll assume we're on Earth and divide
// by 9.81 (earth gravity) to get a percentage value, and then multiply that
// by 90 to convert to degrees.
var tiltLR = Math.round(((acceleration.x) / 9.81) * -90);
var tiltFB = Math.round(((acceleration.y + 9.81) / 9.81) * 90 * facingUp);
绘制加速度值的示例脚本(不是来自 HTML5Rocks)