@@ -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,23 @@ 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)
1519- return ;
1520-
1521- if (!m_firstPersonBody) // initialize our fp body and bone sets
1534+ if (!m_firstPersonBody && psActorFlags.test (AF_FIRST_PERSON_BODY) && cam_active == eacFirstEye) // initialize first person body if necessary
15221535 {
15231536 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-
15411537 g_SetAnimation (mstate_real, true ); // Yohji: hacky way to reset anim state / bones when our visual changes
1542-
15431538 return ;
15441539 }
15451540
15461541 IKinematics* kinematics = m_firstPersonBody->dcast_PKinematics ();
1542+ IKinematics* realBodyK = Visual ()->dcast_PKinematics ();
15471543
1544+ // adjust body position
15481545 Fvector camdir = { cam_Active ()->Direction ().x , 0 .f , cam_Active ()->Direction ().z }; // ignore Y (vertical) value
15491546 Fmatrix trans = XFORM ();
15501547 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
1548+ XFORM ().translate_over (trans.c ); // move our original body to where our first person body is, so shadow renders in correct place
15521549
15531550 // Add body to render
15541551 GEnv.Render ->add_Visual (context_id, root, m_firstPersonBody, trans);
@@ -1561,14 +1558,18 @@ void CActor::RenderBodyWithoutHeadAndArms(u32 context_id, IRenderable* root)
15611558 if (m_firstPersonBodyBonesToIgnoreAnims[i])
15621559 continue ;
15631560
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));
1561+ kinematics->LL_GetTransform (i).set (realBodyK ->LL_GetTransform (i));
1562+ kinematics->LL_GetTransform_R (i).set (realBodyK ->LL_GetTransform_R (i));
15661563 }
15671564
15681565 // Hide bones
15691566 for (auto [boneId, vis] : m_firstPersonBodyBonesToHide)
15701567 kinematics->LL_SetBoneVisible (boneId, !vis, true );
15711568
1569+ // Update head position
1570+ headPosition.set (trans);
1571+ headPosition.mulB_43 (realBodyK->LL_GetTransform (realBodyK->LL_BoneID (" bip01_head" )));
1572+
15721573#ifdef DEBUG
15731574 Fvector ypr;
15741575 trans.getHPB (ypr);
@@ -1577,7 +1578,11 @@ void CActor::RenderBodyWithoutHeadAndArms(u32 context_id, IRenderable* root)
15771578 F->SetAligment (CGameFont::alLeft);
15781579 F->OutSetI (-.9 , 0 );
15791580 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 );
1581+ xr_sprintf (text, " first person body position [%3.3f %3.3f %3.3f]" , trans.c .x , trans.c .y , trans.c .z );
1582+ F->OutNext (text);
1583+ xr_sprintf (text, " head position [%3.3f %3.3f %3.3f]" , headPosition.c .x , headPosition.c .y , headPosition.c .z );
1584+ F->OutNext (text);
1585+ xr_sprintf (text, " camera position [%3.3f %3.3f %3.3f]" , cam_Active ()->Position ().x , cam_Active ()->Position ().y , cam_Active ()->Position ().z );
15811586 F->OutNext (text);
15821587#endif // DEBUG
15831588}
0 commit comments