1

嗨,我怎样才能将加速度计 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
4

1 回答 1

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
于 2013-07-21T03:55:27.907 回答