a little program to check how to know the angle the ipad is looking to. Integrating RotationRate is more accurate than i thought it would be.
--# Main
-- test RotationRate
backingMode(RETAINED)
-- Use this function to perform your initial setup
function setup()
drawAngle()
end
local angle = 0
local rotGain = 1
function updateAngle()
local rz = RotationRate.y * DeltaTime * 60
angle = angle + rz * rotGain
end
local lastx,lasty, offset, gain, x,y
function drawAngle(v)
if v then
-- draw new point
x = lastx + 1
y = v * gain + offset
if x > WIDTH then
x = 0
else
stroke(255, 0, 28, 255)
strokeWidth(3)
line(lastx, lasty, x, y)
end
lastx,lasty = x, y
else
-- init
offset = HEIGHT/2
gain = HEIGHT/2/180
lastx,lasty = 0, offset
background(40, 40, 50)
drawScale()
end
end
function drawScale()
local ox,oy = 0, HEIGHT/2
local gx, gy = 1, HEIGHT/2/180
local xmax = WIDTH/gx - ox
local function rline(x,y,z,t) line( x*gx+ox, y*gy+oy, z*gx+ox, t*gy+oy) end
local function rtext(str,x,y) text( str, x*gx+ox, y*gy+oy) end
stroke(164, 164, 164, 255)
strokeWidth(2)
rline(5,-180,5,180)
for i = -180,180,90 do
rline(0,i,xmax,i)
end
for i = -180,180,30 do
rline(0,i,10,i)
rtext(tostring(i),30,i)
end
rtext("Rotation angle in Horizontal plane (hold iPad vertically)", xmax/2, 160)
end
function fpsKiller()
dummy = 0 -- this is a test to kill the fps and check the angle is still ok
for i=1,10 do dummy = dummy + 1 end
end
-- This function gets called once every frame
function draw()
-- drawPoint(RotationRate.y)
updateAngle()
drawAngle(angle)
fpsKiller()
end