---@param pos > Vector3D
---@param radius > number
---@param segments > number ( 1 - 3 )
---@param color > number ( hex )
---@param linesStem > number ( 1 - 90 ) лучше не указывать вообще, а то ещё игру положишь
function drawSphere3D(pos, radius, segments, color, linesStep)
local dl = imgui.GetBackgroundDrawList()
local function drawCircle3D(segment)
for line = 0, 360, linesStep and linesStep * 4 or 40 do
for i = 0, 360, linesStep or 10 do
local a = getPointOnCurve(math.rad(i), math.rad(i), radius, 64, 64)
local x, y, z
if segment == 1 then
x, y, z =
pos.x + a.x,
pos.y + a.y * math.sin(math.rad(line)),
pos.z + a.y * math.cos(math.rad(line))
elseif segment == 2 then
x, y, z =
pos.x + a.x * math.cos(math.rad(line)),
pos.y + a.x * math.sin(math.rad(line)),
pos.z + a.y
elseif segment == 3 then
x, y, z =
pos.x + a.x * math.sin(math.rad(line)),
pos.y + a.y,
pos.z + a.x * math.cos(math.rad(line))
end
if isPointOnScreen(x, y, z, 0) then
dl:PathLineTo(imgui.ImVec2(convert3DCoordsToScreen(x, y, z)))
end
end
end
dl:PathStroke(color, false, 1)
end
for segment = 1, (segments and segments <= 3) and segments or 1 do
drawCircle3D(segment)
end
end
imgui.OnFrame(function() return true end, function()
local pos = Vector3D(10, 10, 5)
drawSphere3D(pos, 5, 3, 0xFFFFFFFF)
end).HideCursor = true
function getPointOnCurve(cstart, cend, cradius, point, max_points)
local a = cstart + (point / max_points) * (cend - cstart)
return imgui.ImVec2(math.cos(a) * cradius, math.sin(a) * cradius)
end