I most often think of rotation of an item like this. Maybe it can be of help for someone? The ship has a position, direction and up, just like the camera input. Then the different turn, roll, yaw rotations can be described like this:
-- 0 Ship
-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)
pos = vec3(0,0,100)
dir = vec3(0,1,0)
up = vec3(0,0,1)
end
function mult(m, v) -- matrix multiplication
return vec3(
m[1]*v.x+m[2]*v.y+m[3]*v.z,
m[5]*v.x+m[6]*v.y+m[7]*v.z,
m[9]*v.x+m[10]*v.y+m[11]*v.z
)
end
function turn(d)
local m = matrix():rotate(d, up.x,up.y,up.z)
dir = mult(m,dir):normalize()
end
function roll(d)
local m = matrix():rotate(d, dir.x,dir.y,dir.z)
up = mult(m,up):normalize()
end
function yaw(d)
local right = dir:cross(up)
local m = matrix():rotate(d, right.x,right.y,right.z)
dir = mult(m,dir):normalize()
up = mult(m, up):normalize()
end
-- This function gets called once every frame
function draw()
background(40, 40, 50)
perspective(80)
local lookAt = pos + dir
camera(pos.x,pos.y,pos.z,
lookAt.x, lookAt.y, lookAt.z,
up.x, up.y, up.z)
sprite("Cargo Bot:Pack Crazy",0,0,1000)
end
function touched(touch)
if touch.state == MOVING then
if math.abs(touch.deltaX) > math.abs(touch.deltaY) then
turn(-touch.deltaX*.5)
else
yaw(touch.deltaY*.5)
end
end
end
But maybe there is a value to try using quats again…