GUI sort of thing help

I can’t seem to figure out how to use perspective and ortho correctly. I have a 3d world, but I’m trying to add in a CAMERA as the background, so it acts like an agumented reality game.

perspective(FieldOfView,WIDTH/HEIGHT)
background(0, 0, 0, 0)
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)
sprite("Documents:Charzard",0,0)
pushStyle()
sprite(CAMERA,0,0)
popStyle()

This is a section of the code. The sprite with the CAMERA in it, is also in the 3d world. Which I’m trying to fix. But I can’t seem to do it.

@Leviathan - the way you are doing rotation - changing camera orientation - seems rather strange to me (unless you know what you are doing of course!).

I’ve written a partial ebook on 3D graphics in Codea here, which covers the basics

https://www.dropbox.com/s/6rkqoqvvj7zhwhz/3D%20in%20Codea.pdf

plus many other 3D posts

http://coolcodea.wordpress.com/2013/06/19/index-of-posts/

btw, perspective turns on 3D drawing, ortho turns it off, basically

I think some of the problem is the order you’re drawing in. There are some other problems in the parameters, too. Something like this should be better:

function setup()
    angle = 0
    FieldOfView = 45
    spriteBatching(false)
    screen = image(WIDTH, HEIGHT)
end

function draw()
    background(255)
    sprite(CAMERA, WIDTH / 2, HEIGHT / 2)
    pushMatrix()
    setContext(screen)
    background(0, 0, 0, 0)
    perspective(FieldOfView,WIDTH/HEIGHT)
    angle = angle + RotationRate.y / math.abs(Gravity.y)
    local x, y, z = math.sin(math.rad(angle)) * 200, Gravity.z * 200, math.cos(math.rad(angle)) * 200
    camera(0, 0, 0, x, y, z, 0, 1, 0)
    translate(0, 0, 200)
    sprite("Planet Cute:Character Boy")
    setContext()
    popMatrix()
    ortho()
    resetMatrix()
    viewMatrix(matrix())
    sprite(screen, WIDTH / 2, HEIGHT / 2)
end

I think I got it. How’s that? Runs fine for me.

@Ignatz Perspective adds in distortion of the mesh for the vertices to be smaller depending on their distance, ortho does none of that. Ortho supports 3D. You’d need to reset the camera too for it to appear as if you were drawing in 2D.

Oh my gosh thank you! I read the ebooks and tried out your code, it works perfectly. Thank you!