From: Lukas Krickl Date: Thu, 5 Mar 2026 07:25:07 +0000 (+0100) Subject: camera: fixed on camera detection for tile rendering X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=eba42906d3ad6dfbb96aaecf4f501c6677444f7b;p=lrts%2F.git camera: fixed on camera detection for tile rendering --- diff --git a/src/r_assets.c b/src/r_assets.c index 6661eab..02ba142 100644 --- a/src/r_assets.c +++ b/src/r_assets.c @@ -52,13 +52,14 @@ void r_draw_solid_isometric_tile(i32 x, i32 y, r_color color) { u32 j = 0; r_color final_color; struct u_vec2 t = u_tile_to_screen(x, y); - t = u_screen_to_camera(&t_main_camera, t); + struct u_vec2 te = u_tile_to_screen(x+1, y+1); /* do not draw if tile is not visible at all */ - if (!t_camera_is_visible_world(&t_main_camera, t.x, t.y) - && !t_camera_is_visible_world(&t_main_camera, t.x + R_TILE_W, t.y + R_TILE_H)) { + if (!t_camera_is_visible_screen(&t_main_camera, t.x, t.y) + && !t_camera_is_visible_screen(&t_main_camera, te.x, te.y)) { return; } + t = u_screen_to_camera(&t_main_camera, t); /* converted origin point in isometric space */ diff --git a/src/t_camera.c b/src/t_camera.c index 3e2a830..f9a34a8 100644 --- a/src/t_camera.c +++ b/src/t_camera.c @@ -20,13 +20,7 @@ void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y) { } lrts_bool t_camera_is_visible_screen(struct t_camera *c, i32 x, i32 y) { - return u_point_in_rect(x, y, c->x, c->y, c->x + c->viewport_x, c->y + c->viewport_y); -} - -lrts_bool t_camera_is_visible_world(struct t_camera *c, i32 x, i32 y) { - struct u_vec2 t = u_point_to_screen(c->x, c->y); - - return u_point_in_rect(x, y, t.x, t.y, t.x + c->viewport_x, t.y + c->viewport_y); + return u_point_in_rect(x, y, c->x, c->y, c->viewport_x, c->viewport_y); } diff --git a/src/t_camera.h b/src/t_camera.h index 3a9d57c..5763f64 100644 --- a/src/t_camera.h +++ b/src/t_camera.h @@ -23,7 +23,5 @@ struct u_vec2 u_screen_to_camera(struct t_camera *c, struct u_vec2 v); /* tests if a point is visible in screen sapce */ lrts_bool t_camera_is_visible_screen(struct t_camera *c, i32 x, i32 y); -/* tests if a point is visible in world space */ -lrts_bool t_camera_is_visible_world(struct t_camera *c, i32 x, i32 y); #endif