camera: fixed on camera detection for tile rendering
authorLukas Krickl <lukas@krickl.dev>
Thu, 5 Mar 2026 07:25:07 +0000 (08:25 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 5 Mar 2026 07:25:07 +0000 (08:25 +0100)
src/r_assets.c
src/t_camera.c
src/t_camera.h

index 6661eabd5052b0384b6762a1d03ec4e73feb2745..02ba142fea4a9cb7add08bc02223ef8096ec0f0f 100644 (file)
@@ -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 */
        
index 3e2a83007ccb667b55882f6529d5efa319223c89..f9a34a889488c5f03df3acbb22f29e409dfeecac 100644 (file)
@@ -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);
 }
 
 
index 3a9d57c960f2acc5903bdbcf25ec1cceb5f0b22f..5763f642b964712ae8cf67c8d74d300c14fd9c23 100644 (file)
@@ -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