bounding-box skin

This commit is contained in:
jacob 2026-02-10 14:06:48 -06:00
parent 1e393394c1
commit 19b7601c5f
2 changed files with 76 additions and 62 deletions

View File

@ -173,14 +173,15 @@ P_Shape P_MulXformShape(Xform xf, P_Shape shape)
Rng2 P_BoundingBoxFromShape(P_Shape shape)
{
f32 skin = 0.01;
Vec2 left = P_SupportPointFromShape(shape, VEC2(-1, 0)).p;
Vec2 top = P_SupportPointFromShape(shape, VEC2(0, -1)).p;
Vec2 right = P_SupportPointFromShape(shape, VEC2(1, 0)).p;
Vec2 bottom = P_SupportPointFromShape(shape, VEC2(0, 1)).p;
Rng2 result = Zi;
result.p0 = VEC2(left.x, top.y);
result.p1 = VEC2(right.x, bottom.y);
result.p0 = VEC2(left.x - skin, top.y - skin);
result.p1 = VEC2(right.x + skin, bottom.y + skin);
return result;
}
@ -1377,7 +1378,7 @@ P_Space P_SpaceFromWalls(Arena *arena, P_Frame *frame)
{
Vec2 p0 = VEC2(wall->start.x / P_TilesPerMeter - P_WorldPitch / 2, wall->start.y / P_TilesPerMeter - P_WorldPitch / 2);
Vec2 p1 = VEC2(wall->end.x / P_TilesPerMeter - P_WorldPitch / 2, wall->end.y / P_TilesPerMeter - P_WorldPitch / 2);
P_Shape shape = P_ShapeFromDesc(.count = 2, .points = { p0, p1 }, .radius = 0.01 );
P_Shape shape = P_ShapeFromDesc(.count = 2, .points = { p0, p1 }, .radius = 0.01 );
Rng2 aabb = P_BoundingBoxFromShape(shape);
aabb = AddRng2Vec2(aabb, VEC2(P_WorldPitch / 2.0, P_WorldPitch / 2.0));
aabb.p0 = FloorVec2(aabb.p0);
@ -1926,10 +1927,7 @@ void P_StepFrame(P_Frame *frame)
{
// TODO: Something better than linear distance for scoring
f32 score = Vec2Len(SubVec2(ent->xf.t, spawn->ent->xf.t));
// if (score < 10)
{
spawn->score = MinF32(spawn->score, score);
}
spawn->score = MinF32(spawn->score, score);
}
}
}
@ -2041,12 +2039,13 @@ void P_StepFrame(P_Frame *frame)
f32 solver_dt = sim_dt / solver_steps_count;
// Solid params
// SoftSpring solid_spring = MakeSpring(TweakFloat("Contact spring hz", 25, 5, 200), TweakFloat("Contact spring damp", 10, 5, 100), solver_dt);
SoftSpring solid_spring = MakeSpring(TweakFloat("Contact spring hz", 100, 5, 200), TweakFloat("Contact spring damp", 10, 5, 100), solver_dt);
f32 solid_pushout_velocity = TweakFloat("Contact spring pushout", 3, 0, 50);
// Gentle params
// f32 gentle_pushout_factor = TweakFloat("Gentle pushout factor", 10, 0, 50);
f32 gentle_pushout_factor = TweakFloat("Gentle pushout factor", 0.1, 0, 50);
f32 gentle_pushout_factor = TweakFloat("Gentle pushout factor", 0.5, 0, 50);
//////////////////////////////
//- Bake world
@ -2613,6 +2612,60 @@ void P_StepFrame(P_Frame *frame)
f32 tweak_speed = TweakFloat("Bullet speed", 100, 1, 100);
b32 can_fire = (firer->last_fire_ns + NsFromSeconds(1.0 / fire_rate)) <= frame->time_ns;
Vec2 fire_pos = Zi;
Vec2 fire_dir = Zi;
if (can_fire)
{
Vec2 look = firer->control.look;
P_Anim anim = P_AnimFromEnt(firer, frame->time_ns);
SPR_Sprite body = SPR_SpriteFromSheet(anim.sheet, anim.span, anim.frame_seq);
SPR_Sprite wep = SPR_SpriteFromSheet(anim.wep_sheet, anim.span, anim.frame_seq);
//- Compute sprite transforms
Affine ent_to_world_af = MulAffineXform(AffineIdentity, firer->xf);
Affine body_pix_to_world_af = AffineIdentity;
Affine wep_pix_to_world_af = AffineIdentity;
{
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
//- Compute body transform
Affine body_pix_to_ent_af = AffineIdentity;
{
body_pix_to_ent_af = ScaleAffine(body_pix_to_ent_af, pix_scale);
SPR_Ray anchor_ray = body.rays[SPR_RayKind_Anchor];
body_pix_to_ent_af = RotateAffine(body_pix_to_ent_af, InvertRot(anchor_ray.dir));
body_pix_to_ent_af = TranslateAffine(body_pix_to_ent_af, NegVec2(anchor_ray.pos));
}
//- Compute weapon transform
Affine wep_pix_to_ent_af = AffineIdentity;
{
wep_pix_to_ent_af = ScaleAffine(wep_pix_to_ent_af, pix_scale);
SPR_Ray body_anchor_ray = body.rays[SPR_RayKind_Anchor];
SPR_Ray body_ap_ray = body.rays[SPR_RayKind_Ap];
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, InvertRot(body_anchor_ray.dir));
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, SubVec2(body_ap_ray.pos, body_anchor_ray.pos));
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, InvertRot(body_ap_ray.dir));
SPR_Ray anchor_ray = wep.rays[SPR_RayKind_Anchor];
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, anchor_ray.dir);
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, NegVec2(anchor_ray.pos));
}
body_pix_to_world_af = MulAffine(ent_to_world_af, body_pix_to_ent_af);
wep_pix_to_world_af = MulAffine(ent_to_world_af, wep_pix_to_ent_af);
}
SPR_Ray fire_ray = wep.rays[SPR_RayKind_Ap];
fire_pos = MulAffineVec2(wep_pix_to_world_af, fire_ray.pos);
fire_dir = NormRot(MulAffineBasisVec2(wep_pix_to_world_af, fire_ray.dir));
// FIXME: Prevent obstructed weapons from firing through walls
}
if (can_fire)
{
i64 tick_bullets_count = bullets_per_fire;
@ -2623,57 +2676,6 @@ void P_StepFrame(P_Frame *frame)
// Vec2 fire_pos = P_EdgePointFromShape(firer_world_shape, firer->control.look);
// Vec2 fire_dir = firer->control.look;
Vec2 fire_pos = Zi;
Vec2 fire_dir = Zi;
{
Vec2 look = firer->control.look;
P_Anim anim = P_AnimFromEnt(firer, frame->time_ns);
SPR_Sprite body = SPR_SpriteFromSheet(anim.sheet, anim.span, anim.frame_seq);
SPR_Sprite wep = SPR_SpriteFromSheet(anim.wep_sheet, anim.span, anim.frame_seq);
//- Compute sprite transforms
Affine ent_to_world_af = MulAffineXform(AffineIdentity, firer->xf);
Affine body_pix_to_world_af = AffineIdentity;
Affine wep_pix_to_world_af = AffineIdentity;
{
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
//- Compute body transform
Affine body_pix_to_ent_af = AffineIdentity;
{
body_pix_to_ent_af = ScaleAffine(body_pix_to_ent_af, pix_scale);
SPR_Ray anchor_ray = body.rays[SPR_RayKind_Anchor];
body_pix_to_ent_af = RotateAffine(body_pix_to_ent_af, InvertRot(anchor_ray.dir));
body_pix_to_ent_af = TranslateAffine(body_pix_to_ent_af, NegVec2(anchor_ray.pos));
}
//- Compute weapon transform
Affine wep_pix_to_ent_af = AffineIdentity;
{
wep_pix_to_ent_af = ScaleAffine(wep_pix_to_ent_af, pix_scale);
SPR_Ray body_anchor_ray = body.rays[SPR_RayKind_Anchor];
SPR_Ray body_ap_ray = body.rays[SPR_RayKind_Ap];
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, InvertRot(body_anchor_ray.dir));
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, SubVec2(body_ap_ray.pos, body_anchor_ray.pos));
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, InvertRot(body_ap_ray.dir));
SPR_Ray anchor_ray = wep.rays[SPR_RayKind_Anchor];
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, anchor_ray.dir);
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, NegVec2(anchor_ray.pos));
}
body_pix_to_world_af = MulAffine(ent_to_world_af, body_pix_to_ent_af);
wep_pix_to_world_af = MulAffine(ent_to_world_af, wep_pix_to_ent_af);
}
SPR_Ray fire_ray = wep.rays[SPR_RayKind_Ap];
fire_pos = MulAffineVec2(wep_pix_to_world_af, fire_ray.pos);
fire_dir = NormRot(MulAffineBasisVec2(wep_pix_to_world_af, fire_ray.dir));
}
// FIXME: Prevent obstructed weapons from firing through walls
for (i64 bullet_idx = 0; bullet_idx < tick_bullets_count; ++bullet_idx)
{
P_Ent *bullet = P_PushTempEnt(scratch.arena, &bullets_to_spawn);
@ -2719,6 +2721,8 @@ void P_StepFrame(P_Frame *frame)
Vec2 ray_end = bullet->bullet_end;
Vec2 ray_dir = SubVec2(ray_end, ray_start);
P_DebugDrawLine(bullet->bullet_start, bullet->bullet_end, Color_Red);
// TODO: Real raycast query
P_Ent *victim = &P_NilEnt;
P_RaycastResult victim_raycast = Zi;

View File

@ -4730,6 +4730,8 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Initialization pass
b32 disable_vis_draw = TweakBool("Disable vis draw", 0);
{
// Prepare shade
G_Compute(frame->cl, V_PrepareShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims));
@ -4743,10 +4745,17 @@ void V_TickForever(WaveLaneCtx *lane)
G_Compute(frame->cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap));
}
// Discard screen RT
G_DiscardRenderTarget(frame->cl, screen_target);
// Prepare screen RT
if (disable_vis_draw)
{
G_ClearRenderTarget(frame->cl, screen_target, VEC4(0, 0, 0, 0));
}
else
{
G_DiscardRenderTarget(frame->cl, screen_target);
}
// Clear albedo RT
// Prepare albedo RT
G_ClearRenderTarget(frame->cl, albedo_target, VEC4(0, 0, 0, 0));
}
@ -4804,6 +4813,7 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Composite pass
if (!disable_vis_draw)
{
G_Rasterize(
frame->cl,