braking distance and visualization. bad calculation

the visualization is really helpful for showing me that I fucked up my math
This commit is contained in:
Kistaro Windrider 2024-01-14 19:57:22 -08:00
parent d0a17488d0
commit a1df463a16
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -126,6 +126,12 @@ function ship:draw()
else
spr(1,self.x,self.y)
end
if (self.dx == 0) return
local bd, f = brake_dist(self.dx, self.thrust + self.drag)
local bdx = self.x+bd-2
spr(3, bdx,self.y-3)
print(tostr(f), bdx, self.y - 8, 14)
end
function calc_velocity(v0, t, vmax, drag)
@ -163,9 +169,21 @@ constraints = {
function constraints:constrain(s, want)
self.color=10
local v1 = calc_velocity(s.dx, want, s.maxspd, s.drag)
local bd, bf = brake_dist(v1, s.thrust + s.drag)
return want
end
function brake_dist(v0, brake_max)
local tri_frames = abs(v0/brake_max)&-1
local chunks = tri_frames * (tri_frames - 1) >> 1
local chunk_zone = chunks * brake_max
local overage = v0 - chunk_zone
return chunk_zone + overage * (tri_frames + 1) * -sgn(v0), (overage > 0) and tri_frames + 1 or tri_frames
end
function constraints:cycle()
if self.ctype=="bounds" then
self.ctype="point"
@ -201,10 +219,10 @@ end
-- todo: spark ring buffer
__gfx__
00000000800000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000006666000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000008000000000080000a000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000006666000080000009090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000067777600800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000675555758008888000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000675000750800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000675555758008888009090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000006750007508000000a000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000067777500080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000005555000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000