I tried do 3D but I didn’t work can someone please help me.
I used a table called vecs
but i need to draw them now.
Okay plz help
@Purple107 3D isn’t easy, and will take some time to learn. The next version of Codea will have Craft which makes 3D a lot easier. Here’s a simple cube.
function setup()
parameter.integer("R",-360,360, 60)
parameter.number("x",0,1,.5)
parameter.number("y",0,1,.5)
parameter.number("z",0,1,.5)
parameter.integer("size", 1, 50, 20)
end
function draw()
background(0, 0, 0, 255)
perspective(50,WIDTH/HEIGHT)
camera(-200,0,0,0,0,0,0,1,0)
rotate(R,x,y,z)
fill(255, 0, 0, 255)
cube(0,0,0,size,size,size)
end
function cube(x,y,z,w,h,d)
local cube = mesh()
v = {
vec3(x-w,y-h,z+d),vec3(x-w,y+h,z+d),vec3(x+w,y-h,z+d),vec3(x+w,y+h,z+d),
vec3(x-w,y-h,z-d),vec3(x-w,y+h,z-d),vec3(x+w,y-h,z-d),vec3(x+w,y+h,z-d)
}
local faces = {
v[1],v[2],v[3],v[2],v[3],v[4],
v[2],v[4],v[6],v[4],v[6],v[8],
v[1],v[2],v[5],v[2],v[5],v[6],
v[3],v[4],v[7],v[4],v[7],v[8],
v[1],v[3],v[5],v[3],v[5],v[7],
v[5],v[6],v[7],v[6],v[7],v[8]
}
local c = { color(255, 0, 0, 255), color(0, 255, 0, 255), color(255, 243, 0, 255),
color(0, 0, 255, 255), color(255, 255, 255, 255), color(255, 0, 189, 255)}
local colors = {}
for i = 1, 6 do
for j = 1, 6 do
table.insert(colors, c[i])
end
end
cube.vertices = faces
cube.colors = colors
cube:draw()
end
@dave1707 That looks hard. :#
Thank you for the code.
@Purple107 for now until craft is fully released I suggest you study the 3d example a lot! Make small changes and see how they effect your game. After a while you will understand it a lot better!
@GR00G0 My opinion is doing it after CC. Then it will be times easier?
@Purple107 Just to give you an idea of the simplicity of Craft 3D, here’s a program that draws a red cube and allows you to rotate it in the x,y,z axis similar to my above program.
NOTE: This requires Craft 3D which is in the next Codea version.
function setup()
parameter.integer("x",-180,180,45)
parameter.integer("y",-180,180,30)
parameter.integer("z",-180,180,60)
scene=craft.scene()
cube=scene:entity()
cube.z=10
r=cube:add(craft.renderer,craft.mesh.cube(vec3(1,1,1)))
r.material=craft.material("Materials:Standard")
r.material.diffuse=color(255,0,0)
end
function update(d)
cube.rotation = quat.eulerAngles(x,y,z)
end
function draw()
update(DeltaTime)
scene:draw()
end