actual entity transform rotation
This commit is contained in:
parent
c26488870a
commit
80f9434af8
35
src/pp/pp.c
35
src/pp/pp.c
@ -1709,24 +1709,8 @@ void P_StepFrame(P_Frame *frame)
|
|||||||
{
|
{
|
||||||
P_Control control = guy->control;
|
P_Control control = guy->control;
|
||||||
|
|
||||||
// Affine af = guy->af;
|
// Dampen movement
|
||||||
// Affine desired_af = af;
|
|
||||||
// if (!IsVec2Zero(control.look))
|
|
||||||
// {
|
|
||||||
// desired_af = AffineWithWorldRotation(af, AngleFromVec2(control.look));
|
|
||||||
// }
|
|
||||||
// f32 move_speed = TweakFloat("Guy move speed", 6.5, 0, 20);
|
|
||||||
// desired_af.og = AddVec2(af.og, MulVec2(control.move, move_speed * sim_dt));
|
|
||||||
|
|
||||||
// Vec2 pos_diff = SubVec2(desired_af.og, af.og);
|
|
||||||
// f32 angle_diff = UnwindAngleF32(RotationFromAffine(desired_af) - RotationFromAffine(af));
|
|
||||||
|
|
||||||
// guy->solved_v = pos_diff;
|
|
||||||
// guy->solved_w = angle_diff;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// f32 damp_vel = damp_force * sim_dt;
|
|
||||||
|
|
||||||
if (Vec2Len(guy->solved_v) > 0.001)
|
if (Vec2Len(guy->solved_v) > 0.001)
|
||||||
{
|
{
|
||||||
f32 damp_force = TweakFloat("Guy damp force", 50, 0, 100);
|
f32 damp_force = TweakFloat("Guy damp force", 50, 0, 100);
|
||||||
@ -1739,24 +1723,31 @@ void P_StepFrame(P_Frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Integrate linear movement
|
||||||
{
|
{
|
||||||
f32 move_force = TweakFloat("Guy move force", 400, 0, 400);
|
f32 move_force = TweakFloat("Guy move force", 400, 0, 400);
|
||||||
f32 max_speed = TweakFloat("Guy max speed", 10, 0, 20);
|
f32 max_speed = TweakFloat("Guy max speed", 10, 0, 20);
|
||||||
|
|
||||||
Vec2 new_velocity = guy->solved_v;
|
Vec2 new_velocity = guy->solved_v;
|
||||||
new_velocity = AddVec2(new_velocity, MulVec2(control.move, move_force * sim_dt));
|
new_velocity = AddVec2(new_velocity, MulVec2(control.move, move_force * sim_dt));
|
||||||
|
|
||||||
if (Vec2Len(new_velocity) > max_speed)
|
if (Vec2Len(new_velocity) > max_speed)
|
||||||
{
|
{
|
||||||
new_velocity = Vec2WithLen(new_velocity, max_speed);
|
new_velocity = Vec2WithLen(new_velocity, max_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
guy->solved_v = new_velocity;
|
guy->solved_v = new_velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Integrate look
|
||||||
|
{
|
||||||
|
f32 turn_rate = TweakFloat("Guy turn rate", 1, 0, 1);
|
||||||
|
f32 cur_angle = AngleFromVec2(guy->xf.r);
|
||||||
|
f32 desired_angle = AngleFromVec2(control.look);
|
||||||
|
f32 diff = UnwindAngleF32(desired_angle - cur_angle);
|
||||||
|
f32 look_force = 1.0 / (sim_dt * sim_dt) * turn_rate;
|
||||||
|
guy->solved_w = diff * sim_dt * look_force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
\
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Copy previous frame's constraints
|
//- Copy previous frame's constraints
|
||||||
|
|
||||||
|
|||||||
@ -1876,11 +1876,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
Affine wep_pix_to_world_af = AffineIdentity;
|
Affine wep_pix_to_world_af = AffineIdentity;
|
||||||
{
|
{
|
||||||
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
|
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
|
||||||
|
Affine ent_to_world_af = MulAffineXform(AffineIdentity, ent->xf);
|
||||||
// FIXME: Remove this, use ent rotation
|
|
||||||
Xform ent_to_world_xf = ent->xf;
|
|
||||||
ent_to_world_xf = XformTR(ent->xf.t, NormRot(ent->control.look));
|
|
||||||
Affine ent_to_world_af = MulAffineXform(AffineIdentity, ent_to_world_xf);
|
|
||||||
|
|
||||||
//- Compute body transform
|
//- Compute body transform
|
||||||
{
|
{
|
||||||
@ -1946,51 +1942,60 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
SPR_Sprite wep = SPR_SpriteFromSheet(anim.wep_sheet, anim.span, anim.frame_seq);
|
SPR_Sprite wep = SPR_SpriteFromSheet(anim.wep_sheet, anim.span, anim.frame_seq);
|
||||||
|
|
||||||
//- Compute sprite transforms
|
//- Compute sprite transforms
|
||||||
Affine body_pix_to_world_af = AffineIdentity;
|
|
||||||
Affine wep_pix_to_world_af = AffineIdentity;
|
Affine cur_body_pix_to_world_af = AffineIdentity;
|
||||||
|
Affine cur_wep_pix_to_world_af = AffineIdentity;
|
||||||
|
Affine desired_body_pix_to_world_af = AffineIdentity;
|
||||||
|
Affine desired_wep_pix_to_world_af = AffineIdentity;
|
||||||
{
|
{
|
||||||
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
|
Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter);
|
||||||
|
|
||||||
// FIXME: Remove this, use ent rotation
|
Affine cur_ent_to_world_af = MulAffineXform(AffineIdentity, ent->xf);
|
||||||
Xform ent_to_world_xf = ent->xf;
|
Affine desired_ent_to_world_af = MulAffineXform(AffineIdentity, XformTR(ent->xf.t, NormRot(ent->control.look)));
|
||||||
ent_to_world_xf = XformTR(ent->xf.t, NormRot(ent->control.look));
|
|
||||||
Affine ent_to_world_af = MulAffineXform(AffineIdentity, ent_to_world_xf);
|
|
||||||
|
|
||||||
//- Compute body transform
|
//- Compute body transform
|
||||||
|
Affine body_pix_to_ent_af = AffineIdentity;
|
||||||
{
|
{
|
||||||
body_pix_to_world_af = MulAffine(body_pix_to_world_af, ent_to_world_af);
|
body_pix_to_ent_af = ScaleAffine(body_pix_to_ent_af, pix_scale);
|
||||||
body_pix_to_world_af = ScaleAffine(body_pix_to_world_af, pix_scale);
|
|
||||||
|
|
||||||
SPR_Ray anchor_ray = body.rays[SPR_RayKind_Anchor];
|
SPR_Ray anchor_ray = body.rays[SPR_RayKind_Anchor];
|
||||||
body_pix_to_world_af = RotateAffine(body_pix_to_world_af, InvertRot(anchor_ray.dir));
|
body_pix_to_ent_af = RotateAffine(body_pix_to_ent_af, InvertRot(anchor_ray.dir));
|
||||||
body_pix_to_world_af = TranslateAffine(body_pix_to_world_af, NegVec2(anchor_ray.pos));
|
body_pix_to_ent_af = TranslateAffine(body_pix_to_ent_af, NegVec2(anchor_ray.pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Compute weapon transform
|
//- Compute weapon transform
|
||||||
|
Affine wep_pix_to_ent_af = AffineIdentity;
|
||||||
{
|
{
|
||||||
wep_pix_to_world_af = MulAffine(wep_pix_to_world_af, ent_to_world_af);
|
wep_pix_to_ent_af = ScaleAffine(wep_pix_to_ent_af, pix_scale);
|
||||||
wep_pix_to_world_af = ScaleAffine(wep_pix_to_world_af, pix_scale);
|
|
||||||
|
|
||||||
SPR_Ray body_anchor_ray = body.rays[SPR_RayKind_Anchor];
|
SPR_Ray body_anchor_ray = body.rays[SPR_RayKind_Anchor];
|
||||||
SPR_Ray body_ap_ray = body.rays[SPR_RayKind_Ap];
|
SPR_Ray body_ap_ray = body.rays[SPR_RayKind_Ap];
|
||||||
wep_pix_to_world_af = RotateAffine(wep_pix_to_world_af, InvertRot(body_anchor_ray.dir));
|
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, InvertRot(body_anchor_ray.dir));
|
||||||
wep_pix_to_world_af = TranslateAffine(wep_pix_to_world_af, SubVec2(body_ap_ray.pos, body_anchor_ray.pos));
|
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, SubVec2(body_ap_ray.pos, body_anchor_ray.pos));
|
||||||
wep_pix_to_world_af = RotateAffine(wep_pix_to_world_af, InvertRot(body_ap_ray.dir));
|
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];
|
SPR_Ray anchor_ray = wep.rays[SPR_RayKind_Anchor];
|
||||||
wep_pix_to_world_af = RotateAffine(wep_pix_to_world_af, anchor_ray.dir);
|
wep_pix_to_ent_af = RotateAffine(wep_pix_to_ent_af, anchor_ray.dir);
|
||||||
wep_pix_to_world_af = TranslateAffine(wep_pix_to_world_af, NegVec2(anchor_ray.pos));
|
wep_pix_to_ent_af = TranslateAffine(wep_pix_to_ent_af, NegVec2(anchor_ray.pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_body_pix_to_world_af = MulAffine(cur_ent_to_world_af, body_pix_to_ent_af);
|
||||||
|
cur_wep_pix_to_world_af = MulAffine(cur_ent_to_world_af, wep_pix_to_ent_af);
|
||||||
|
desired_body_pix_to_world_af = MulAffine(desired_ent_to_world_af, body_pix_to_ent_af);
|
||||||
|
desired_wep_pix_to_world_af = MulAffine(desired_ent_to_world_af, wep_pix_to_ent_af);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPR_Ray fire_ray = wep.rays[SPR_RayKind_Ap];
|
SPR_Ray fire_ray = wep.rays[SPR_RayKind_Ap];
|
||||||
|
|
||||||
Vec2 fire_pos = MulAffineVec2(wep_pix_to_world_af, fire_ray.pos);
|
Vec2 cur_fire_pos = MulAffineVec2(cur_wep_pix_to_world_af, fire_ray.pos);
|
||||||
Vec2 fire_dir = NormRot(MulAffineBasisVec2(wep_pix_to_world_af, fire_ray.dir));
|
Vec2 cur_fire_dir = NormRot(MulAffineBasisVec2(cur_wep_pix_to_world_af, fire_ray.dir));
|
||||||
|
Vec2 desired_fire_pos = MulAffineVec2(desired_wep_pix_to_world_af, fire_ray.pos);
|
||||||
|
Vec2 desired_fire_dir = NormRot(MulAffineBasisVec2(desired_wep_pix_to_world_af, fire_ray.dir));
|
||||||
|
|
||||||
Vec2 look_dir = NormRot(frame->look);
|
Vec2 look_dir = NormRot(frame->look);
|
||||||
|
|
||||||
Vec2 line_start = fire_pos;
|
Vec2 line_start = cur_fire_pos;
|
||||||
Vec2 line_end = AddVec2(line_start, fire_dir);
|
Vec2 line_end = AddVec2(line_start, cur_fire_dir);
|
||||||
P_DebugDrawLine(line_start, line_end, Color_Yellow);
|
P_DebugDrawLine(line_start, line_end, Color_Yellow);
|
||||||
|
|
||||||
// Vec2 cross = fire_pos;
|
// Vec2 cross = fire_pos;
|
||||||
@ -1999,7 +2004,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
// f32 cross_dist = 1.0;
|
// f32 cross_dist = 1.0;
|
||||||
f32 cross_dist = Vec2Len(frame->look);
|
f32 cross_dist = Vec2Len(frame->look);
|
||||||
|
|
||||||
Vec2 cross = AddVec2(fire_pos, MulVec2(look_dir, cross_dist));
|
Vec2 cross = AddVec2(desired_fire_pos, MulVec2(look_dir, cross_dist));
|
||||||
|
|
||||||
// P_DebugDrawPoint(AddVec2(MulAffineVec2(frame->af.screen_to_world, MulVec2(frame->screen_dims, 0.5)), frame->look), Color_Red);
|
// P_DebugDrawPoint(AddVec2(MulAffineVec2(frame->af.screen_to_world, MulVec2(frame->screen_dims, 0.5)), frame->look), Color_Red);
|
||||||
P_DebugDrawPoint(cross, Color_Green);
|
P_DebugDrawPoint(cross, Color_Green);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user