您好我如何将加速度计0点设置为用户位置/他持有的天使? 我正在使用:
delta = -40/180*math.pi --
cos_delta, sin_delta = math.cos(delta), math.sin(delta)
要偏移是,但我可以确定设备被盗的天使是0
#额外代码:
-- Speed of Movement with tilt. You can change it ans see the effects.
tiltSpeed = 30;
motionx = 0;
motiony = 0;
rotation = 0;
--delta = -50/180*math.pi -- 30 degrees, maybe should have minus sign
--cos_delta, sin_delta = math.cos(delta), math.sin(delta)
-- Firstly, you need to get accelerometer's values in "zero position"
-- probably, inside onTilt event
local gy, gz = event.yGravity, event.zGravity
local len = math.sqrt(gy*gy+gz*gz) * (gz < 0 and -1 or 1)
cos_delta = gz / len
sin_delta = -gy / len
local function onTilt(event)
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
答案 0 :(得分:1)
-- Firstly, you need to get accelerometer's values in "zero position"
-- probably, inside onTilt event
local gy, gz = event.yGravity, event.zGravity
-- Secondly, update your cos_delta and sin_delta to remember "zero position"
local len = math.sqrt(gy*gy+gz*gz) * (gz < 0 and -1 or 1)
cos_delta = gz / len
sin_delta = -gy / len