More intuitive 3d example

http://www.youtube.com/watch?v=tTlvoo3vJlc

 function setup()
    camspot = vec3(0,0,0)
parameter("distance",100,1000,440)
parameter("angle",0,360,45);    
parameter("topangle",-89,89,0)
parameter("fov",65,144,100)
parameter("camerax",-100,100,0)
parameter("cameray",-100,100,0)
parameter("cameraz",-100,100,0)
definefacerot()
watch("fps")
noSmooth()

rectMode(CENTER)

end


function draw()


    background(134, 166, 179, 255)
    
    
    cam()
    
for i = -3,3 do
    for j = -3,3 do
    drawcube(i*12,0,j*12,red,12,24)

    end
    end
 drawcube(6,32,6,
"SpaceCute:Background",32,24,nil, CurrentTouch.x,CurrentTouch.y)
end
function definefacerot()
    
   red = setflat(color(255, 0, 0, 255))
blue = setflat(color(0, 0, 255, 255))
green = setflat(color(0, 255, 0, 255))
black =setflat(color(3, 3, 3, 255))
dark =setflat(color(33, 34, 35, 255))

local face = {

{90,1,0,0}, -- north     3
 {180,1,0,0}, --back   2
 {0}, --front        1

{270,0,1,0}, -- west     6
{90,0,1,0}, -- east      5
{270,1,0,0}, -- south    4

nil
}


cubefacerot= face
end

function setflat(culurr)
    
local cull = image(1,1)

cull:set(1,1,culurr)

return cull
end

function drawcube(xx,yy,zz,tex,size,shading,rra,rrb,rrc)
    if shading == nil then shading = 0 end
    pushMatrix()
    translate(xx,yy,zz)
    if rra == nil then else rotate(rra) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale(size/64,size/64,size/64)
    pushMatrix()
    for i = 1,6 do
        pushMatrix()
rotate(unpack(cubefacerot[i]))
if shading > 0 then
        tint(255-(i)*shading) end
        translate(0,0,-32)
        sprite(tex,0,0,64)
        popMatrix()
--rect(i*111,0,99,99)
 end
noTint()
popMatrix()
popMatrix()
popMatrix()
end
    
    function cam() 
    
       camspot = vec3(camerax,cameray,cameraz)
    topangle = math.min(89.9,math.max(-89.9,topangle))
    fps = 0.1 * math.ceil( DeltaTime*600)
 --   rotate(yaw)
    pushMatrix()
    perspective(fov, WIDTH/HEIGHT)
    local camdown = vec2(distance/(fov/44),0):rotate(math.rad(topangle))
    
local camplane = vec2(camdown.x,0):rotate(math.rad(angle))

    camera(camplane.x+camspot.x,camdown.y+camspot.y,camplane.y+camspot.z, camspot.x,camspot.y,camspot.z, 0,4,0)
    
    end

Love it!

I’m going to add a system to make the shading dynamic as well, but figured I may as well post this now anyway.