ok, i will take look at the roller coaster demo.
i made a first attempt using cylinders as the segments and using spheres to fill in the joints.
But for reasons i don’t understand the spheres do not get displayed?
-- 3d pipe
--
displayMode(FULLSCREEN)
function setup()
--define direction of light source - this is the direction light is coming from,
--ie if you draw a line from here to 0,0,0, that is the direction of the light
light=vec3(1,.5,0)
--create shapes using colours and images
--we'll store them in separate meshes, because these shapes will usually be moved/rotated individually
shapes={}
newcyl={}
newsphere={}
pts={}
end
function touched(t)
tpos=vec2(t.x,t.y)
if t.state==MOVING then
print (tpos)
table.insert(pts,tpos)
npts=#pts
if npts>1 then
dir=pts[npts]-pts[npts-1]
else
dir=vec2(0,0.1)
end
--
newcyl[npts]=addCylinder{
centre=vec3(0,0,0),
height=dir:len(),
radius=10,
color=color(141, 203, 77, 255),
-- texture="Cargo Bot:Starry Background",
light=light,
ambience=.5,
faceted=false,
axis=vec3(dir.x,dir.y,0)
}
newcyl[npts].pos=vec3(pts[npts].x, pts[npts].y, 0)
table.insert(shapes,newcyl[npts])
--]]
--[[
newsphere[npts]=addSphere{
centre=vec3(0,0,0),
size=10,
color=color(141, 203, 77, 255),
-- texture="Cargo Bot:Starry Background",
light=light,
ambience=.5}
newsphere[npts].pos=vec3(pts[npts].x, pts[npts].y, 0)
table.insert(shapes,newsphere[npts])
--]]
end
end
function draw()
background(50)
-- perspective() --puts Codea in 3D mode
-- camera(0,0,250,WIDTH/2,HEIGHT/2,0) --camera is 250 pixels back from 0, looking at (0,0,0)
-- camera(0,0,250,0,0,0) --camera is 250 pixels back from 0, looking at (0,0,0)
for _,s in pairs(shapes) do
-- print("-")
pushMatrix()
translate(s.pos.x,s.pos.y,s.pos.z)
-- rotate(rot.x,1,0,0) rotate(rot.y,0,1,0) rotate(rot.z,0,0,1)
--use this next line with all your objects that use lighting
if s.shader then s.shader.invModel = modelMatrix():inverse():transpose() end
s:draw()
popMatrix()
end
end