diff options
| author | ubq323 <ubq323@ubq323.website> | 2025-11-02 20:11:34 +0000 |
|---|---|---|
| committer | ubq323 <ubq323@ubq323.website> | 2025-11-02 20:11:34 +0000 |
| commit | a71eeea17a7b54f46710f8d0ccb5e1e22fd54752 (patch) | |
| tree | d193f18674c8c52dbb079cc48f54abf8f17fea59 | |
| parent | bbd39c98b8c47091983ebbc0ccd507ac9801e100 (diff) | |
rmath: add clerp round squish unsquish sqlerp
| -rw-r--r-- | math.lua | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -20,5 +20,13 @@ function M.clamp(x,minv,maxv) return math.min(math.max(x,minv),maxv) end +function M.clerp(a,b,t) return M.lerp(a,b,M.clamp(t,0,1)) end +function M.round(x) return math.floor(x+0.5) end + +-- [-1,1] -> [0,1] +function M.squish(x) return (x/2)+0.5 end +-- [0,1] -> [-1,1] +function M.unsquish(x) return (x*2)-1 end +function M.sqlerp(a,b,t) return M.lerp(a,b,M.squish(t)) end return M |
