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