# 3D example forward and back

On the 3D example, I have the ellipse move left and right with t.deltaX. How would I get it to go forward and back. I want to do a full rotation around a point in space.

I found that example quite confusing, and there is a lot to learn with 3D.

https://www.dropbox.com/sh/mr2yzp07vffskxt/AACqVnmzpAKOkNDWENPmN4psa

@FearMe2142 Heres an example I have that draws 2 cubes near 0,0,0 and moves the camera around them based on the calculation of x,y,z.

EDIT: Just to be clear, the cubes are stationary and the camera is moving around them always looking at 0,0,0.

``````displayMode(FULLSCREEN)

function setup()
x,y,z=0,0,0
ang=0
cube()
end

function draw()
background(0)

ang=ang+.5
if ang>=360 then
ang=0
end

y=10

fill(255)
str=string.format("camera   x=%.1f    y=%.1f    z=%.1f    ang=%.1f",x,y,z,ang)
text(str,WIDTH/2,HEIGHT-50)

perspective()
camera(x,y,z,0,0,0, 0,1,0)

pushMatrix()
translate(-2,0,0)
m:draw()
popMatrix()

pushMatrix()
translate(2,0,0)
m:draw()
popMatrix()

pushMatrix()
translate(0,2,2)
m:draw()
popMatrix()

pushMatrix()
translate(0,2,-2)
m:draw()
popMatrix()
end

function cube()
local vertices = {
vec3(-1, -1,  1),
vec3( 1, -1,  1),
vec3( 1,  1,  1),
vec3(-1,  1,  1),
vec3(-1, -1, -1),
vec3( 1, -1, -1),
vec3( 1,  1, -1),
vec3(-1,  1, -1),
}

local cubeverts = {
vertices[1], vertices[2], vertices[3],
vertices[1], vertices[3], vertices[4],
vertices[2], vertices[6], vertices[7],
vertices[2], vertices[7], vertices[3],
vertices[6], vertices[5], vertices[8],
vertices[6], vertices[8], vertices[7],
vertices[5], vertices[1], vertices[4],
vertices[5], vertices[4], vertices[8],
vertices[4], vertices[3], vertices[7],
vertices[4], vertices[7], vertices[8],
vertices[5], vertices[6], vertices[2],
vertices[5], vertices[2], vertices[1],
}
local texverts = { vec2(0.03,0.24),vec2(0.97,0.24),
vec2(0.03,0.69),vec2(0.97,0.69) }
local cubetexCoords = {
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
texverts[1], texverts[2], texverts[4],
texverts[1], texverts[4], texverts[3],
}

m=mesh()
m.vertices = cubeverts
m.texture = "Planet Cute:Stone Block"
m.texCoords = cubetexCoords
end
``````