Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "death_pose.h"
  8. #ifdef CLIENT_DLL
  9. void GetRagdollCurSequenceWithDeathPose( C_BaseAnimating *entity, matrix3x4_t *curBones, float flTime, int activity, int frame )
  10. {
  11. // blow the cached prev bones
  12. entity->InvalidateBoneCache();
  13. Vector vPrevOrigin = entity->GetAbsOrigin();
  14. entity->Interpolate( flTime );
  15. if ( activity != ACT_INVALID )
  16. {
  17. Vector vNewOrigin = entity->GetAbsOrigin();
  18. Vector vDirection = vNewOrigin - vPrevOrigin;
  19. float flVelocity = VectorNormalize( vDirection );
  20. Vector vAdjustedOrigin = vNewOrigin + vDirection * ( ( flVelocity * flVelocity ) * gpGlobals->frametime );
  21. int iTempSequence = entity->GetSequence();
  22. float flTempCycle = entity->GetCycle();
  23. entity->SetSequence( activity );
  24. entity->SetCycle( (float)frame / MAX_DEATHPOSE_FRAMES );
  25. entity->SetAbsOrigin( vAdjustedOrigin );
  26. // Now do the current bone setup
  27. entity->SetupBones( curBones, MAXSTUDIOBONES, BONE_USED_BY_ANYTHING, flTime );
  28. entity->SetAbsOrigin( vNewOrigin );
  29. // blow the cached prev bones
  30. entity->InvalidateBoneCache();
  31. entity->SetSequence( iTempSequence );
  32. entity->SetCycle( flTempCycle );
  33. entity->Interpolate( gpGlobals->curtime );
  34. entity->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, gpGlobals->curtime );
  35. }
  36. else
  37. {
  38. entity->SetupBones( curBones, MAXSTUDIOBONES, BONE_USED_BY_ANYTHING, flTime );
  39. // blow the cached prev bones
  40. entity->InvalidateBoneCache();
  41. entity->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, flTime );
  42. }
  43. }
  44. #else // !CLIENT_DLL
  45. Activity GetDeathPoseActivity( CBaseAnimating *entity, const CTakeDamageInfo &info )
  46. {
  47. if ( !entity )
  48. {
  49. return ACT_INVALID;
  50. }
  51. Activity aActivity;
  52. Vector vForward, vRight;
  53. entity->GetVectors( &vForward, &vRight, NULL );
  54. Vector vDir = -info.GetDamageForce();
  55. VectorNormalize( vDir );
  56. float flDotForward = DotProduct( vForward, vDir );
  57. float flDotRight = DotProduct( vRight, vDir );
  58. bool bNegativeForward = false;
  59. bool bNegativeRight = false;
  60. if ( flDotForward < 0.0f )
  61. {
  62. bNegativeForward = true;
  63. flDotForward = flDotForward * -1;
  64. }
  65. if ( flDotRight < 0.0f )
  66. {
  67. bNegativeRight = true;
  68. flDotRight = flDotRight * -1;
  69. }
  70. if ( flDotRight > flDotForward )
  71. {
  72. if ( bNegativeRight == true )
  73. aActivity = ACT_DIE_LEFTSIDE;
  74. else
  75. aActivity = ACT_DIE_RIGHTSIDE;
  76. }
  77. else
  78. {
  79. if ( bNegativeForward == true )
  80. aActivity = ACT_DIE_BACKSIDE;
  81. else
  82. aActivity = ACT_DIE_FRONTSIDE;
  83. }
  84. return aActivity;
  85. }
  86. void SelectDeathPoseActivityAndFrame( CBaseAnimating *entity, const CTakeDamageInfo &info, int hitgroup, Activity& activity, int& frame )
  87. {
  88. activity = ACT_INVALID;
  89. frame = 0;
  90. if ( !entity->GetModelPtr() )
  91. return;
  92. activity = GetDeathPoseActivity( entity, info );
  93. frame = DEATH_FRAME_HEAD;
  94. switch( hitgroup )
  95. {
  96. //Do normal ragdoll stuff if no specific hitgroup was hit.
  97. case HITGROUP_GENERIC:
  98. default:
  99. {
  100. return;
  101. }
  102. case HITGROUP_HEAD:
  103. {
  104. frame = DEATH_FRAME_HEAD;
  105. break;
  106. }
  107. case HITGROUP_LEFTARM:
  108. frame = DEATH_FRAME_LEFTARM;
  109. break;
  110. case HITGROUP_RIGHTARM:
  111. frame = DEATH_FRAME_RIGHTARM;
  112. break;
  113. case HITGROUP_CHEST:
  114. case HITGROUP_STOMACH:
  115. frame = DEATH_FRAME_STOMACH;
  116. break;
  117. case HITGROUP_LEFTLEG:
  118. frame = DEATH_FRAME_LEFTLEG;
  119. break;
  120. case HITGROUP_RIGHTLEG:
  121. frame = DEATH_FRAME_RIGHTLEG;
  122. break;
  123. }
  124. }
  125. #endif // !CLIENT_DLL