- 81
- 12
У меня вопрос, как убрать дублирование полосы renderDrawLine, у меня снизу рисуется адекватно, но эта полоса дублируется сверху и следует за персонажем, я двигаюсь и она двигается
Lua:
local function drawRouteLine(pts, width, px, py, pz)
if not pts or #pts < 2 then return end
local n = #pts
local nearest = 1
local nearestDist = math.huge
for i = 1, n do
local pt = pts[i]
local d = dist3D(px, py, pz, pt.x, pt.y, pt.z)
if d < nearestDist then
nearestDist = d
nearest = i
end
end
local startIndex = math.max(1, nearest - 250)
local endIndex = math.min(n - 1, nearest + 250)
for i = startIndex, endIndex do
local a = pts[i]
local b = pts[i + 1]
local mx = (a.x + b.x) * 0.5
local my = (a.y + b.y) * 0.5
local mz = (a.z + b.z) * 0.5
local d = dist3D(px, py, pz, mx, my, mz)
if d <= DRAW_DISTANCE then
local dx = b.x - a.x
local dy = b.y - a.y
-- защита от битых сегментов
local segLen = math.sqrt(dx * dx + dy * dy)
if segLen <= 25.0 then
local ax, ay = safeProject(a.x, a.y, a.z)
local bx, by = safeProject(b.x, b.y, b.z)
if ax and ay and bx and by then
local ndx, ndy = normalize2D(dx, dy)
local perpX = -ndy
local perpY = ndx
local half = width * 0.5
-- левая граница
local laX = a.x + perpX * half
local laY = a.y + perpY * half
local lbX = b.x + perpX * half
local lbY = b.y + perpY * half
-- правая граница
local raX = a.x - perpX * half
local raY = a.y - perpY * half
local rbX = b.x - perpX * half
local rbY = b.y - perpY * half
local lax, lay = safeProject(laX, laY, a.z)
local lbx, lby = safeProject(lbX, lbY, b.z)
local rax, ray = safeProject(raX, raY, a.z)
local rbx, rby = safeProject(rbX, rbY, b.z)
-- центральная линия
local cdx = bx - ax
local cdy = by - ay
local centerLen = math.sqrt(cdx * cdx + cdy * cdy)
if centerLen < 1000 then
renderDrawLine(ax, ay, bx, by, 1.5, CLR_CENTER)
end
-- левая граница
if lax and lay and lbx and lby then
local ldx = lbx - lax
local ldy = lby - lay
local leftLen = math.sqrt(ldx * ldx + ldy * ldy)
if leftLen < 1000 then
renderDrawLine(lax, lay, lbx, lby, 1.0, CLR_BORDER)
end
end
-- правая граница
if rax and ray and rbx and rby then
local rdx = rbx - rax
local rdy = rby - ray
local rightLen = math.sqrt(rdx * rdx + rdy * rdy)
if rightLen < 1000 then
renderDrawLine(rax, ray, rbx, rby, 1.0, CLR_BORDER)
end
end
end
end
end
end
end