This uses RotationRate directly:

```
function setup()
local size = math.min(HEIGHT, WIDTH) / 2
d = 1000
m = cubeMesh(size)
dirz = vec3(0, 0, 1)
diry = vec3(0, 1, 0)
dirx = vec3(1,0,0)
mat = matrix()
end
function draw()
background(0)
perspective()
local mat = matrix()
local dxa = RotationRate.x
local dya = RotationRate.y
local dza = RotationRate.z
mat = mat:rotate(dza, dirz.x,dirz.y,dirz.z)
mat = mat:rotate(dya, diry.x,diry.y,diry.z)
mat = mat:rotate(dxa, dirx.x,dirx.y,dirx.z)
dirx = mult(mat, dirx)
diry = mult(mat, diry)
dirz = mult(mat, dirz)
local x = dirz.x * d
local y = dirz.y * d
local z = dirz.z * d
camera(x, y, z, 0, 0, 0, diry.x, diry.y, diry.z)
m:draw()
end
function cubeMesh(size)
local v = {}
local c = {}
for i = 0, 7 do
local x = (i % 2) * 2 - 1
local y = (math.floor(i / 2) % 2) * 2 - 1
local z = (math.floor(i / 4) % 2) * 2 - 1
v[i] = vec3(x, y, z) * size / 2
c[i] = color(127 + 127 * x, 127 + 127 * y, 127 + 127 * z)
end
local ver = {}
local col = {}
for v1 = 1, 3 do
local v2 = v1 * 3 % 7
local v3 = 7 - v1
local v4 = 7 - v2
local vt = {v[0], v[v1], v[v2], v[0], v[v3], v[v4],
v[7], v[v2], v[v1], v[7], v[v4], v[v3]}
for i = 1, #vt do
ver[(v1 - 1) * #vt + i] = vt[i]
end
local ct = {c[0], c[v1], c[v2], c[0], c[v3], c[v4],
c[7], c[v2], c[v1], c[7], c[v4], c[v3]}
for i = 1, #ct do
col[(v1 - 1) * #ct + i] = ct[i]
end
end
local m = mesh()
m.vertices = ver
m.colors = col
return m
end
function mult(mat, vec)
local v1 = mat[1] * vec.x + mat[5] * vec.y + mat[9] * vec.z
local v2 = mat[2] * vec.x + mat[6] * vec.y + mat[10] * vec.z
local v3 = mat[3] * vec.x + mat[7] * vec.y + mat[11] * vec.z
return vec3(v1, v2, v3)
end
```