From d84e12d598acc3d3374194c5926aa4eb63b4f7d6 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 28 Dec 2025 16:49:18 -0600 Subject: [PATCH] unsmooth editor camera panning --- src/pp/pp_vis/pp_vis_core.c | 43 +++++++++++++++++++++++++------------ src/pp/pp_vis/pp_vis_core.h | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index b3ebea1c..94c439aa 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -669,8 +669,8 @@ void V_TickForever(WaveLaneCtx *lane) frame->edit_camera_zoom *= PowF32(zoom_rate, -last_frame->zooms); frame->edit_camera_zoom = ClampF32(frame->edit_camera_zoom, min_zoom, max_zoom); // Offset edit camera based on cursor if panning / zooming - b32 is_zooming = last_frame->zooms != 0 && (frame->edit_camera_zoom != last_frame->edit_camera_zoom); - if (last_frame->is_editing && (is_zooming || (frame->is_panning && last_frame->is_panning))) + b32 should_zoom = last_frame->zooms != 0 && (frame->edit_camera_zoom != last_frame->edit_camera_zoom); + if (last_frame->is_editing && (should_zoom || (frame->is_panning && last_frame->is_panning))) { Xform last_frame_edit_to_ui_xf = Zi; Xform edit_to_ui_xf = Zi; @@ -710,17 +710,33 @@ void V_TickForever(WaveLaneCtx *lane) // Create world <-> ui xforms { - f32 lerp_ratio = 15.0 * frame->dt; if (last_frame->tick == 0) { - lerp_ratio = 1; + frame->camera_lerp_ratio = 1; } else if (frame->is_editing) { - lerp_ratio = 30.0 * frame->dt; + b32 is_zooming = AbsF32(target_camera_zoom - last_frame->camera_zoom) > 0.001; + if (frame->is_panning && !is_zooming) + { + // When panning & not zooming, we want camera interpolation to be + // instant (no smoothing). However, the transition to non + // interpolation must be smooth. + frame->camera_lerp_ratio += last_frame->camera_lerp_ratio + (5 * frame->dt); + frame->camera_lerp_ratio = MinF32(frame->camera_lerp_ratio, 1); + } + else + { + frame->camera_lerp_ratio = 30.0 * frame->dt; + } } - frame->camera_pos = LerpVec2(last_frame->camera_pos, target_camera_pos, lerp_ratio); - frame->camera_zoom = LerpF32(last_frame->camera_zoom, target_camera_zoom, lerp_ratio); + else + { + frame->camera_lerp_ratio = 15.0 * frame->dt; + } + + frame->camera_pos = LerpVec2(last_frame->camera_pos, target_camera_pos, frame->camera_lerp_ratio); + frame->camera_zoom = LerpF32(last_frame->camera_zoom, target_camera_zoom, frame->camera_lerp_ratio); { f32 camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->camera_zoom); frame->world_to_ui_xf = XformFromScale(VEC2(camera_scale, camera_scale)); @@ -1513,15 +1529,14 @@ void V_TickForever(WaveLaneCtx *lane) { S_Cmd *cmd = V_PushSimCmd(S_CmdKind_Spawn); S_Ent *ent = &cmd->ent; + *ent = *S_EntFromKey(&V.lookup, V.player_key); ent->key = V.player_key; ent->move_speed = 0.1; - { - ent->local_shape = S_ShapeFromDesc( - .mass = 10, - .count = 1, - .radius = 0.3, - ); - } + ent->local_shape = S_ShapeFromDesc( + .mass = 10, + .count = 1, + .radius = 0.3, + ); ent->xf = XformFromPos(frame->world_cursor); ent->has_weapon = 1; } break; diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 872995d0..0ab5fe4f 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -234,6 +234,7 @@ Struct(V_Frame) f32 edit_camera_zoom; // Camera + f32 camera_lerp_ratio; Vec2 camera_pos; f32 camera_zoom;