move camera logic to vis layer

This commit is contained in:
jacob 2025-12-16 17:02:29 -06:00
parent 1de54d60ba
commit 2144de02a0
4 changed files with 24 additions and 42 deletions

View File

@ -356,28 +356,6 @@ void S_TickForever(WaveLaneCtx *lane)
ent->xf = xf; 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 //- Publish sim state

View File

@ -49,11 +49,7 @@ Struct(S_Ent)
Xform xf; Xform xf;
S_Shape local_shape; S_Shape local_shape;
S_Key follow;
S_Key camera;
f32 move_speed; f32 move_speed;
Vec2 move; Vec2 move;
Vec2 look; Vec2 look;

View File

@ -139,6 +139,8 @@ void V_TickForever(WaveLaneCtx *lane)
frame->time_ns = TimeNs(); frame->time_ns = TimeNs();
frame->tick = last_frame->tick + 1; 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_Iter iter = Zi;
S_EntList spawn_ents = Zi; S_EntList spawn_ents = Zi;
@ -149,9 +151,8 @@ void V_TickForever(WaveLaneCtx *lane)
if (frame->tick == 1) if (frame->tick == 1)
{ {
S_Key child_key = S_RandKey(); 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) for (u64 i = 0; i < count; ++i)
{ {
S_EntListNode *n = PushStruct(frame->arena, S_EntListNode); S_EntListNode *n = PushStruct(frame->arena, S_EntListNode);
@ -165,7 +166,6 @@ void V_TickForever(WaveLaneCtx *lane)
case 0: case 0:
{ {
ent->key = V.player_key; ent->key = V.player_key;
ent->camera = camera_key;
ent->move_speed = 0.1; ent->move_speed = 0.1;
{ {
ent->local_shape = S_ShapeFromDesc( ent->local_shape = S_ShapeFromDesc(
@ -179,13 +179,6 @@ void V_TickForever(WaveLaneCtx *lane)
ent->has_weapon = 1; ent->has_weapon = 1;
} break; } break;
/* Test camera */
case 1:
{
ent->key = camera_key;
ent->follow = V.player_key;
} break;
default: default:
{ {
Assert(0); Assert(0);
@ -259,12 +252,22 @@ void V_TickForever(WaveLaneCtx *lane)
f32 meters_per_draw_width = 20; f32 meters_per_draw_width = 20;
Vec2 camera_pos = Zi; {
f32 camera_zoom = 1; 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); S_Ent *player = S_EntFromKey(&V.lookup, V.player_key);
S_Ent *camera = S_EntFromKey(&V.lookup, player->camera); target_camera_pos = MulXformV2(player->xf, player->local_shape.centroid);
camera_pos = MulXformV2(camera->xf, camera->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.x = (f32)draw_size.x / meters_per_draw_width;
scale.y = scale.x; scale.y = scale.x;
world_to_draw_xf = XformFromScale(scale); 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)); world_to_draw_xf = WorldTranslateXform(world_to_draw_xf, MulVec2(Vec2FromVec(draw_size), 0.5));
draw_to_world_xf = InvertXform(world_to_draw_xf); draw_to_world_xf = InvertXform(world_to_draw_xf);
} }

View File

@ -80,8 +80,13 @@ Struct(V_Frame)
Arena *dvert_idxs_arena; Arena *dvert_idxs_arena;
G_ArenaHandle gpu_arena; G_ArenaHandle gpu_arena;
Vec2 camera_pos;
f32 camera_zoom;
i64 tick; i64 tick;
i64 time_ns; i64 time_ns;
i64 dt_ns;
f64 dt;
G_CommandListHandle cl; G_CommandListHandle cl;
}; };