6 static void player__dead_update(void){
7 player_ragdoll_iter( &localplayer
.ragdoll
);
10 static void player__dead_post_update(void){
11 struct player_avatar
*av
= localplayer
.playeravatar
;
12 struct ragdoll_part
*part
= &localplayer
.ragdoll
.parts
[ av
->id_hip
-1 ];
13 struct player_dead
*d
= &player_dead
;
17 rb_extrapolate( &part
->obj
.rb
, ext_co
, ext_q
);
19 v3_lerp( d
->co_lpf
, ext_co
, vg
.time_frame_delta
*4.0f
, d
->co_lpf
);
20 v3_lerp( d
->v_lpf
, part
->obj
.rb
.v
, vg
.time_frame_delta
*4.0f
, d
->v_lpf
);
21 v3_lerp( d
->w_lpf
, part
->obj
.rb
.w
, vg
.time_frame_delta
*4.0f
, d
->w_lpf
);
23 v3_copy( d
->co_lpf
, localplayer
.rb
.co
);
24 v3_zero( localplayer
.rb
.v
);
25 v3_zero( localplayer
.rb
.w
);
28 static void player__dead_animate(void){
29 struct player_dead
*d
= &player_dead
;
30 struct player_dead_animator
*animator
= &d
->animator
;
31 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
32 struct player_avatar
*av
= localplayer
.playeravatar
;
33 struct skeleton
*sk
= &av
->sk
;
35 m4x3f transforms
[ 32 ];
38 q_m3x3( localplayer
.rb
.q
, transforms
[0] );
39 v3_copy( localplayer
.rb
.co
, transforms
[0][3] );
41 v4_copy( localplayer
.rb
.q
, animator
->transforms
[0].q
);
42 v3_copy( localplayer
.rb
.co
, animator
->transforms
[0].co
);
44 /* colliders with bones transforms */
45 for( int i
=0; i
<rd
->part_count
; i
++ ){
46 struct ragdoll_part
*part
= &rd
->parts
[i
];
53 float substep
= vg
.time_fixed_extrapolate
;
54 v3_lerp( part
->prev_co
, part
->obj
.rb
.co
, substep
, co_int
);
55 q_nlerp( part
->prev_q
, part
->obj
.rb
.q
, substep
, q_int
);
56 v4_copy( part
->obj
.rb
.q
, q_int
);
59 v3_copy( co_int
, mtx
[3] );
61 m4x3_mul( mtx
, part
->inv_collider_mtx
, transforms
[part
->bone_id
] );
64 /* bones without colliders transforms */
65 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
66 struct skeleton_bone
*sb
= &sk
->bones
[i
];
68 if( sb
->parent
&& !sb
->collider
){
70 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, delta
);
73 m3x3_identity( posemtx
);
74 v3_copy( delta
, posemtx
[3] );
77 m4x3_mul( transforms
[sb
->parent
], posemtx
, transforms
[i
] );
82 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
83 struct skeleton_bone
*sb
= &sk
->bones
[i
];
85 v3_zero( animator
->transforms
[i
].co
);
86 q_identity( animator
->transforms
[i
].q
);
88 m4x3f parent
, inverse
, local
;
89 m3x3_identity( parent
);
90 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, parent
[3] );
91 m4x3_mul( transforms
[ sb
->parent
], parent
, parent
);
92 m4x3_invert_affine( parent
, inverse
);
95 m4x3_mul( inverse
, transforms
[i
], local
);
96 m4x3_decompose( local
, animator
->transforms
[i
].co
,
97 animator
->transforms
[i
].q
, _s
);
101 static void player__dead_pose( void *_animator
, player_pose
*pose
){
102 struct player_dead_animator
*animator
= _animator
;
103 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
104 struct player_avatar
*av
= localplayer
.playeravatar
;
105 struct skeleton
*sk
= &av
->sk
;
107 pose
->type
= k_player_pose_type_fk_2
;
108 pose
->board
.lean
= 0.0f
;
110 v3_copy( animator
->transforms
[0].co
, pose
->root_co
);
111 v4_copy( animator
->transforms
[0].q
, pose
->root_q
);
113 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
114 v3_copy( animator
->transforms
[i
].co
, pose
->keyframes
[i
-1].co
);
115 v4_copy( animator
->transforms
[i
].q
, pose
->keyframes
[i
-1].q
);
116 v3_fill( pose
->keyframes
[i
-1].s
, 1.0f
);
120 static void player__dead_post_animate(void){
121 localplayer
.cam_velocity_influence
= 1.0f
;
124 static void player__dead_im_gui(void){
127 static void player__dead_transition(void){
128 localplayer
.subsystem
= k_player_subsystem_dead
;
129 copy_avatar_pose_to_ragdoll( localplayer
.playeravatar
, &localplayer
.ragdoll
,
132 struct player_avatar
*av
= localplayer
.playeravatar
;
133 struct ragdoll_part
*part
= &localplayer
.ragdoll
.parts
[ av
->id_hip
-1 ];
134 v3_copy( part
->obj
.rb
.co
, player_dead
.co_lpf
);
135 v3_copy( part
->obj
.rb
.v
, player_dead
.v_lpf
);
136 v3_copy( part
->obj
.rb
.w
, player_dead
.w_lpf
);
139 static void player__dead_animator_exchange( bitpack_ctx
*ctx
, void *data
){
140 struct player_dead_animator
*animator
= data
;
142 for( u32 i
=0; i
<localplayer
.playeravatar
->sk
.bone_count
; i
++ ){
143 bitpack_qv3f( ctx
, 24, -1024.0f
, 1024.0f
, animator
->transforms
[i
].co
);
144 bitpack_qquat( ctx
, animator
->transforms
[i
].q
);
148 #endif /* PLAYER_DEAD_C */