diff options
| author | ne_mene <[email protected]> | 2026-03-09 17:33:46 +0100 |
|---|---|---|
| committer | ne_mene <[email protected]> | 2026-03-09 17:33:46 +0100 |
| commit | 9e7d27e8d43617955c8a1213b392d98e3932f7a3 (patch) | |
| tree | 978535c1fc3de6de78b40e8fe574fbe7b6734268 /src | |
| parent | ac2a4291182769510fdc0c877a52acaa0fb0ce4a (diff) | |
| parent | 3950a3b2fa78b7a928c0437d98105d79c13a922f (diff) | |
Merge remote-tracking branch 'refs/remotes/origin/main'
Please brochacho
Diffstat (limited to 'src')
| -rw-r--r-- | src/init.lua | 2 | ||||
| -rw-r--r-- | src/utils.lua | 55 |
2 files changed, 56 insertions, 1 deletions
diff --git a/src/init.lua b/src/init.lua index c18f175..fd13bcb 100644 --- a/src/init.lua +++ b/src/init.lua @@ -35,7 +35,7 @@ end function main_init() lg.setDefaultFilter("nearest", "nearest") - Viewport = lg.newCanvas(SCR_WIDTH, SCR_HEIGHT) + viewport = lg.newCanvas(SCR_WIDTH, SCR_HEIGHT) load_textures_from() diff --git a/src/utils.lua b/src/utils.lua index c3e4bea..b2186cc 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -37,3 +37,58 @@ function dist(x1, y1, x2, y2) local dy = y1 - y2 return (dx*dx + dy*dy)^0.5 end + +mathx = {} + +mathx.tau = math.pi * 2 + +function mathx.sign(x) + if x == 0 then + return 0 + end + return x < 0 and -1 or 1 +end + +function round(x) + return math.floor(x + 0.5) +end + +function clamp(a, min, max) + return math.min(max, math.max(a, min)) +end + +function snap(x, step) + return math.floor(x / step) * step +end + +function frac(x) + return x - math.floor(x) +end + +local function angle_diff(a, b) + local diff = (b - a) % (math.pi * 2) + return (2 * diff) % (math.pi * 2) - diff +end + +function lerp_angle(a, b, t) + return a + angle_diff(a, b) * (1 - 0.5^t) +end + +function dot(x, y, xx, yy) + return x*xx + y*yy +end + +function vec_sqlen(x, y) + return x*x + y*y +end + +function vec_len(x, y) + return math.sqrt(x*x + y*y) +end + +function rotate_vec(x, y, r) + local angle = math.atan2(y, x) + r + local len = mathx.vec_len(x, y) + return math.cos(angle) * len, math.sin(angle) * len +end + |
