Counter Strike : Global Offensive Source Code
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.

207 lines
4.3 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "death_pose.h"
  8. // NOTE: This has to be the last file included!
  9. #include "tier0/memdbgon.h"
  10. #ifdef CLIENT_DLL
  11. void GetRagdollCurSequenceWithDeathPose( C_BaseAnimating *entity, matrix3x4a_t *curBones, float flTime, int activity, int frame )
  12. {
  13. // blow the cached prev bones
  14. entity->InvalidateBoneCache();
  15. Vector vPrevOrigin = entity->GetAbsOrigin();
  16. entity->Interpolate( flTime );
  17. if ( activity != ACT_INVALID )
  18. {
  19. Vector vNewOrigin = entity->GetAbsOrigin();
  20. Vector vDirection = vNewOrigin - vPrevOrigin;
  21. float flVelocity = VectorNormalize( vDirection );
  22. Vector vAdjustedOrigin = vNewOrigin + vDirection * ( ( flVelocity * flVelocity ) * gpGlobals->frametime );
  23. int iTempSequence = entity->GetSequence();
  24. float flTempCycle = entity->GetCycle();
  25. entity->SetEffects( EF_NOINTERP );
  26. entity->SetSequence( activity );
  27. entity->SetCycle( (float)frame / MAX_DEATHPOSE_FRAMES );
  28. entity->SetAbsOrigin( vAdjustedOrigin );
  29. // Now do the current bone setup
  30. entity->SetupBones( curBones, MAXSTUDIOBONES, BONE_USED_BY_ANYTHING, flTime );
  31. entity->SetAbsOrigin( vNewOrigin );
  32. // blow the cached prev bones
  33. entity->InvalidateBoneCache();
  34. entity->SetSequence( iTempSequence );
  35. entity->SetCycle( flTempCycle );
  36. entity->Interpolate( gpGlobals->curtime );
  37. entity->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, gpGlobals->curtime );
  38. entity->RemoveEffects( EF_NOINTERP );
  39. }
  40. else
  41. {
  42. entity->SetupBones( curBones, MAXSTUDIOBONES, BONE_USED_BY_ANYTHING, flTime );
  43. // blow the cached prev bones
  44. entity->InvalidateBoneCache();
  45. entity->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, flTime );
  46. }
  47. }
  48. #else // !CLIENT_DLL
  49. Activity GetDeathPoseActivity( CBaseAnimating *entity, const CTakeDamageInfo &info )
  50. {
  51. if ( !entity )
  52. {
  53. return ACT_INVALID;
  54. }
  55. // Get the entity's current activity.
  56. Activity aCurrentActivity = entity->GetSequenceActivity( entity->GetSequence() );
  57. // Determine if the enitiy is crouched or not
  58. bool bCrouched = false;
  59. switch ( aCurrentActivity )
  60. {
  61. case ACT_CROUCHIDLE:
  62. case ACT_RUN_CROUCH:
  63. bCrouched = true;
  64. break;
  65. }
  66. Activity aActivity;
  67. Vector vForward, vRight;
  68. entity->GetVectors( &vForward, &vRight, NULL );
  69. Vector vDir = -info.GetDamageForce();
  70. VectorNormalize( vDir );
  71. float flDotForward = DotProduct( vForward, vDir );
  72. float flDotRight = DotProduct( vRight, vDir );
  73. bool bNegativeForward = false;
  74. bool bNegativeRight = false;
  75. if ( flDotForward < 0.0f )
  76. {
  77. bNegativeForward = true;
  78. flDotForward = flDotForward * -1;
  79. }
  80. if ( flDotRight < 0.0f )
  81. {
  82. bNegativeRight = true;
  83. flDotRight = flDotRight * -1;
  84. }
  85. if ( flDotRight > flDotForward )
  86. {
  87. if ( bNegativeRight == true )
  88. {
  89. if ( bCrouched == true )
  90. aActivity = ACT_DIE_CROUCH_LEFTSIDE;
  91. else
  92. aActivity = ACT_DIE_LEFTSIDE;
  93. }
  94. else
  95. {
  96. if ( bCrouched == true )
  97. aActivity = ACT_DIE_CROUCH_RIGHTSIDE;
  98. else
  99. aActivity = ACT_DIE_RIGHTSIDE;
  100. }
  101. }
  102. else
  103. {
  104. if ( bNegativeForward == true )
  105. {
  106. if ( bCrouched == true )
  107. aActivity = ACT_DIE_CROUCH_BACKSIDE;
  108. else
  109. aActivity = ACT_DIE_BACKSIDE;
  110. }
  111. else
  112. {
  113. if ( bCrouched == true )
  114. aActivity = ACT_DIE_CROUCH_FRONTSIDE;
  115. else
  116. aActivity = ACT_DIE_FRONTSIDE;
  117. }
  118. }
  119. return aActivity;
  120. }
  121. void SelectDeathPoseActivityAndFrame( CBaseAnimating *entity, const CTakeDamageInfo &info, int hitgroup, Activity& activity, int& frame )
  122. {
  123. activity = ACT_INVALID;
  124. frame = 0;
  125. if ( !entity->GetModelPtr() )
  126. return;
  127. activity = GetDeathPoseActivity( entity, info );
  128. frame = DEATH_FRAME_HEAD;
  129. switch( hitgroup )
  130. {
  131. //Do normal ragdoll stuff if no specific hitgroup was hit.
  132. case HITGROUP_GENERIC:
  133. default:
  134. {
  135. return;
  136. }
  137. case HITGROUP_HEAD:
  138. {
  139. frame = DEATH_FRAME_HEAD;
  140. break;
  141. }
  142. case HITGROUP_LEFTARM:
  143. frame = DEATH_FRAME_LEFTARM;
  144. break;
  145. case HITGROUP_RIGHTARM:
  146. frame = DEATH_FRAME_RIGHTARM;
  147. break;
  148. case HITGROUP_CHEST:
  149. case HITGROUP_STOMACH:
  150. frame = DEATH_FRAME_STOMACH;
  151. break;
  152. case HITGROUP_LEFTLEG:
  153. frame = DEATH_FRAME_LEFTLEG;
  154. break;
  155. case HITGROUP_RIGHTLEG:
  156. frame = DEATH_FRAME_RIGHTLEG;
  157. break;
  158. }
  159. }
  160. #endif // !CLIENT_DLL