Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getLineVoxels(x1,y1,z1,x2,y2,z2)
- local point = {x1,y1,z1}
- local dx = x2 - x1
- local dy = y2 - y1
- local dz = z2 - z1
- local x_inc = 1
- if dx < 0 then x_inc = -1 end
- local l = math.abs(dx)
- local y_inc = 1
- if dy < 0 then y_inc = -1 end
- local m = math.abs(dy)
- local z_inc = 1
- if dz < 0 then z_inc = -1 end
- local n = math.abs(dz)
- local dx2 = l * 2
- local dy2 = m * 2
- local dz2 = n * 2
- local err_1 = 0
- local err_2 = 0
- local output = {}
- if l>=m and l>=n then
- err_1 = dy2 -1
- err_2 = dz2 -1
- for i=0,i<l do
- table.insert(output,point)
- if err_1 > 0 then
- point[2] = point[2] + y_inc
- err_1 = err1 - dx2
- end
- if err_2 > 0 then
- point[3] = point[3] + z_inc
- err2 = err2 -dx2
- end
- err_1 = err1 + dy2
- err_2 = err_2 + dz2
- point[1] = point[1] + x_inc
- end
- elseif m>=l and m>=n then
- err_1 = dx2 - m
- err_2 = dz2 - m
- for i = 0,i<m do
- table.insert(output,point)
- if err_1 > 0 then
- point[1] = point[1] + x_inc
- err_1 = err_1 - dy2
- end
- if err_2 > 0 then
- point[3] = point[3] + z_inc;
- err_2 = err_2 - dy2
- end
- err_1 = err_1 + dx2
- err_2 = err_2 + dz2
- point[2] = point[2] + y_inc;
- end
- else
- err_1 = dy2 - n
- err_2 = dx2 - n
- for i = 0,i<n do
- table.insert(output,point)
- if err_1 > 0 then
- point[2] = point[2] + y_inc
- err_1 = err_1 - dz2
- end
- if err_2 > 0 then
- point[1] = point[1] + x_inc
- err_2 = err_2 - dz2
- end
- err_1 = err_1 + dy2
- err_2 = err_2 + dx2
- point[3] = point[3] + z_inc
- end
- end
- table.insert(output,point)
- return output
- end
Add Comment
Please, Sign In to add comment