diff --git a/src/pp/pp_sim/pp_sim_core.c b/src/pp/pp_sim/pp_sim_core.c index 4eacf3cf..8abb400f 100644 --- a/src/pp/pp_sim/pp_sim_core.c +++ b/src/pp/pp_sim/pp_sim_core.c @@ -356,28 +356,6 @@ void S_TickForever(WaveLaneCtx *lane) ent->xf = xf; } - ////////////////////////////// - //- Solve followers - - for (S_Ent *ent = S_FirstEnt(&iter, world); ent->active; ent = S_NextEnt(&iter)) - { - S_Ent *follow = S_EntFromKey(&lookup, ent->follow); - if (follow->active) - { - f32 follow_speed = 20 * sim_dt; - Vec2 look_ratio = Zi; - look_ratio.y = 0.25; - look_ratio.x = look_ratio.y / (16.0 / 9.0); - - Vec2 target = MulXformV2(follow->xf, follow->local_shape.centroid); - target = AddVec2(target, MulVec2Vec2(follow->look, look_ratio)); - - Xform xf = ent->xf; - xf.og = LerpVec2(xf.og, target, follow_speed); - ent->xf = xf; - } - } - ////////////////////////////// //- Publish sim state diff --git a/src/pp/pp_sim/pp_sim_core.h b/src/pp/pp_sim/pp_sim_core.h index a6eb2dbd..b19a6380 100644 --- a/src/pp/pp_sim/pp_sim_core.h +++ b/src/pp/pp_sim/pp_sim_core.h @@ -49,11 +49,7 @@ Struct(S_Ent) Xform xf; S_Shape local_shape; - S_Key follow; - S_Key camera; - f32 move_speed; - Vec2 move; Vec2 look; diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 9c1f1c31..e5ce0e24 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -139,6 +139,8 @@ void V_TickForever(WaveLaneCtx *lane) frame->time_ns = TimeNs(); frame->tick = last_frame->tick + 1; + frame->dt_ns = frame->time_ns - last_frame->time_ns; + frame->dt = SecondsFromNs(frame->dt_ns); S_Iter iter = Zi; S_EntList spawn_ents = Zi; @@ -149,9 +151,8 @@ void V_TickForever(WaveLaneCtx *lane) if (frame->tick == 1) { S_Key child_key = S_RandKey(); - S_Key camera_key = S_RandKey(); - i32 count = 2; + i32 count = 1; for (u64 i = 0; i < count; ++i) { S_EntListNode *n = PushStruct(frame->arena, S_EntListNode); @@ -165,7 +166,6 @@ void V_TickForever(WaveLaneCtx *lane) case 0: { ent->key = V.player_key; - ent->camera = camera_key; ent->move_speed = 0.1; { ent->local_shape = S_ShapeFromDesc( @@ -179,13 +179,6 @@ void V_TickForever(WaveLaneCtx *lane) ent->has_weapon = 1; } break; - /* Test camera */ - case 1: - { - ent->key = camera_key; - ent->follow = V.player_key; - } break; - default: { Assert(0); @@ -259,12 +252,22 @@ void V_TickForever(WaveLaneCtx *lane) f32 meters_per_draw_width = 20; - Vec2 camera_pos = Zi; - f32 camera_zoom = 1; { - S_Ent *player = S_EntFromKey(&V.lookup, V.player_key); - S_Ent *camera = S_EntFromKey(&V.lookup, player->camera); - camera_pos = MulXformV2(camera->xf, camera->local_shape.centroid); + f32 lerp_ratio = 20 * frame->dt; + Vec2 look_ratio = Zi; + look_ratio.y = 0.25; + look_ratio.x = look_ratio.y / (16.0 / 9.0); + + Vec2 target_camera_pos = Zi; + f32 target_camera_zoom = 1; + { + S_Ent *player = S_EntFromKey(&V.lookup, V.player_key); + target_camera_pos = MulXformV2(player->xf, player->local_shape.centroid); + target_camera_pos = AddVec2(target_camera_pos, MulVec2Vec2(player->look, look_ratio)); + } + + 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); } ////////////////////////////// @@ -278,7 +281,7 @@ void V_TickForever(WaveLaneCtx *lane) scale.x = (f32)draw_size.x / meters_per_draw_width; scale.y = scale.x; world_to_draw_xf = XformFromScale(scale); - world_to_draw_xf = TranslateXform(world_to_draw_xf, NegVec2(camera_pos)); + world_to_draw_xf = TranslateXform(world_to_draw_xf, NegVec2(frame->camera_pos)); world_to_draw_xf = WorldTranslateXform(world_to_draw_xf, MulVec2(Vec2FromVec(draw_size), 0.5)); draw_to_world_xf = InvertXform(world_to_draw_xf); } diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 35189ac3..84f1d82b 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -80,8 +80,13 @@ Struct(V_Frame) Arena *dvert_idxs_arena; G_ArenaHandle gpu_arena; + Vec2 camera_pos; + f32 camera_zoom; + i64 tick; i64 time_ns; + i64 dt_ns; + f64 dt; G_CommandListHandle cl; };