@@ -461,6 +461,22 @@ void CActor::Load(LPCSTR section)
461461 m_sInventoryBoxUseAction = " inventory_box_use" ;
462462 // ---------------------------------------------------------------------
463463 m_sHeadShotParticle = READ_IF_EXISTS (pSettings, r_string, section, " HeadShotParticle" , 0 );
464+
465+ // initialize bones for first person body
466+ m_firstPersonBodyBonesToHide =
467+ {
468+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_head" ), true },
469+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_neck" ), true },
470+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_l_clavicle" ), true },
471+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_r_clavicle" ), true },
472+ };
473+
474+ m_firstPersonBodyBonesToIgnoreAnims =
475+ {
476+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_spine" ), true },
477+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_spine1" ), true },
478+ { Visual ()->dcast_PKinematics ()->LL_BoneID (" bip01_spine2" ), true },
479+ };
464480}
465481
466482void CActor::PHHit (SHit& H) { m_pPhysics_support->in_Hit (H, false ); }
@@ -1513,42 +1529,26 @@ bool CActor::renderable_ShadowGenerate()
15131529}
15141530
15151531extern float g_first_person_body_offset;
1516- void CActor::RenderBodyWithoutHeadAndArms (u32 context_id, IRenderable* root)
1532+ void CActor::RenderFirstPersonBody (u32 context_id, IRenderable* root)
15171533{
1518- if (!(psActorFlags.test (AF_FIRST_PERSON_BODY)) || cam_active != eacFirstEye)
1534+ if (!(psActorFlags.test (AF_FIRST_PERSON_BODY) && cam_active == eacFirstEye) )
15191535 return ;
15201536
1521- if (!m_firstPersonBody) // initialize our fp body and bone sets
1537+ if (!m_firstPersonBody) // initialize first person body if necessary
15221538 {
15231539 m_firstPersonBody = GEnv.Render ->model_Duplicate (Visual ());
1524- IKinematics* kinematics = m_firstPersonBody->dcast_PKinematics ();
1525-
1526- m_firstPersonBodyBonesToHide =
1527- {
1528- { kinematics->LL_BoneID (" bip01_head" ), true },
1529- { kinematics->LL_BoneID (" bip01_neck" ), true },
1530- { kinematics->LL_BoneID (" bip01_l_clavicle" ), true },
1531- { kinematics->LL_BoneID (" bip01_r_clavicle" ), true },
1532- };
1533-
1534- m_firstPersonBodyBonesToIgnoreAnims =
1535- {
1536- { kinematics->LL_BoneID (" bip01_spine" ), true },
1537- { kinematics->LL_BoneID (" bip01_spine1" ), true },
1538- { kinematics->LL_BoneID (" bip01_spine2" ), true },
1539- };
1540-
15411540 g_SetAnimation (mstate_real, true ); // Yohji: hacky way to reset anim state / bones when our visual changes
1542-
15431541 return ;
15441542 }
15451543
15461544 IKinematics* kinematics = m_firstPersonBody->dcast_PKinematics ();
1545+ IKinematics* realBodyK = Visual ()->dcast_PKinematics ();
15471546
1547+ // adjust body position
15481548 Fvector camdir = { cam_Active ()->Direction ().x , 0 .f , cam_Active ()->Direction ().z }; // ignore Y (vertical) value
15491549 Fmatrix trans = XFORM ();
15501550 trans.c .add (camdir.normalize ().mul (g_first_person_body_offset)); // push model back so it doesn't look weird (default value: -0.75f)
1551- XFORM ().translate_over (trans.c ); // move our original body to where our first person body is, so shadow render in correct place
1551+ XFORM ().translate_over (trans.c ); // move our original body to where our first person body is, so shadow renders in correct place
15521552
15531553 // Add body to render
15541554 GEnv.Render ->add_Visual (context_id, root, m_firstPersonBody, trans);
@@ -1561,14 +1561,18 @@ void CActor::RenderBodyWithoutHeadAndArms(u32 context_id, IRenderable* root)
15611561 if (m_firstPersonBodyBonesToIgnoreAnims[i])
15621562 continue ;
15631563
1564- kinematics->LL_GetTransform (i).set (Visual ()-> dcast_PKinematics () ->LL_GetTransform (i));
1565- kinematics->LL_GetTransform_R (i).set (Visual ()-> dcast_PKinematics () ->LL_GetTransform_R (i));
1564+ kinematics->LL_GetTransform (i).set (realBodyK ->LL_GetTransform (i));
1565+ kinematics->LL_GetTransform_R (i).set (realBodyK ->LL_GetTransform_R (i));
15661566 }
15671567
15681568 // Hide bones
15691569 for (auto [boneId, vis] : m_firstPersonBodyBonesToHide)
15701570 kinematics->LL_SetBoneVisible (boneId, !vis, true );
15711571
1572+ // Update head position
1573+ headPosition.set (trans);
1574+ headPosition.mulB_43 (realBodyK->LL_GetTransform (realBodyK->LL_BoneID (" bip01_head" )));
1575+
15721576#ifdef DEBUG
15731577 Fvector ypr;
15741578 trans.getHPB (ypr);
@@ -1577,7 +1581,11 @@ void CActor::RenderBodyWithoutHeadAndArms(u32 context_id, IRenderable* root)
15771581 F->SetAligment (CGameFont::alLeft);
15781582 F->OutSetI (-.9 , 0 );
15791583 F->SetColor (color_rgba (255 , 0 , 0 , 255 ));
1580- xr_sprintf (text, " fp legs position [%3.3f %3.3f %3.3f] rotation [%3.3f %3.3f %3.3f]" , trans.c .x , trans.c .y , trans.c .z , ypr.x , ypr.y , ypr.z );
1584+ xr_sprintf (text, " first person body position [%3.3f %3.3f %3.3f]" , trans.c .x , trans.c .y , trans.c .z );
1585+ F->OutNext (text);
1586+ xr_sprintf (text, " head position [%3.3f %3.3f %3.3f]" , headPosition.c .x , headPosition.c .y , headPosition.c .z );
1587+ F->OutNext (text);
1588+ xr_sprintf (text, " camera position [%3.3f %3.3f %3.3f]" , cam_Active ()->Position ().x , cam_Active ()->Position ().y , cam_Active ()->Position ().z );
15811589 F->OutNext (text);
15821590#endif // DEBUG
15831591}
0 commit comments