i want to sort a table containing triangles, which all contains 3 3d-vectors each, by the average of all z coponents of the vectors in the triangle.
(Which ever triangle has the lower z gets drawn earlier). I have my attempt here line 133 (and the source):
Code: Select all
function Sort_Triangles(list)
local i = 1
table.sort(list,function (a, b)
i = i+1
if i+1 > #list then i = 1 end
print(i)
return (list[i].vectors[1].z + list[i].vectors[2].z + list[i].vectors[3].z)/3 > (list[i+1].vectors[1].z + list[i+1].vectors[2].z + list[i+1].vectors[3].z)/3 end)
for i=1, #list do
love.graphics.polygon("fill",
list[i].vectors[1].x, list[i].vectors.vectors[1].y,
list[i].vectors.vectors[2].x, list[i].vectors.vectors[2].y,
list[i].vectors[3].x,list[i].vectors.vectors[3].y)
love.graphics.setColor( 0, 0, 0)
end
end