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:
parent
d0a17488d0
commit
a1df463a16
@ -126,6 +126,12 @@ function ship:draw()
|
|||||||
else
|
else
|
||||||
spr(1,self.x,self.y)
|
spr(1,self.x,self.y)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function calc_velocity(v0, t, vmax, drag)
|
function calc_velocity(v0, t, vmax, drag)
|
||||||
@ -163,9 +169,21 @@ constraints = {
|
|||||||
|
|
||||||
function constraints:constrain(s, want)
|
function constraints:constrain(s, want)
|
||||||
self.color=10
|
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
|
return want
|
||||||
end
|
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()
|
function constraints:cycle()
|
||||||
if self.ctype=="bounds" then
|
if self.ctype=="bounds" then
|
||||||
self.ctype="point"
|
self.ctype="point"
|
||||||
@ -201,10 +219,10 @@ end
|
|||||||
-- todo: spark ring buffer
|
-- todo: spark ring buffer
|
||||||
|
|
||||||
__gfx__
|
__gfx__
|
||||||
00000000800000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000008000000000080000a000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000006666000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000006666000080000009090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000067777600800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000067777600800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000675555758008888000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000675555758008888009090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000675000750800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000006750007508000000a000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000067777500080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000067777500080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000005555000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000005555000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
Loading…
Reference in New Issue
Block a user