#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# 3D "Base" for begginers

edited October 2012 in General Posts: 19

Here's a base code for anyone that wants to mess with 3D

``````function setup()
print("Hello World!")
parameter("guyX",0,500,150)
parameter("guyY",0,500,150)
parameter("guyZ",0,500,150)
parameter("Angle",-360, 360, 0)
Angle = 0
Velocity = 0
cameraHeight = 0
end

function draw()
perspective(100, WIDTH/HEIGHT)
camera(0,cameraHeight,-300, 0,0,0, 0,1,0)

background(40, 40, 50)

if CurrentTouch.state == MOVING then
if CurrentTouch.deltaX > 0 then
Velocity = CurrentTouch.deltaX/3
end
if CurrentTouch.deltaY > 0 then
cameraHeight = cameraHeight + 1
end

if CurrentTouch.deltaX < 0 then
Velocity = CurrentTouch.deltaX/3
end
if CurrentTouch.deltaY<0 then
cameraHeight = cameraHeight - 1
end
end

if Velocity > 0 then
Velocity = Velocity - 1
end

if Velocity < 0 then
Velocity = Velocity + 1
end

if Velocity > -1 and Velocity < 1 then
Velocity = 0
end

Angle = Angle + Velocity

pushMatrix()
pushStyle()

translate(0,0,0)
rotate(Angle,0,1,0)
rotate(90,1,0,0)
sprite("SpaceCute:Background", 0, 0, 300, 300)

popStyle()
popMatrix()

pushMatrix()
pushStyle()

translate(guyX, guyY, -guyZ)
sprite("Planet Cute:Character Boy")

popStyle()
popMatrix()

ortho()
viewMatrix(matrix())
end

``````

Do your drawings in between pushMatrix pushStyle popStyle popMatrix

Very simple code but for some people(like it was for me), initializing the code (like perspective, ortho) was the biggest problem, the rest is cake (well, maybe)

Tagged: