mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 22:24:35 +00:00
[added] math.lerp_eps and matching vec2/vec3 methods; for ensuring a lerp actually reaches its destination once the delta doesn't matter
This commit is contained in:
parent
870d291369
commit
9422152181
10
math.lua
10
math.lua
@ -55,6 +55,16 @@ function _math.lerp(a, b, t)
|
|||||||
return a * (1.0 - t) + b * t
|
return a * (1.0 - t) + b * t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--linear interpolation with a minimum "final step" distance
|
||||||
|
--useful for making sure dynamic lerps do actually reach their final destination
|
||||||
|
function _math.lerp_eps(a, b, t, eps)
|
||||||
|
local v = math.lerp(a, b, t)
|
||||||
|
if math.abs(v - b) < eps then
|
||||||
|
v = b
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
--classic smoothstep
|
--classic smoothstep
|
||||||
--(only "safe" for 0-1 range)
|
--(only "safe" for 0-1 range)
|
||||||
function _math.smoothstep(v)
|
function _math.smoothstep(v)
|
||||||
|
10
vec2.lua
10
vec2.lua
@ -484,6 +484,16 @@ function vec2:lerp(other, amount)
|
|||||||
return self:copy():lerpi(other, amount)
|
return self:copy():lerpi(other, amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function vec2:lerp_epsi(other, amount, eps)
|
||||||
|
self.x = math.lerp_eps(self.x, other.x, amount, eps)
|
||||||
|
self.y = math.lerp_eps(self.y, other.y, amount, eps)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2:lerp_eps(other, amount, eps)
|
||||||
|
return self:copy():lerp_epsi(other, amount, eps)
|
||||||
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
-- vector products and projections
|
-- vector products and projections
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
11
vec3.lua
11
vec3.lua
@ -556,6 +556,17 @@ function vec3:lerp(other, amount)
|
|||||||
return self:copy():lerpi(other, amount)
|
return self:copy():lerpi(other, amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function vec3:lerp_epsi(other, amount, eps)
|
||||||
|
self.x = math.lerp_eps(self.x, other.x, amount, eps)
|
||||||
|
self.y = math.lerp_eps(self.y, other.y, amount, eps)
|
||||||
|
self.z = math.lerp_eps(self.z, other.z, amount, eps)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec3:lerp_eps(other, amount, eps)
|
||||||
|
return self:copy():lerp_epsi(other, amount, eps)
|
||||||
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
-- vector products and projections
|
-- vector products and projections
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user