From 9c9503a5fcf78545a4de28f0be596c12ddf8709c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 19 Jul 2025 13:29:59 -0700 Subject: Make picking take camera into account --- src/isogfx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/isogfx.c b/src/isogfx.c index 5d23ae4..c3a87bf 100644 --- a/src/isogfx.c +++ b/src/isogfx.c @@ -84,6 +84,12 @@ static inline ivec2 iso2cart(ivec2 iso, int s, int t, int w) { .y = (iso.x + iso.y) * (t / 2)}; } +static inline vec2 vec2_add(vec2 a, vec2 b) { + return (vec2){.x = a.x + b.x, .y = a.y + b.y}; +} + +static inline vec2 ivec2_to_vec2(ivec2 a) { return (vec2){a.x, a.y}; } + // Method 1. // static inline vec2 cart2iso(vec2 cart, int s, int t, int w) { // const double x = cart.x - (double)(w / 2); @@ -682,9 +688,12 @@ void isogfx_pick_tile( assert(xiso); assert(yiso); + const vec2 camera = ivec2_to_vec2(iso->camera); + const vec2 xy_cart = vec2_add(camera, (vec2){xcart, ycart}); + const vec2 xy_iso = cart2iso( - (vec2){.x = xcart, .y = ycart}, iso->map->base_tile_width, - iso->map->base_tile_height, iso->screen.width); + xy_cart, iso->map->base_tile_width, iso->map->base_tile_height, + iso->screen.width); if ((0 <= xy_iso.x) && (xy_iso.x < iso->map->world_width) && (0 <= xy_iso.y) && (xy_iso.y < iso->map->world_height)) { -- cgit v1.2.3