starfall-data/koptilnya/physics_debugger.txt
Nikita Kruglickiy 09be0ea795 UPDATE
2023-05-22 19:06:26 +03:00

74 lines
2.2 KiB
Lua

--@name Physics debugger
--@author Opti1337
--@shared
--@include /koptilnya/libs/entity.txt
if SERVER then
require("/koptilnya/libs/entity.txt")
wire.adjustPorts(
{
W1 = "ENTITY",
W2 = "ENTITY"
}
)
timer.create("interval", 0.08, 0, function()
local data = {}
for k, w in pairs({wire.ports.W1, wire.ports.W2}) do
if not isValid(w) then return end
local physObj = w:getPhysicsObject()
if not isValid(physObj) then return end
local v = physObj:getVelocity()
local lV = getLocalVelocity(physObj)
local m = physObj:getMass()
local f = m * (lV / 0.08)
data[k] = {
Velocity = v,
LocalVelocity = lV,
Mass = m,
Force = f
}
end
net.start("data")
net.writeString(json.encode(data))
net.send(nil, true)
end)
else
local data = {}
net.receive("data", function()
data = json.decode(net.readString())
end)
hook.add("drawhud", "_drawhud", function()
if #data < 2 then return end
render.setColor(Color(0, 255, 0))
render.drawCircle(1400, 950, 50)
render.drawSimpleText(1400, 1020, "F = " .. tostring(data[1].Force), 2, 1)
--render.drawLine(1400, 950, 1400 - data[1].Force[1] / 10000, 950 - data[1].Force[2] / 10000)
render.setColor(Color(0, 0, 255))
render.drawLine(1400, 950, 1400 - data[1].Force[2] / 10000, 950)
render.setColor(Color(255, 0, 0))
render.drawLine(1400, 950, 1400, 950 - data[1].Force[1] / 10000)
render.setColor(Color(0, 255, 0))
render.drawCircle(1820, 950, 50)
render.drawSimpleText(1820, 1020, "F = " .. tostring(data[2].Force), 2, 1)
--render.drawLine(1820, 950, 1820 - data[2].Force[1] / 10000, 950 - data[2].Force[2] / 10000)
render.setColor(Color(0, 0, 255))
render.drawLine(1820, 950, 1820 - data[1].Force[2] / 10000, 950)
render.setColor(Color(255, 0, 0))
render.drawLine(1820, 950, 1820, 950 - data[2].Force[1] / 10000)
--for k, w in pairs(data) do end
end)
end