diff options
-rw-r--r-- | src/isogfx.c | 13 |
1 files changed, 11 insertions, 2 deletions
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) { | |||
84 | .y = (iso.x + iso.y) * (t / 2)}; | 84 | .y = (iso.x + iso.y) * (t / 2)}; |
85 | } | 85 | } |
86 | 86 | ||
87 | static inline vec2 vec2_add(vec2 a, vec2 b) { | ||
88 | return (vec2){.x = a.x + b.x, .y = a.y + b.y}; | ||
89 | } | ||
90 | |||
91 | static inline vec2 ivec2_to_vec2(ivec2 a) { return (vec2){a.x, a.y}; } | ||
92 | |||
87 | // Method 1. | 93 | // Method 1. |
88 | // static inline vec2 cart2iso(vec2 cart, int s, int t, int w) { | 94 | // static inline vec2 cart2iso(vec2 cart, int s, int t, int w) { |
89 | // const double x = cart.x - (double)(w / 2); | 95 | // const double x = cart.x - (double)(w / 2); |
@@ -682,9 +688,12 @@ void isogfx_pick_tile( | |||
682 | assert(xiso); | 688 | assert(xiso); |
683 | assert(yiso); | 689 | assert(yiso); |
684 | 690 | ||
691 | const vec2 camera = ivec2_to_vec2(iso->camera); | ||
692 | const vec2 xy_cart = vec2_add(camera, (vec2){xcart, ycart}); | ||
693 | |||
685 | const vec2 xy_iso = cart2iso( | 694 | const vec2 xy_iso = cart2iso( |
686 | (vec2){.x = xcart, .y = ycart}, iso->map->base_tile_width, | 695 | xy_cart, iso->map->base_tile_width, iso->map->base_tile_height, |
687 | iso->map->base_tile_height, iso->screen.width); | 696 | iso->screen.width); |
688 | 697 | ||
689 | if ((0 <= xy_iso.x) && (xy_iso.x < iso->map->world_width) && | 698 | if ((0 <= xy_iso.x) && (xy_iso.x < iso->map->world_width) && |
690 | (0 <= xy_iso.y) && (xy_iso.y < iso->map->world_height)) { | 699 | (0 <= xy_iso.y) && (xy_iso.y < iso->map->world_height)) { |