I’ve been working on implementing the particle system from unity into Codea craft, however in order to get trails working on the particles. I first must create a line rendering component. One that does not draw pixels, but rather creates a polygon with (n) points and connects them dynamically. Of course, you’d have to make the line face the camera, but that parts pretty easy. Here is where I’m getting confused… I’ve been working on getting 2 points on the line dynamically generated, but I’m having trouble with the indices, i think? Here is my code.
function createLine(pos,p1width,p2width)
-- Create a blank model
local m = craft.model()
pos=pos or {}
p1=table.remove(pos,1) or vec3(1,-1,0)
p1width=p1width or 2
p2=table.remove(pos,#pos) or vec3(-1,1,0)
p2width=p2width or 2
local positions = computeLineMesh(p1,p2)
local indices = {3,2,1,4,3,1}
-- Update model vertices using tables
m.positions = positions
m.indices = indices
newEntity("lineT")
add_model(lineT,m)
end
function computeLineMesh(start,fin,lineWidth)
normal = start:cross(fin)
side=normal:cross(fin-start)
side=side:normalize()
lineWidth=lineWidth or 10
a = start + side * (lineWidth / 2)
b = start + side * (lineWidth / -2)
c = fin + side * (lineWidth / 2)
d = fin + side * (lineWidth / -2)
return {a,b,c,d}
end
This code actually works! However, it almost always produces just a single triangle, and not a proper rectangle/polygon. I’m not extremely mathematical, so some help in that department is always appreciated. Though I suspect it’s my use of indices that causes issues.