6 #include "vg/vg_perlin.h"
8 #include "ent_skateshop.h"
11 static void player__skate_bind(void){
12 struct player_avatar
*av
= localplayer
.playeravatar
;
13 struct skeleton
*sk
= &av
->sk
;
15 rb_update_transform( &localplayer
.rb
);
17 struct { struct skeleton_anim
**anim
; const char *name
; }
19 { &player_skate
.anim_grind
, "pose_grind" },
20 { &player_skate
.anim_grind_jump
, "pose_grind_jump" },
21 { &player_skate
.anim_stand
, "pose_stand" },
22 { &player_skate
.anim_highg
, "pose_highg" },
23 { &player_skate
.anim_air
, "pose_air" },
24 { &player_skate
.anim_slide
, "pose_slide" },
25 { &player_skate
.anim_push
, "push" },
26 { &player_skate
.anim_push_reverse
, "push_reverse" },
27 { &player_skate
.anim_ollie
, "ollie" },
28 { &player_skate
.anim_ollie_reverse
,"ollie_reverse" },
29 { &player_skate
.anim_grabs
, "grabs" }
32 for( u32 i
=0; i
<vg_list_size(bindings
); i
++ )
33 *bindings
[i
].anim
= skeleton_get_anim( sk
, bindings
[i
].name
);
36 static void player__skate_kill_audio(void){
38 if( player_skate
.aud_main
){
39 player_skate
.aud_main
=
40 audio_channel_fadeout( player_skate
.aud_main
, 0.1f
);
42 if( player_skate
.aud_air
){
43 player_skate
.aud_air
=
44 audio_channel_fadeout( player_skate
.aud_air
, 0.1f
);
46 if( player_skate
.aud_slide
){
47 player_skate
.aud_slide
=
48 audio_channel_fadeout( player_skate
.aud_slide
, 0.1f
);
54 * Collision detection routines
60 * Does collision detection on a sphere vs world, and applies some smoothing
61 * filters to the manifold afterwards
63 static int skate_collide_smooth( m4x3f mtx
, rb_sphere
*sphere
, rb_ct
*man
){
64 world_instance
*world
= world_current_instance();
67 len
= rb_sphere__scene( mtx
, sphere
, NULL
, &world
->rb_geo
.inf
.scene
, man
,
68 k_material_flag_walking
);
70 for( int i
=0; i
<len
; i
++ ){
71 man
[i
].rba
= &localplayer
.rb
;
75 rb_manifold_filter_coplanar( man
, len
, 0.03f
);
78 rb_manifold_filter_backface( man
, len
);
79 rb_manifold_filter_joint_edges( man
, len
, 0.03f
);
80 rb_manifold_filter_pairs( man
, len
, 0.03f
);
82 int new_len
= rb_manifold_apply_filtered( man
, len
);
96 static int skate_grind_scansq( v3f pos
, v3f dir
, float r
,
97 struct grind_info
*inf
){
98 world_instance
*world
= world_current_instance();
101 v3_copy( dir
, plane
);
102 v3_normalize( plane
);
103 plane
[3] = v3_dot( plane
, pos
);
106 v3_add( pos
, (v3f
){ r
, r
, r
}, box
[1] );
107 v3_sub( pos
, (v3f
){ r
, r
, r
}, box
[0] );
116 int sample_count
= 0;
122 v3_cross( plane
, localplayer
.basis
[1], support_axis
);
123 v3_normalize( support_axis
);
126 bh_iter_init_box( 0, &it
, box
);
129 while( bh_next( world
->geo_bh
, &it
, &idx
) ){
130 u32
*ptri
= &world
->scene_geo
.arrindices
[ idx
*3 ];
133 struct world_surface
*surf
= world_tri_index_surface(world
,ptri
[0]);
134 if( !(surf
->info
.flags
& k_material_flag_grindable
) )
137 for( int j
=0; j
<3; j
++ )
138 v3_copy( world
->scene_geo
.arrvertices
[ptri
[j
]].co
, tri
[j
] );
140 for( int j
=0; j
<3; j
++ ){
144 struct grind_sample
*sample
= &samples
[ sample_count
];
147 if( plane_segment( plane
, tri
[i0
], tri
[i1
], co
) ){
149 v3_sub( co
, pos
, d
);
150 if( v3_length2( d
) > r
*r
)
154 v3_sub( tri
[1], tri
[0], va
);
155 v3_sub( tri
[2], tri
[0], vb
);
156 v3_cross( va
, vb
, normal
);
158 sample
->normal
[0] = v3_dot( support_axis
, normal
);
159 sample
->normal
[1] = v3_dot( localplayer
.basis
[1], normal
);
160 sample
->co
[0] = v3_dot( support_axis
, d
);
161 sample
->co
[1] = v3_dot( localplayer
.basis
[1], d
);
163 v3_copy( normal
, sample
->normal3
); /* normalize later
164 if we want to us it */
166 v3_muls( tri
[0], 1.0f
/3.0f
, sample
->centroid
);
167 v3_muladds( sample
->centroid
, tri
[1], 1.0f
/3.0f
, sample
->centroid
);
168 v3_muladds( sample
->centroid
, tri
[2], 1.0f
/3.0f
, sample
->centroid
);
170 v2_normalize( sample
->normal
);
173 if( sample_count
== vg_list_size( samples
) )
174 goto too_many_samples
;
181 if( sample_count
< 2 )
189 v2_fill( min_co
, INFINITY
);
190 v2_fill( max_co
, -INFINITY
);
192 v3_zero( average_direction
);
193 v3_zero( average_normal
);
195 int passed_samples
= 0;
197 for( int i
=0; i
<sample_count
-1; i
++ ){
198 struct grind_sample
*si
, *sj
;
202 for( int j
=i
+1; j
<sample_count
; j
++ ){
208 /* non overlapping */
209 if( v2_dist2( si
->co
, sj
->co
) >= (0.01f
*0.01f
) )
212 /* not sharp angle */
213 if( v2_dot( si
->normal
, sj
->normal
) >= 0.7f
)
218 v3_sub( sj
->centroid
, si
->centroid
, v0
);
219 if( v3_dot( v0
, si
->normal3
) >= 0.0f
||
220 v3_dot( v0
, sj
->normal3
) <= 0.0f
)
223 v2_minv( sj
->co
, min_co
, min_co
);
224 v2_maxv( sj
->co
, max_co
, max_co
);
227 v3_copy( si
->normal3
, n0
);
228 v3_copy( sj
->normal3
, n1
);
229 v3_cross( n0
, n1
, dir
);
232 /* make sure the directions all face a common hemisphere */
233 v3_muls( dir
, vg_signf(v3_dot(dir
,plane
)), dir
);
234 v3_add( average_direction
, dir
, average_direction
);
236 float yi
= v3_dot( localplayer
.basis
[1], si
->normal3
),
237 yj
= v3_dot( localplayer
.basis
[1], sj
->normal3
);
239 if( yi
> yj
) v3_add( si
->normal3
, average_normal
, average_normal
);
240 else v3_add( sj
->normal3
, average_normal
, average_normal
);
246 if( !passed_samples
)
249 if( (v3_length2( average_direction
) <= 0.001f
) ||
250 (v3_length2( average_normal
) <= 0.001f
) )
253 float div
= 1.0f
/(float)passed_samples
;
254 v3_normalize( average_direction
);
255 v3_normalize( average_normal
);
258 v2_add( min_co
, max_co
, average_coord
);
259 v2_muls( average_coord
, 0.5f
, average_coord
);
261 v3_muls( support_axis
, average_coord
[0], inf
->co
);
262 inf
->co
[1] += average_coord
[1];
263 v3_add( pos
, inf
->co
, inf
->co
);
264 v3_copy( average_normal
, inf
->n
);
265 v3_copy( average_direction
, inf
->dir
);
267 vg_line_point( inf
->co
, 0.02f
, VG__GREEN
);
268 vg_line_arrow( inf
->co
, average_direction
, 0.3f
, VG__GREEN
);
269 vg_line_arrow( inf
->co
, inf
->n
, 0.2f
, VG__CYAN
);
271 return passed_samples
;
274 static void reset_jump_info( jump_info
*inf
){
276 inf
->land_dist
= 0.0f
;
278 inf
->type
= k_prediction_unset
;
279 v3_zero( inf
->apex
);
282 static int create_jumps_to_hit_target( jump_info
*jumps
,
283 v3f target
, float max_angle_delta
,
285 /* calculate the exact 2 solutions to jump onto that grind spot */
288 v3_sub( target
, localplayer
.rb
.co
, v0
);
289 m3x3_mulv( localplayer
.invbasis
, v0
, v0
);
297 m3x3_mulv( localplayer
.invbasis
, localplayer
.rb
.v
, v_local
);
299 v2f d
= { v3_dot( ax
, v0
), v0
[1] },
300 v
= { v3_dot( ax
, v_local
), v_local
[1] };
302 float a
= atan2f( v
[1], v
[0] ),
304 root
= m
*m
*m
*m
- gravity
*(gravity
*d
[0]*d
[0] + 2.0f
*d
[1]*m
*m
);
309 root
= sqrtf( root
);
310 float a0
= atanf( (m
*m
+ root
) / (gravity
* d
[0]) ),
311 a1
= atanf( (m
*m
- root
) / (gravity
* d
[0]) );
313 if( fabsf(a0
-a
) < max_angle_delta
){
314 jump_info
*inf
= &jumps
[ valid_count
++ ];
315 reset_jump_info( inf
);
317 v3_muls( ax
, cosf( a0
) * m
, inf
->v
);
318 inf
->v
[1] += sinf( a0
) * m
;
319 m3x3_mulv( localplayer
.basis
, inf
->v
, inf
->v
);
320 inf
->land_dist
= d
[0] / (cosf(a0
)*m
);
321 inf
->gravity
= gravity
;
323 v3_copy( target
, inf
->log
[inf
->log_length
++] );
326 if( fabsf(a1
-a
) < max_angle_delta
){
327 jump_info
*inf
= &jumps
[ valid_count
++ ];
328 reset_jump_info( inf
);
330 v3_muls( ax
, cosf( a1
) * m
, inf
->v
);
331 inf
->v
[1] += sinf( a1
) * m
;
332 m3x3_mulv( localplayer
.basis
, inf
->v
, inf
->v
);
333 inf
->land_dist
= d
[0] / (cosf(a1
)*m
);
334 inf
->gravity
= gravity
;
336 v3_copy( target
, inf
->log
[inf
->log_length
++] );
343 static void player__approximate_best_trajectory(void){
344 world_instance
*world0
= world_current_instance();
346 float k_trace_delta
= k_rb_delta
* 10.0f
;
347 struct player_skate_state
*state
= &player_skate
.state
;
349 state
->air_start
= vg
.time
;
350 v3_copy( localplayer
.rb
.v
, state
->air_init_v
);
351 v3_copy( localplayer
.rb
.co
, state
->air_init_co
);
353 player_skate
.possible_jump_count
= 0;
356 v3_cross( localplayer
.rb
.v
, localplayer
.rb
.to_world
[1], axis
);
357 v3_normalize( axis
);
359 /* at high slopes, Y component is low */
360 float upness
= v3_dot( localplayer
.rb
.to_world
[1], localplayer
.basis
[1] ),
361 angle_begin
= -(1.0f
-fabsf( upness
)),
364 struct grind_info grind
;
365 int grind_located
= 0;
366 float grind_located_gravity
= k_gravity
;
369 v3f launch_v_bounds
[2];
371 for( int i
=0; i
<2; i
++ ){
372 v3_copy( localplayer
.rb
.v
, launch_v_bounds
[i
] );
373 float ang
= (float[]){ angle_begin
, angle_end
}[ i
];
377 q_axis_angle( qbias
, axis
, ang
);
378 q_mulv( qbias
, launch_v_bounds
[i
], launch_v_bounds
[i
] );
381 for( int m
=0;m
<=30; m
++ ){
383 &player_skate
.possible_jumps
[ player_skate
.possible_jump_count
++ ];
384 reset_jump_info( inf
);
386 v3f launch_co
, launch_v
, co0
, co1
;
387 v3_copy( localplayer
.rb
.co
, launch_co
);
388 v3_copy( localplayer
.rb
.v
, launch_v
);
389 v3_copy( launch_co
, co0
);
390 world_instance
*trace_world
= world0
;
392 float vt
= (float)m
* (1.0f
/30.0f
),
393 ang
= vg_lerpf( angle_begin
, angle_end
, vt
) * 0.15f
;
396 q_axis_angle( qbias
, axis
, ang
);
397 q_mulv( qbias
, launch_v
, launch_v
);
399 float yaw_sketch
= 1.0f
-fabsf(upness
);
401 float yaw_bias
= ((float)(m
%3) - 1.0f
) * 0.08f
* yaw_sketch
;
402 q_axis_angle( qbias
, localplayer
.rb
.to_world
[1], yaw_bias
);
403 q_mulv( qbias
, launch_v
, launch_v
);
405 float gravity_bias
= vg_lerpf( 0.85f
, 1.4f
, vt
),
406 gravity
= k_gravity
* gravity_bias
;
407 inf
->gravity
= gravity
;
408 v3_copy( launch_v
, inf
->v
);
411 m3x3_copy( localplayer
.basis
, basis
);
413 for( int i
=1; i
<=50; i
++ ){
414 float t
= (float)i
* k_trace_delta
;
416 v3_muls( launch_v
, t
, co1
);
417 v3_muladds( co1
, basis
[1], -0.5f
* gravity
* t
*t
, co1
);
418 v3_add( launch_co
, co1
, co1
);
420 float launch_vy
= v3_dot( launch_v
,basis
[1] );
422 int search_for_grind
= 1;
423 if( grind_located
) search_for_grind
= 0;
424 if( launch_vy
- gravity
*t
> 0.0f
) search_for_grind
= 0;
428 v3f closest
={0.0f
,0.0f
,0.0f
};
429 if( search_for_grind
){
430 if( bh_closest_point(trace_world
->geo_bh
,co1
,closest
,1.0f
) != -1 ){
431 float min_dist
= 0.75f
;
432 min_dist
*= min_dist
;
434 if( v3_dist2( closest
, launch_co
) < min_dist
)
435 search_for_grind
= 0;
439 for( int j
=0; j
<2; j
++ ){
440 v3_muls( launch_v_bounds
[j
], t
, bound
[j
] );
441 v3_muladds( bound
[j
], basis
[1], -0.5f
*gravity
*t
*t
, bound
[j
] );
442 v3_add( launch_co
, bound
[j
], bound
[j
] );
445 float limh
= vg_minf( 2.0f
, t
),
446 minh
= vg_minf( bound
[0][1], bound
[1][1] )-limh
,
447 maxh
= vg_maxf( bound
[0][1], bound
[1][1] )+limh
;
449 if( (closest
[1] < minh
) || (closest
[1] > maxh
) ){
450 search_for_grind
= 0;
454 search_for_grind
= 0;
457 if( search_for_grind
){
459 v3_copy( launch_v
, ve
);
460 v3_muladds( ve
, basis
[1], -gravity
* t
, ve
);
462 if( skate_grind_scansq( closest
, ve
, 0.5f
, &grind
) ){
463 /* check alignment */
464 v2f v0
= { v3_dot( ve
, basis
[0] ),
465 v3_dot( ve
, basis
[2] ) },
466 v1
= { v3_dot( grind
.dir
, basis
[0] ),
467 v3_dot( grind
.dir
, basis
[2] ) };
472 float a
= v2_dot( v0
, v1
);
474 float a_min
= cosf( VG_PIf
* 0.185f
);
475 if( state
->grind_cooldown
)
476 a_min
= cosf( VG_PIf
* 0.05f
);
479 if( (fabsf(v3_dot( ve
, grind
.dir
))>=k_grind_axel_min_vel
) &&
481 (fabsf(grind
.dir
[1]) < 0.70710678118654752f
))
484 grind_located_gravity
= inf
->gravity
;
489 if( trace_world
->rendering_gate
){
490 ent_gate
*gate
= trace_world
->rendering_gate
;
491 if( gate_intersect( gate
, co1
, co0
) ){
492 m4x3_mulv( gate
->transport
, co0
, co0
);
493 m4x3_mulv( gate
->transport
, co1
, co1
);
494 m3x3_mulv( gate
->transport
, launch_v
, launch_v
);
495 m4x3_mulv( gate
->transport
, launch_co
, launch_co
);
496 m3x3_mul( gate
->transport
, basis
, basis
);
498 if( gate
->flags
& k_ent_gate_nonlocal
){
499 trace_world
= &world_static
.instances
[ gate
->target
];
507 float scan_radius
= k_board_radius
;
508 scan_radius
*= vg_clampf( t
, 0.02f
, 1.0f
);
510 int idx
= spherecast_world( trace_world
, co0
, co1
, scan_radius
, &t1
, n
,
511 k_material_flag_walking
);
514 v3_lerp( co0
, co1
, t1
, co
);
515 v3_copy( co
, inf
->log
[ inf
->log_length
++ ] );
517 v3_copy( n
, inf
->n
);
518 u32
*tri
= &trace_world
->scene_geo
.arrindices
[ idx
*3 ];
519 struct world_surface
*surf
=
520 world_tri_index_surface( trace_world
, tri
[0] );
522 inf
->type
= k_prediction_land
;
525 v3_copy( launch_v
, ve
);
526 v3_muladds( ve
, localplayer
.basis
[1], -gravity
* t
, ve
);
528 inf
->score
= -v3_dot( ve
, inf
->n
);
529 inf
->land_dist
= t
+ k_trace_delta
* t1
;
531 /* Bias prediction towords ramps */
532 if( !(surf
->info
.flags
& k_material_flag_skate_target
) )
535 if( surf
->info
.flags
& k_material_flag_boundary
)
536 player_skate
.possible_jump_count
--;
542 v3_copy( co1
, inf
->log
[ inf
->log_length
++ ] );
546 if( inf
->type
== k_prediction_unset
)
547 player_skate
.possible_jump_count
--;
551 jump_info grind_jumps
[2];
554 create_jumps_to_hit_target( grind_jumps
, grind
.co
,
555 0.175f
*VG_PIf
, grind_located_gravity
);
557 /* knock out original landing points in the 1m area */
558 for( u32 j
=0; j
<player_skate
.possible_jump_count
; j
++ ){
559 jump_info
*jump
= &player_skate
.possible_jumps
[ j
];
560 float dist
= v3_dist2( jump
->log
[jump
->log_length
-1], grind
.co
);
561 float descale
= 1.0f
-vg_minf(1.0f
,dist
);
562 jump
->score
+= descale
*3.0f
;
565 for( int i
=0; i
<valid_count
; i
++ ){
566 jump_info
*jump
= &grind_jumps
[i
];
567 jump
->type
= k_prediction_grind
;
569 v3f launch_v
, launch_co
, co0
, co1
;
571 v3_copy( jump
->v
, launch_v
);
572 v3_copy( localplayer
.rb
.co
, launch_co
);
575 m3x3_copy( localplayer
.basis
, basis
);
577 float t
= 0.05f
* jump
->land_dist
;
578 v3_muls( launch_v
, t
, co0
);
579 v3_muladds( co0
, basis
[1], -0.5f
* jump
->gravity
* t
*t
, co0
);
580 v3_add( launch_co
, co0
, co0
);
582 /* rough scan to make sure we dont collide with anything */
583 for( int j
=1; j
<=16; j
++ ){
584 t
= (float)j
*(1.0f
/16.0f
);
587 t
*= jump
->land_dist
;
589 v3_muls( launch_v
, t
, co1
);
590 v3_muladds( co1
, basis
[1], -0.5f
* jump
->gravity
* t
*t
, co1
);
591 v3_add( launch_co
, co1
, co1
);
596 int idx
= spherecast_world( world0
, co0
,co1
,
597 k_board_radius
*0.1f
, &t1
, n
,
598 k_material_flag_walking
);
600 goto invalidated_grind
;
606 v3_copy( grind
.n
, jump
->n
);
608 /* determine score */
610 v3_copy( jump
->v
, ve
);
611 v3_muladds( ve
, localplayer
.basis
[1],
612 -jump
->gravity
*jump
->land_dist
, ve
);
613 jump
->score
= -v3_dot( ve
, grind
.n
) * 0.9f
;
615 player_skate
.possible_jumps
[ player_skate
.possible_jump_count
++ ] =
624 float score_min
= INFINITY
,
625 score_max
= -INFINITY
;
627 jump_info
*best
= NULL
;
629 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
630 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
632 if( jump
->score
< score_min
)
635 score_min
= vg_minf( score_min
, jump
->score
);
636 score_max
= vg_maxf( score_max
, jump
->score
);
639 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
640 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
641 float s
= jump
->score
;
644 s
/= (score_max
-score_min
);
648 jump
->colour
= s
* 255.0f
;
652 else if( jump
->type
== k_prediction_land
)
655 jump
->colour
|= 0xff000000;
659 v3_copy( best
->n
, state
->land_normal
);
660 v3_copy( best
->v
, localplayer
.rb
.v
);
661 state
->land_dist
= best
->land_dist
;
662 state
->gravity_bias
= best
->gravity
;
664 if( best
->type
== k_prediction_grind
){
665 state
->activity
= k_skate_activity_air_to_grind
;
669 joystick_state( k_srjoystick_steer
, steer
);
670 v2_normalize_clamp( steer
);
672 if( (fabsf(steer
[1]) > 0.5f
) && (state
->land_dist
>= 1.5f
) ){
673 state
->flip_rate
= (1.0f
/state
->land_dist
) * vg_signf(steer
[1]) *
675 state
->flip_time
= 0.0f
;
676 v3_copy( localplayer
.rb
.to_world
[0], state
->flip_axis
);
679 state
->flip_rate
= 0.0f
;
680 v3_zero( state
->flip_axis
);
684 v3_copy( localplayer
.basis
[1], state
->land_normal
);
690 * Varius physics models
691 * ------------------------------------------------
695 * Air control, no real physics
697 static void skate_apply_air_model(void){
698 struct player_skate_state
*state
= &player_skate
.state
;
700 if( state
->activity_prev
> k_skate_activity_air_to_grind
)
701 player__approximate_best_trajectory();
703 float angle
= v3_dot( localplayer
.rb
.to_world
[1], state
->land_normal
);
704 angle
= vg_clampf( angle
, -1.0f
, 1.0f
);
706 v3_cross( localplayer
.rb
.to_world
[1], state
->land_normal
, axis
);
709 q_axis_angle( correction
, axis
,
710 acosf(angle
)*2.0f
*VG_TIMESTEP_FIXED
);
711 q_mul( correction
, localplayer
.rb
.q
, localplayer
.rb
.q
);
714 static enum trick_type
player_skate_trick_input(void);
715 static void skate_apply_trick_model(void){
716 struct player_skate_state
*state
= &player_skate
.state
;
719 v3f strength
= { 3.7f
, 3.6f
, 8.0f
};
721 v3_muls( state
->trick_residualv
, -4.0f
, Fd
);
722 v3_muls( state
->trick_residuald
, -10.0f
, Fs
);
724 v3_mul( strength
, F
, F
);
726 v3_muladds( state
->trick_residualv
, F
, k_rb_delta
,
727 state
->trick_residualv
);
728 v3_muladds( state
->trick_residuald
, state
->trick_residualv
,
729 k_rb_delta
, state
->trick_residuald
);
731 if( state
->activity
<= k_skate_activity_air_to_grind
){
732 if( v3_length2( state
->trick_vel
) < 0.0001f
)
735 int carry_on
= player_skate_trick_input();
737 /* we assume velocities share a common divisor, in which case the
738 * interval is the minimum value (if not zero) */
740 float min_rate
= 99999.0f
;
742 for( int i
=0; i
<3; i
++ ){
743 float v
= state
->trick_vel
[i
];
744 if( (v
> 0.0f
) && (v
< min_rate
) )
748 float interval
= 1.0f
/ min_rate
,
749 current
= floorf( state
->trick_time
/ interval
),
750 next_end
= (current
+1.0f
) * interval
;
753 /* integrate trick velocities */
754 v3_muladds( state
->trick_euler
, state
->trick_vel
, k_rb_delta
,
755 state
->trick_euler
);
757 if( !carry_on
&& (state
->trick_time
+ k_rb_delta
>= next_end
) ){
758 state
->trick_time
= 0.0f
;
759 state
->trick_euler
[0] = roundf( state
->trick_euler
[0] );
760 state
->trick_euler
[1] = roundf( state
->trick_euler
[1] );
761 state
->trick_euler
[2] = roundf( state
->trick_euler
[2] );
762 v3_copy( state
->trick_vel
, state
->trick_residualv
);
763 v3_zero( state
->trick_vel
);
766 state
->trick_time
+= k_rb_delta
;
769 if( (v3_length2(state
->trick_vel
) >= 0.0001f
) &&
770 state
->trick_time
> 0.2f
)
772 player__skate_kill_audio();
773 player__dead_transition();
776 state
->trick_euler
[0] = roundf( state
->trick_euler
[0] );
777 state
->trick_euler
[1] = roundf( state
->trick_euler
[1] );
778 state
->trick_euler
[2] = roundf( state
->trick_euler
[2] );
779 state
->trick_time
= 0.0f
;
780 v3_zero( state
->trick_vel
);
784 static void skate_apply_grab_model(void){
785 struct player_skate_state
*state
= &player_skate
.state
;
787 float grabt
= axis_state( k_sraxis_grab
);
790 v2_muladds( state
->grab_mouse_delta
, vg
.mouse_delta
, 0.02f
,
791 state
->grab_mouse_delta
);
793 v2_normalize_clamp( state
->grab_mouse_delta
);
796 v2_zero( state
->grab_mouse_delta
);
798 state
->grabbing
= vg_lerpf( state
->grabbing
, grabt
, 8.4f
*k_rb_delta
);
801 static void skate_apply_steering_model(void){
802 struct player_skate_state
*state
= &player_skate
.state
;
805 joystick_state( k_srjoystick_steer
, jsteer
);
808 float steer
= jsteer
[0],
809 grab
= axis_state( k_sraxis_grab
);
811 steer
= vg_signf( steer
) * steer
*steer
* k_steer_ground
;
814 v3_muls( localplayer
.rb
.to_world
[1], -vg_signf( steer
), steer_axis
);
819 if( state
->activity
<= k_skate_activity_air_to_grind
){
820 rate
= 6.0f
* fabsf(steer
);
824 /* rotate slower when grabbing on ground */
825 steer
*= (1.0f
-(state
->jump_charge
+grab
)*0.4f
);
827 if( state
->activity
== k_skate_activity_grind_5050
){
832 else if( state
->activity
>= k_skate_activity_grind_any
){
833 rate
*= fabsf(steer
);
835 float a
= 0.8f
* -steer
* k_rb_delta
;
838 q_axis_angle( q
, localplayer
.rb
.to_world
[1], a
);
839 q_mulv( q
, player_skate
.grind_vec
, player_skate
.grind_vec
);
841 v3_normalize( player_skate
.grind_vec
);
844 else if( state
->manual_direction
){
850 top
*= 1.0f
+v3_length( state
->throw_v
)*k_mmthrow_steer
;
854 float current
= v3_dot( localplayer
.rb
.to_world
[1], localplayer
.rb
.w
),
855 addspeed
= (steer
* -top
) - current
,
856 maxaccel
= rate
* k_rb_delta
,
857 accel
= vg_clampf( addspeed
, -maxaccel
, maxaccel
);
859 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1],
860 accel
, localplayer
.rb
.w
);
864 * Computes friction and surface interface model
866 static void skate_apply_friction_model(void){
867 struct player_skate_state
*state
= &player_skate
.state
;
870 * Computing localized friction forces for controlling the character
871 * Friction across X is significantly more than Z
875 m3x3_mulv( localplayer
.rb
.to_local
, localplayer
.rb
.v
, vel
);
878 if( fabsf(vel
[2]) > 0.01f
)
879 slip
= fabsf(-vel
[0] / vel
[2]) * vg_signf(vel
[0]);
881 if( fabsf( slip
) > 1.2f
)
882 slip
= vg_signf( slip
) * 1.2f
;
885 state
->reverse
= -vg_signf(vel
[2]);
887 vel
[0] += vg_cfrictf( vel
[0], k_friction_lat
* k_rb_delta
);
888 vel
[2] += vg_cfrictf( vel
[2], k_friction_resistance
* k_rb_delta
);
890 /* Pushing additive force */
892 if( !button_press( k_srbind_jump
) ){
893 if( button_press( k_srbind_push
) || (vg
.time
-state
->start_push
<0.75) )
895 if( (vg
.time
- state
->cur_push
) > 0.25 )
896 state
->start_push
= vg
.time
;
898 state
->cur_push
= vg
.time
;
900 double push_time
= vg
.time
- state
->start_push
;
902 float cycle_time
= push_time
*k_push_cycle_rate
,
903 accel
= k_push_accel
* (sinf(cycle_time
)*0.5f
+0.5f
),
904 amt
= accel
* VG_TIMESTEP_FIXED
,
905 current
= v3_length( vel
),
906 new_vel
= vg_minf( current
+ amt
, k_max_push_speed
),
907 delta
= new_vel
- vg_minf( current
, k_max_push_speed
);
909 vel
[2] += delta
* -state
->reverse
;
913 /* Send back to velocity */
914 m3x3_mulv( localplayer
.rb
.to_world
, vel
, localplayer
.rb
.v
);
917 static void skate_apply_jump_model(void){
918 struct player_skate_state
*state
= &player_skate
.state
;
919 int charging_jump_prev
= state
->charging_jump
;
920 state
->charging_jump
= button_press( k_srbind_jump
);
922 /* Cannot charge this in air */
923 if( state
->activity
<= k_skate_activity_air_to_grind
){
924 state
->charging_jump
= 0;
928 if( state
->charging_jump
){
929 state
->jump_charge
+= k_rb_delta
* k_jump_charge_speed
;
931 if( !charging_jump_prev
)
932 state
->jump_dir
= state
->reverse
>0.0f
? 1: 0;
935 state
->jump_charge
-= k_jump_charge_speed
* k_rb_delta
;
938 state
->jump_charge
= vg_clampf( state
->jump_charge
, 0.0f
, 1.0f
);
940 /* player let go after charging past 0.2: trigger jump */
941 if( (!state
->charging_jump
) && (state
->jump_charge
> 0.2f
) ){
944 /* Launch more up if alignment is up else improve velocity */
945 float aup
= v3_dot( localplayer
.basis
[1], localplayer
.rb
.to_world
[1] ),
947 dir
= mod
+ fabsf(aup
)*(1.0f
-mod
);
949 if( state
->activity
== k_skate_activity_ground
){
950 v3_copy( localplayer
.rb
.v
, jumpdir
);
951 v3_normalize( jumpdir
);
952 v3_muls( jumpdir
, 1.0f
-dir
, jumpdir
);
953 v3_muladds( jumpdir
, localplayer
.rb
.to_world
[1], dir
, jumpdir
);
954 v3_normalize( jumpdir
);
956 v3_copy( state
->up_dir
, jumpdir
);
957 state
->grind_cooldown
= 30;
958 state
->activity
= k_skate_activity_ground
;
961 joystick_state( k_srjoystick_steer
, steer
);
963 float tilt
= steer
[0] * 0.3f
;
964 tilt
*= vg_signf(v3_dot( localplayer
.rb
.v
,
965 player_skate
.grind_dir
));
968 q_axis_angle( qtilt
, player_skate
.grind_dir
, tilt
);
969 q_mulv( qtilt
, jumpdir
, jumpdir
);
971 state
->surface_cooldown
= 10;
973 float force
= k_jump_force
*state
->jump_charge
;
974 v3_muladds( localplayer
.rb
.v
, jumpdir
, force
, localplayer
.rb
.v
);
975 state
->jump_charge
= 0.0f
;
976 state
->jump_time
= vg
.time
;
977 player__networked_sfx( k_player_subsystem_skate
, 32,
978 k_player_skate_soundeffect_jump
,
979 localplayer
.rb
.co
, 1.0f
);
983 static void skate_apply_pump_model(void){
984 struct player_skate_state
*state
= &player_skate
.state
;
986 if( state
->activity
!= k_skate_activity_ground
){
987 v3_zero( state
->throw_v
);
991 /* Throw / collect routine
993 if( axis_state( k_sraxis_grab
) > 0.5f
){
994 if( state
->activity
== k_skate_activity_ground
){
996 v3_muls( localplayer
.rb
.to_world
[1], k_mmthrow_scale
, state
->throw_v
);
1001 float doty
= v3_dot( localplayer
.rb
.to_world
[1], state
->throw_v
);
1004 v3_muladds( state
->throw_v
, localplayer
.rb
.to_world
[1], -doty
, Fl
);
1006 if( state
->activity
== k_skate_activity_ground
){
1007 if( v3_length2(localplayer
.rb
.v
)<(20.0f
*20.0f
) ){
1008 v3_muladds( localplayer
.rb
.v
, Fl
,
1009 k_mmcollect_lat
, localplayer
.rb
.v
);
1011 v3_muladds( state
->throw_v
, Fl
, -k_mmcollect_lat
, state
->throw_v
);
1014 v3_muls( localplayer
.rb
.to_world
[1], -doty
, Fv
);
1015 v3_muladds( localplayer
.rb
.v
, Fv
, k_mmcollect_vert
, localplayer
.rb
.v
);
1016 v3_muladds( state
->throw_v
, Fv
, k_mmcollect_vert
, state
->throw_v
);
1020 if( v3_length2( state
->throw_v
) > 0.0001f
){
1022 v3_copy( state
->throw_v
, dir
);
1023 v3_normalize( dir
);
1025 float max
= v3_dot( dir
, state
->throw_v
),
1026 amt
= vg_minf( k_mmdecay
* k_rb_delta
, max
);
1027 v3_muladds( state
->throw_v
, dir
, -amt
, state
->throw_v
);
1031 static void skate_apply_cog_model(void){
1032 struct player_skate_state
*state
= &player_skate
.state
;
1034 v3f ideal_cog
, ideal_diff
, ideal_dir
;
1035 v3_copy( state
->up_dir
, ideal_dir
);
1036 v3_normalize( ideal_dir
);
1038 float grab
= axis_state( k_sraxis_grab
);
1039 v3_muladds( localplayer
.rb
.co
, ideal_dir
, 1.0f
-grab
, ideal_cog
);
1040 v3_sub( ideal_cog
, state
->cog
, ideal_diff
);
1042 /* Apply velocities */
1044 v3_sub( localplayer
.rb
.v
, state
->cog_v
, rv
);
1047 v3_muls( ideal_diff
, -k_cog_spring
* k_rb_rate
, F
);
1048 v3_muladds( F
, rv
, -k_cog_damp
* k_rb_rate
, F
);
1050 float ra
= k_cog_mass_ratio
,
1051 rb
= 1.0f
-k_cog_mass_ratio
;
1053 /* Apply forces & intergrate */
1054 v3_muladds( state
->cog_v
, F
, -rb
, state
->cog_v
);
1055 v3_muladds( state
->cog_v
, localplayer
.basis
[1], -9.8f
* k_rb_delta
,
1058 v3_muladds( state
->cog
, state
->cog_v
, k_rb_delta
, state
->cog
);
1061 static void skate_integrate(void){
1062 struct player_skate_state
*state
= &player_skate
.state
;
1064 float rate_x
= 1.0f
- (k_rb_delta
* 3.0f
),
1068 if( state
->activity
>= k_skate_activity_grind_any
){
1069 rate_x
= 1.0f
-(16.0f
*k_rb_delta
);
1070 rate_y
= 1.0f
-(10.0f
*k_rb_delta
);
1071 rate_z
= 1.0f
-(40.0f
*k_rb_delta
);
1074 float wx
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[0] ) * rate_x
,
1075 wy
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1] ) * rate_y
,
1076 wz
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[2] ) * rate_z
;
1078 v3_muls( localplayer
.rb
.to_world
[0], wx
, localplayer
.rb
.w
);
1079 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1], wy
,
1081 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[2], wz
,
1084 state
->flip_time
+= state
->flip_rate
* k_rb_delta
;
1085 rb_update_transform( &localplayer
.rb
);
1088 static enum trick_type
player_skate_trick_input(void){
1089 return (button_press( k_srbind_trick0
) ) |
1090 (button_press( k_srbind_trick1
) << 1) |
1091 (button_press( k_srbind_trick2
) << 1) |
1092 (button_press( k_srbind_trick2
) );
1095 static void player__skate_pre_update(void){
1096 struct player_skate_state
*state
= &player_skate
.state
;
1098 if( button_down( k_srbind_use
) ){
1099 localplayer
.subsystem
= k_player_subsystem_walk
;
1102 v3_copy( localplayer
.cam
.angles
, localplayer
.angles
);
1103 localplayer
.angles
[2] = 0.0f
;
1106 m4x3_mulv( localplayer
.rb
.to_world
, (v3f
){0.0f
,1.0f
,0.0f
}, newpos
);
1107 v3_add( newpos
, (v3f
){0.0f
,-1.0f
,0.0f
}, newpos
);
1108 v3_sub( localplayer
.rb
.co
, newpos
, offset
);
1109 v3_copy( newpos
, localplayer
.rb
.co
);
1111 player__begin_holdout( offset
);
1112 player__skate_kill_audio();
1113 player__walk_transition();
1117 if( state
->activity
<= k_skate_activity_air_to_grind
){
1118 enum trick_type trick
= k_trick_type_none
;
1119 if( (trick
= player_skate_trick_input()) ){
1120 if( (vg
.time
- state
->jump_time
) < 0.1f
){
1121 v3_zero( state
->trick_vel
);
1122 state
->trick_time
= 0.0f
;
1124 if( trick
== k_trick_type_kickflip
){
1125 state
->trick_vel
[0] = 3.0f
;
1127 else if( trick
== k_trick_type_shuvit
){
1128 state
->trick_vel
[2] = 3.0f
;
1130 else if( trick
== k_trick_type_treflip
){
1131 state
->trick_vel
[0] = 2.0f
;
1132 state
->trick_vel
[2] = 2.0f
;
1134 state
->trick_type
= trick
;
1139 state
->trick_type
= k_trick_type_none
;
1142 static void player__skate_post_update(void){
1143 struct player_skate_state
*state
= &player_skate
.state
;
1145 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
1146 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
1148 if( jump
->log_length
== 0 ){
1149 vg_fatal_error( "assert: jump->log_length == 0\n" );
1152 for( int j
=0; j
<jump
->log_length
- 1; j
++ ){
1153 float brightness
= jump
->score
*jump
->score
*jump
->score
;
1155 v3_lerp( jump
->log
[j
], jump
->log
[j
+1], brightness
, p1
);
1156 vg_line( jump
->log
[j
], p1
, jump
->colour
);
1159 vg_line_cross( jump
->log
[jump
->log_length
-1], jump
->colour
, 0.25f
);
1162 v3_add( jump
->log
[jump
->log_length
-1], jump
->n
, p1
);
1163 vg_line( jump
->log
[jump
->log_length
-1], p1
, 0xffffffff );
1165 vg_line_point( jump
->apex
, 0.02f
, 0xffffffff );
1170 float air
= state
->activity
<= k_skate_activity_air_to_grind
? 1.0f
: 0.0f
,
1171 speed
= v3_length( localplayer
.rb
.v
),
1172 attn
= vg_minf( 1.0f
, speed
*0.1f
),
1173 slide
= vg_clampf( fabsf(state
->slip
), 0.0f
, 1.0f
);
1175 if( state
->activity
>= k_skate_activity_grind_any
){
1179 f32 gate
= skaterift
.time_rate
,
1180 vol_main
= sqrtf( (1.0f
-air
)*attn
*(1.0f
-slide
) * 0.4f
) * gate
,
1181 vol_air
= sqrtf( air
*attn
* 0.5f
) * gate
,
1182 vol_slide
= sqrtf( (1.0f
-air
)*attn
*slide
* 0.25f
) * gate
;
1184 const u32 flags
= AUDIO_FLAG_SPACIAL_3D
|AUDIO_FLAG_LOOP
;
1186 if( !player_skate
.aud_air
){
1187 player_skate
.aud_air
= audio_get_first_idle_channel();
1188 if( player_skate
.aud_air
)
1189 audio_channel_init( player_skate
.aud_air
, &audio_board
[1], flags
);
1192 if( !player_skate
.aud_slide
){
1193 player_skate
.aud_slide
= audio_get_first_idle_channel();
1194 if( player_skate
.aud_slide
)
1195 audio_channel_init( player_skate
.aud_slide
, &audio_board
[2], flags
);
1199 /* brrrrrrrrrrrt sound for tiles and stuff
1200 * --------------------------------------------------------*/
1201 float sidechain_amt
= 0.0f
,
1202 hz
= vg_maxf( speed
* 2.0f
, 2.0f
);
1204 if( (player_skate
.surface
== k_surface_prop_tiles
) &&
1205 (state
->activity
< k_skate_activity_grind_any
) )
1206 sidechain_amt
= 1.0f
;
1208 sidechain_amt
= 0.0f
;
1210 audio_set_lfo_frequency( 0, hz
);
1211 audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar
,
1212 vg_lerpf( 250.0f
, 80.0f
, attn
) );
1214 if( player_skate
.sample_change_cooldown
> 0.0f
){
1215 player_skate
.sample_change_cooldown
-= vg
.time_frame_delta
;
1218 int sample_type
= k_skate_sample_concrete
;
1220 if( state
->activity
== k_skate_activity_grind_5050
){
1221 if( player_skate
.surface
== k_surface_prop_metal
)
1222 sample_type
= k_skate_sample_metal_scrape_generic
;
1224 sample_type
= k_skate_sample_concrete_scrape_metal
;
1226 else if( (state
->activity
== k_skate_activity_grind_back50
) ||
1227 (state
->activity
== k_skate_activity_grind_front50
) )
1229 if( player_skate
.surface
== k_surface_prop_metal
){
1230 sample_type
= k_skate_sample_metal_scrape_generic
;
1233 float a
= v3_dot( localplayer
.rb
.to_world
[2],
1234 player_skate
.grind_dir
);
1235 if( fabsf(a
) > 0.70710678118654752f
)
1236 sample_type
= k_skate_sample_concrete_scrape_wood
;
1238 sample_type
= k_skate_sample_concrete_scrape_metal
;
1241 else if( state
->activity
== k_skate_activity_grind_boardslide
){
1242 if( player_skate
.surface
== k_surface_prop_metal
)
1243 sample_type
= k_skate_sample_metal_scrape_generic
;
1245 sample_type
= k_skate_sample_concrete_scrape_wood
;
1248 audio_clip
*relevant_samples
[] = {
1256 if( (player_skate
.main_sample_type
!= sample_type
) ||
1257 (!player_skate
.aud_main
) ){
1259 player_skate
.aud_main
=
1260 audio_channel_crossfade( player_skate
.aud_main
,
1261 relevant_samples
[sample_type
],
1263 player_skate
.sample_change_cooldown
= 0.1f
;
1264 player_skate
.main_sample_type
= sample_type
;
1268 if( player_skate
.aud_main
){
1269 player_skate
.aud_main
->colour
= 0x00103efe;
1270 audio_channel_set_spacial( player_skate
.aud_main
,
1271 localplayer
.rb
.co
, 40.0f
);
1272 //audio_channel_slope_volume( player_skate.aud_main, 0.05f, vol_main );
1273 audio_channel_edit_volume( player_skate
.aud_main
, vol_main
, 1 );
1274 audio_channel_sidechain_lfo( player_skate
.aud_main
, 0, sidechain_amt
);
1276 float rate
= 1.0f
+ (attn
-0.5f
)*0.2f
;
1277 audio_channel_set_sampling_rate( player_skate
.aud_main
, rate
);
1280 if( player_skate
.aud_slide
){
1281 player_skate
.aud_slide
->colour
= 0x00103efe;
1282 audio_channel_set_spacial( player_skate
.aud_slide
,
1283 localplayer
.rb
.co
, 40.0f
);
1284 //audio_channel_slope_volume( player_skate.aud_slide, 0.05f, vol_slide );
1285 audio_channel_edit_volume( player_skate
.aud_slide
, vol_slide
, 1 );
1286 audio_channel_sidechain_lfo( player_skate
.aud_slide
, 0, sidechain_amt
);
1289 if( player_skate
.aud_air
){
1290 player_skate
.aud_air
->colour
= 0x00103efe;
1291 audio_channel_set_spacial( player_skate
.aud_air
,
1292 localplayer
.rb
.co
, 40.0f
);
1293 //audio_channel_slope_volume( player_skate.aud_air, 0.05f, vol_air );
1294 audio_channel_edit_volume( player_skate
.aud_air
, vol_air
, 1 );
1301 * truck alignment model at ra(local)
1302 * returns 1 if valid surface:
1303 * surface_normal will be filled out with an averaged normal vector
1304 * axel_dir will be the direction from left to right wheels
1306 * returns 0 if no good surface found
1309 int skate_compute_surface_alignment( v3f ra
, u32 colour
,
1310 v3f surface_normal
, v3f axel_dir
){
1311 world_instance
*world
= world_current_instance();
1313 v3f truck
, left
, right
;
1314 m4x3_mulv( localplayer
.rb
.to_world
, ra
, truck
);
1316 v3_muladds( truck
, localplayer
.rb
.to_world
[0], -k_board_width
, left
);
1317 v3_muladds( truck
, localplayer
.rb
.to_world
[0], k_board_width
, right
);
1318 vg_line( left
, right
, colour
);
1320 float k_max_truck_flex
= VG_PIf
* 0.25f
;
1322 ray_hit ray_l
, ray_r
;
1325 v3_muls( localplayer
.rb
.to_world
[1], -1.0f
, dir
);
1327 int res_l
= 0, res_r
= 0;
1329 for( int i
=0; i
<8; i
++ ){
1330 float t
= 1.0f
- (float)i
* (1.0f
/8.0f
);
1331 v3_muladds( truck
, localplayer
.rb
.to_world
[0], -k_board_radius
*t
, left
);
1332 v3_muladds( left
, localplayer
.rb
.to_world
[1], k_board_radius
, left
);
1333 ray_l
.dist
= 2.1f
* k_board_radius
;
1335 res_l
= ray_world( world
, left
, dir
, &ray_l
, k_material_flag_walking
);
1341 for( int i
=0; i
<8; i
++ ){
1342 float t
= 1.0f
- (float)i
* (1.0f
/8.0f
);
1343 v3_muladds( truck
, localplayer
.rb
.to_world
[0], k_board_radius
*t
, right
);
1344 v3_muladds( right
, localplayer
.rb
.to_world
[1], k_board_radius
, right
);
1345 ray_r
.dist
= 2.1f
* k_board_radius
;
1347 res_r
= ray_world( world
, right
, dir
, &ray_r
, k_material_flag_walking
);
1355 v3f tangent_average
;
1356 v3_muladds( truck
, localplayer
.rb
.to_world
[1], -k_board_radius
, midpoint
);
1357 v3_zero( tangent_average
);
1359 if( res_l
|| res_r
){
1361 v3_copy( midpoint
, p0
);
1362 v3_copy( midpoint
, p1
);
1365 v3_copy( ray_l
.pos
, p0
);
1366 v3_cross( ray_l
.normal
, localplayer
.rb
.to_world
[0], t
);
1367 v3_add( t
, tangent_average
, tangent_average
);
1370 v3_copy( ray_r
.pos
, p1
);
1371 v3_cross( ray_r
.normal
, localplayer
.rb
.to_world
[0], t
);
1372 v3_add( t
, tangent_average
, tangent_average
);
1375 v3_sub( p1
, p0
, v0
);
1379 /* fallback: use the closes point to the trucks */
1381 int idx
= bh_closest_point( world
->geo_bh
, midpoint
, closest
, 0.1f
);
1384 u32
*tri
= &world
->scene_geo
.arrindices
[ idx
* 3 ];
1387 for( int j
=0; j
<3; j
++ )
1388 v3_copy( world
->scene_geo
.arrvertices
[ tri
[j
] ].co
, verts
[j
] );
1390 v3f vert0
, vert1
, n
;
1391 v3_sub( verts
[1], verts
[0], vert0
);
1392 v3_sub( verts
[2], verts
[0], vert1
);
1393 v3_cross( vert0
, vert1
, n
);
1396 if( v3_dot( n
, localplayer
.rb
.to_world
[1] ) < 0.3f
)
1399 v3_cross( n
, localplayer
.rb
.to_world
[2], v0
);
1400 v3_muladds( v0
, localplayer
.rb
.to_world
[2],
1401 -v3_dot( localplayer
.rb
.to_world
[2], v0
), v0
);
1405 v3_cross( n
, localplayer
.rb
.to_world
[0], t
);
1406 v3_add( t
, tangent_average
, tangent_average
);
1412 v3_muladds( truck
, v0
, k_board_width
, right
);
1413 v3_muladds( truck
, v0
, -k_board_width
, left
);
1415 vg_line( left
, right
, VG__WHITE
);
1417 v3_normalize( tangent_average
);
1418 v3_cross( v0
, tangent_average
, surface_normal
);
1419 v3_copy( v0
, axel_dir
);
1424 static void skate_weight_distribute(void){
1425 struct player_skate_state
*state
= &player_skate
.state
;
1426 v3_zero( player_skate
.weight_distribution
);
1428 int reverse_dir
= v3_dot( localplayer
.rb
.to_world
[2],
1429 localplayer
.rb
.v
) < 0.0f
?1:-1;
1432 joystick_state( k_srjoystick_steer
, steer
);
1434 if( state
->manual_direction
== 0 ){
1435 if( (steer
[1] > 0.7f
) && (state
->activity
== k_skate_activity_ground
) &&
1436 (state
->jump_charge
<= 0.01f
) )
1437 state
->manual_direction
= reverse_dir
;
1440 if( steer
[1] < 0.1f
){
1441 state
->manual_direction
= 0;
1444 if( reverse_dir
!= state
->manual_direction
){
1450 if( state
->manual_direction
){
1451 float amt
= vg_minf( steer
[1] * 8.0f
, 1.0f
);
1452 player_skate
.weight_distribution
[2] = k_board_length
* amt
*
1453 (float)state
->manual_direction
;
1456 if( state
->manual_direction
){
1459 m3x3_mulv( localplayer
.rb
.to_world
, player_skate
.weight_distribution
,
1461 v3_negate( plane_z
, plane_z
);
1463 v3_muladds( plane_z
, player_skate
.surface_picture
,
1464 -v3_dot( plane_z
, player_skate
.surface_picture
), plane_z
);
1465 v3_normalize( plane_z
);
1467 v3_muladds( plane_z
, player_skate
.surface_picture
, 0.3f
, plane_z
);
1468 v3_normalize( plane_z
);
1471 v3_muladds( localplayer
.rb
.co
, plane_z
, 1.5f
, p1
);
1472 vg_line( localplayer
.rb
.co
, p1
, VG__GREEN
);
1475 v3_muls( localplayer
.rb
.to_world
[2], -(float)state
->manual_direction
,
1478 rb_effect_spring_target_vector( &localplayer
.rb
, refdir
, plane_z
,
1479 k_manul_spring
, k_manul_dampener
,
1480 player_skate
.substep_delta
);
1484 static void skate_adjust_up_direction(void){
1485 struct player_skate_state
*state
= &player_skate
.state
;
1487 if( state
->activity
== k_skate_activity_ground
){
1489 v3_copy( player_skate
.surface_picture
, target
);
1491 target
[1] += 2.0f
* player_skate
.surface_picture
[1];
1492 v3_normalize( target
);
1494 v3_lerp( state
->up_dir
, target
,
1495 8.0f
* player_skate
.substep_delta
, state
->up_dir
);
1497 else if( state
->activity
<= k_skate_activity_air_to_grind
){
1498 v3_lerp( state
->up_dir
, localplayer
.rb
.to_world
[1],
1499 8.0f
* player_skate
.substep_delta
, state
->up_dir
);
1503 v3_add( localplayer
.rb
.to_world
[1], localplayer
.basis
[1], avg
);
1504 v3_normalize( avg
);
1506 v3_lerp( state
->up_dir
, avg
,
1507 6.0f
* player_skate
.substep_delta
, state
->up_dir
);
1511 static int skate_point_visible( v3f origin
, v3f target
){
1513 v3_sub( target
, origin
, dir
);
1516 ray
.dist
= v3_length( dir
);
1517 v3_muls( dir
, 1.0f
/ray
.dist
, dir
);
1520 if( ray_world( world_current_instance(), origin
, dir
, &ray
,
1521 k_material_flag_walking
) )
1527 static void skate_grind_orient( struct grind_info
*inf
, m3x3f mtx
){
1528 v3_copy( inf
->dir
, mtx
[0] );
1529 v3_copy( inf
->n
, mtx
[1] );
1530 v3_cross( mtx
[0], mtx
[1], mtx
[2] );
1533 static void skate_grind_friction( struct grind_info
*inf
, float strength
){
1535 v3_muladds( localplayer
.rb
.to_world
[2], inf
->n
,
1536 -v3_dot( localplayer
.rb
.to_world
[2], inf
->n
), v2
);
1538 float a
= 1.0f
-fabsf( v3_dot( v2
, inf
->dir
) ),
1539 dir
= vg_signf( v3_dot( localplayer
.rb
.v
, inf
->dir
) ),
1540 F
= a
* -dir
* k_grind_max_friction
;
1542 v3_muladds( localplayer
.rb
.v
, inf
->dir
, F
*k_rb_delta
*strength
,
1546 static void skate_grind_decay( struct grind_info
*inf
, float strength
){
1548 skate_grind_orient( inf
, mtx
);
1549 m3x3_transpose( mtx
, mtx_inv
);
1552 m3x3_mulv( mtx_inv
, localplayer
.rb
.v
, v_grind
);
1554 float decay
= 1.0f
- ( k_rb_delta
* k_grind_decayxy
* strength
);
1555 v3_mul( v_grind
, (v3f
){ 1.0f
, decay
, decay
}, v_grind
);
1556 m3x3_mulv( mtx
, v_grind
, localplayer
.rb
.v
);
1559 static void skate_grind_truck_apply( float sign
, struct grind_info
*inf
,
1561 struct player_skate_state
*state
= &player_skate
.state
;
1564 v3f ra
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1566 m3x3_mulv( localplayer
.rb
.to_world
, ra
, raw
);
1567 v3_add( localplayer
.rb
.co
, raw
, wsp
);
1569 v3_copy( ra
, player_skate
.weight_distribution
);
1572 v3_sub( inf
->co
, wsp
, delta
);
1575 v3_muladds( localplayer
.rb
.v
, delta
, k_spring_force
*strength
*k_rb_delta
,
1578 skate_grind_decay( inf
, strength
);
1579 skate_grind_friction( inf
, strength
);
1581 /* yeah yeah yeah yeah */
1582 v3f raw_nplane
, axis
;
1583 v3_muladds( raw
, inf
->n
, -v3_dot( inf
->n
, raw
), raw_nplane
);
1584 v3_cross( raw_nplane
, inf
->n
, axis
);
1585 v3_normalize( axis
);
1589 skate_grind_orient( inf
, mtx
);
1590 v3f target_fwd
, fwd
, up
, target_up
;
1591 m3x3_mulv( mtx
, player_skate
.grind_vec
, target_fwd
);
1592 v3_copy( raw_nplane
, fwd
);
1593 v3_copy( localplayer
.rb
.to_world
[1], up
);
1594 v3_copy( inf
->n
, target_up
);
1596 v3_muladds( target_fwd
, inf
->n
, -v3_dot(inf
->n
,target_fwd
), target_fwd
);
1597 v3_muladds( fwd
, inf
->n
, -v3_dot(inf
->n
,fwd
), fwd
);
1599 v3_normalize( target_fwd
);
1600 v3_normalize( fwd
);
1603 joystick_state( k_srjoystick_steer
, steer
);
1605 float way
= steer
[1] * vg_signf( v3_dot( raw_nplane
, localplayer
.rb
.v
) );
1608 q_axis_angle( q
, axis
, VG_PIf
*0.125f
* way
);
1609 q_mulv( q
, target_up
, target_up
);
1610 q_mulv( q
, target_fwd
, target_fwd
);
1612 rb_effect_spring_target_vector( &localplayer
.rb
, up
, target_up
,
1617 rb_effect_spring_target_vector( &localplayer
.rb
, fwd
, target_fwd
,
1618 k_grind_spring
*strength
,
1619 k_grind_dampener
*strength
,
1622 vg_line_arrow( localplayer
.rb
.co
, target_up
, 1.0f
, VG__GREEN
);
1623 vg_line_arrow( localplayer
.rb
.co
, fwd
, 0.8f
, VG__RED
);
1624 vg_line_arrow( localplayer
.rb
.co
, target_fwd
, 1.0f
, VG__YELOW
);
1626 player_skate
.grind_strength
= strength
;
1629 struct grind_limit
*limit
=
1630 &player_skate
.limits
[ player_skate
.limit_count
++ ];
1631 m4x3_mulv( localplayer
.rb
.to_local
, wsp
, limit
->ra
);
1632 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, limit
->n
);
1635 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1638 static void skate_5050_apply( struct grind_info
*inf_front
,
1639 struct grind_info
*inf_back
){
1640 struct player_skate_state
*state
= &player_skate
.state
;
1641 struct grind_info inf_avg
;
1643 v3_sub( inf_front
->co
, inf_back
->co
, inf_avg
.dir
);
1644 v3_muladds( inf_back
->co
, inf_avg
.dir
, 0.5f
, inf_avg
.co
);
1645 v3_normalize( inf_avg
.dir
);
1648 v3_muls( inf_avg
.dir
, vg_signf(v3_dot(inf_avg
.dir
,localplayer
.rb
.v
)),
1651 v3f axis_front
, axis_back
, axis
;
1652 v3_cross( inf_front
->dir
, inf_front
->n
, axis_front
);
1653 v3_cross( inf_back
->dir
, inf_back
->n
, axis_back
);
1654 v3_add( axis_front
, axis_back
, axis
);
1655 v3_normalize( axis
);
1657 v3_cross( axis
, inf_avg
.dir
, inf_avg
.n
);
1658 skate_grind_decay( &inf_avg
, 1.0f
);
1661 joystick_state( k_srjoystick_steer
, steer
);
1663 float way
= steer
[1] * vg_signf( v3_dot( localplayer
.rb
.to_world
[2],
1664 localplayer
.rb
.v
) );
1667 v3_copy( localplayer
.rb
.to_world
[1], up
);
1668 v3_copy( inf_avg
.n
, target_up
);
1669 q_axis_angle( q
, localplayer
.rb
.to_world
[0], VG_PIf
*0.25f
* -way
);
1670 q_mulv( q
, target_up
, target_up
);
1672 v3_zero( player_skate
.weight_distribution
);
1673 player_skate
.weight_distribution
[2] = k_board_length
* -way
;
1675 rb_effect_spring_target_vector( &localplayer
.rb
, up
, target_up
,
1679 vg_line_arrow( localplayer
.rb
.co
, up
, 1.0f
, VG__GREEN
);
1680 vg_line_arrow( localplayer
.rb
.co
, target_up
, 1.0f
, VG__GREEN
);
1682 v3f fwd_nplane
, dir_nplane
;
1683 v3_muladds( localplayer
.rb
.to_world
[2], inf_avg
.n
,
1684 -v3_dot( localplayer
.rb
.to_world
[2], inf_avg
.n
), fwd_nplane
);
1687 v3_muls( inf_avg
.dir
, v3_dot( fwd_nplane
, inf_avg
.dir
), dir
);
1688 v3_muladds( dir
, inf_avg
.n
, -v3_dot( dir
, inf_avg
.n
), dir_nplane
);
1690 v3_normalize( fwd_nplane
);
1691 v3_normalize( dir_nplane
);
1693 rb_effect_spring_target_vector( &localplayer
.rb
, fwd_nplane
, dir_nplane
,
1697 vg_line_arrow( localplayer
.rb
.co
, fwd_nplane
, 0.8f
, VG__RED
);
1698 vg_line_arrow( localplayer
.rb
.co
, dir_nplane
, 0.8f
, VG__RED
);
1700 v3f pos_front
= { 0.0f
, -k_board_radius
, -1.0f
* k_board_length
},
1701 pos_back
= { 0.0f
, -k_board_radius
, 1.0f
* k_board_length
},
1702 delta_front
, delta_back
, delta_total
;
1704 m4x3_mulv( localplayer
.rb
.to_world
, pos_front
, pos_front
);
1705 m4x3_mulv( localplayer
.rb
.to_world
, pos_back
, pos_back
);
1707 v3_sub( inf_front
->co
, pos_front
, delta_front
);
1708 v3_sub( inf_back
->co
, pos_back
, delta_back
);
1709 v3_add( delta_front
, delta_back
, delta_total
);
1711 v3_muladds( localplayer
.rb
.v
, delta_total
, 50.0f
* k_rb_delta
,
1715 struct grind_limit
*limit
=
1716 &player_skate
.limits
[ player_skate
.limit_count
++ ];
1717 v3_zero( limit
->ra
);
1718 m3x3_mulv( localplayer
.rb
.to_local
, inf_avg
.n
, limit
->n
);
1721 v3_copy( inf_avg
.dir
, player_skate
.grind_dir
);
1724 static int skate_grind_truck_renew( f32 sign
, struct grind_info
*inf
){
1725 struct player_skate_state
*state
= &player_skate
.state
;
1727 v3f wheel_co
= { 0.0f
, 0.0f
, sign
* k_board_length
},
1728 grind_co
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1730 m4x3_mulv( localplayer
.rb
.to_world
, wheel_co
, wheel_co
);
1731 m4x3_mulv( localplayer
.rb
.to_world
, grind_co
, grind_co
);
1733 /* Exit condition: lost grind tracking */
1734 if( !skate_grind_scansq( grind_co
, localplayer
.rb
.v
, 0.3f
, inf
) )
1737 /* Exit condition: cant see grind target directly */
1738 if( !skate_point_visible( wheel_co
, inf
->co
) )
1741 /* Exit condition: minimum velocity not reached, but allow a bit of error */
1742 float dv
= fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)),
1743 minv
= k_grind_axel_min_vel
*0.8f
;
1748 if( fabsf(v3_dot( inf
->dir
, player_skate
.grind_dir
)) < k_grind_max_edge_angle
)
1751 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1755 static int skate_grind_truck_entry( f32 sign
, struct grind_info
*inf
){
1756 struct player_skate_state
*state
= &player_skate
.state
;
1759 v3f ra
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1762 m3x3_mulv( localplayer
.rb
.to_world
, ra
, raw
);
1763 v3_add( localplayer
.rb
.co
, raw
, wsp
);
1765 if( skate_grind_scansq( wsp
, localplayer
.rb
.v
, 0.3, inf
) ){
1766 if( fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)) < k_grind_axel_min_vel
)
1769 /* velocity should be at least 60% aligned */
1771 v3_cross( inf
->n
, inf
->dir
, axis
);
1772 v3_muladds( localplayer
.rb
.v
, inf
->n
,
1773 -v3_dot( localplayer
.rb
.v
, inf
->n
), pv
);
1775 if( v3_length2( pv
) < 0.0001f
)
1779 if( fabsf(v3_dot( pv
, inf
->dir
)) < k_grind_axel_max_angle
)
1782 if( v3_dot( localplayer
.rb
.v
, inf
->n
) > 0.5f
)
1785 v3f local_co
, local_dir
, local_n
;
1786 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1787 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1788 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, local_n
);
1790 v2f delta
= { local_co
[0], local_co
[2] - k_board_length
*sign
};
1792 float truck_height
= -(k_board_radius
+0.03f
);
1795 v3_cross( localplayer
.rb
.w
, raw
, rv
);
1796 v3_add( localplayer
.rb
.v
, rv
, rv
);
1798 if( (local_co
[1] >= truck_height
) &&
1799 (v2_length2( delta
) <= k_board_radius
*k_board_radius
) )
1808 static void skate_boardslide_apply( struct grind_info
*inf
){
1809 struct player_skate_state
*state
= &player_skate
.state
;
1811 v3f local_co
, local_dir
, local_n
;
1812 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1813 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1814 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, local_n
);
1817 v3_muladds( local_co
, local_dir
, local_co
[0]/-local_dir
[0],
1819 v3_copy( intersection
, player_skate
.weight_distribution
);
1821 skate_grind_decay( inf
, 0.0125f
);
1822 skate_grind_friction( inf
, 0.25f
);
1824 /* direction alignment */
1826 v3_cross( local_dir
, local_n
, perp
);
1827 v3_muls( local_dir
, vg_signf(local_dir
[0]), dir
);
1828 v3_muls( perp
, vg_signf(perp
[2]), perp
);
1830 m3x3_mulv( localplayer
.rb
.to_world
, dir
, dir
);
1831 m3x3_mulv( localplayer
.rb
.to_world
, perp
, perp
);
1834 q_axis_angle( qbalance
, dir
, local_co
[0]*k_grind_balance
);
1835 q_mulv( qbalance
, perp
, perp
);
1837 rb_effect_spring_target_vector( &localplayer
.rb
, localplayer
.rb
.to_world
[0],
1839 k_grind_spring
, k_grind_dampener
,
1842 rb_effect_spring_target_vector( &localplayer
.rb
, localplayer
.rb
.to_world
[2],
1844 k_grind_spring
, k_grind_dampener
,
1847 vg_line_arrow( localplayer
.rb
.co
, dir
, 0.5f
, VG__GREEN
);
1848 vg_line_arrow( localplayer
.rb
.co
, perp
, 0.5f
, VG__BLUE
);
1850 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1853 static int skate_boardslide_entry( struct grind_info
*inf
){
1854 struct player_skate_state
*state
= &player_skate
.state
;
1856 if( skate_grind_scansq( localplayer
.rb
.co
,
1857 localplayer
.rb
.to_world
[0], k_board_length
,
1860 v3f local_co
, local_dir
;
1861 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1862 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1864 if( (fabsf(local_co
[2]) <= k_board_length
) && /* within wood area */
1865 (local_co
[1] >= 0.0f
) && /* at deck level */
1866 (fabsf(local_dir
[0]) >= 0.25f
) ) /* perpendicular to us */
1868 if( fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)) < k_grind_axel_min_vel
)
1878 static int skate_boardslide_renew( struct grind_info
*inf
){
1879 struct player_skate_state
*state
= &player_skate
.state
;
1881 if( !skate_grind_scansq( localplayer
.rb
.co
,
1882 localplayer
.rb
.to_world
[0], k_board_length
,
1886 /* Exit condition: cant see grind target directly */
1888 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.to_world
[1], 0.2f
, vis
);
1889 if( !skate_point_visible( vis
, inf
->co
) )
1892 /* Exit condition: minimum velocity not reached, but allow a bit of error */
1893 float dv
= fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)),
1894 minv
= k_grind_axel_min_vel
*0.8f
;
1899 if( fabsf(v3_dot( inf
->dir
, player_skate
.grind_dir
)) < k_grind_max_edge_angle
)
1905 static void skate_store_grind_vec( struct grind_info
*inf
){
1906 struct player_skate_state
*state
= &player_skate
.state
;
1909 skate_grind_orient( inf
, mtx
);
1910 m3x3_transpose( mtx
, mtx
);
1913 v3_sub( inf
->co
, localplayer
.rb
.co
, raw
);
1915 m3x3_mulv( mtx
, raw
, player_skate
.grind_vec
);
1916 v3_normalize( player_skate
.grind_vec
);
1917 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1920 static enum skate_activity
skate_availible_grind(void){
1921 struct player_skate_state
*state
= &player_skate
.state
;
1923 if( state
->grind_cooldown
> 100 ){
1924 vg_fatal_error( "wth!\n" );
1927 /* debounces this state manager a little bit */
1928 if( state
->grind_cooldown
){
1929 state
->grind_cooldown
--;
1930 return k_skate_activity_undefined
;
1933 struct grind_info inf_back50
,
1945 joystick_state( k_srjoystick_steer
, steer
);
1947 if( state
->activity
== k_skate_activity_grind_5050
||
1948 state
->activity
== k_skate_activity_grind_back50
||
1949 state
->activity
== k_skate_activity_grind_front50
)
1951 float tilt
= steer
[1];
1953 if( fabsf(tilt
) >= 0.25f
){
1954 v3f raw
= {0.0f
,0.0f
,tilt
};
1955 m3x3_mulv( localplayer
.rb
.to_world
, raw
, raw
);
1957 float way
= tilt
* vg_signf( v3_dot( raw
, localplayer
.rb
.v
) );
1959 if( way
< 0.0f
) allow_front
= 0;
1960 else allow_back
= 0;
1964 if( state
->activity
== k_skate_activity_grind_boardslide
){
1965 res_slide
= skate_boardslide_renew( &inf_slide
);
1967 else if( state
->activity
== k_skate_activity_grind_back50
){
1968 res_back50
= skate_grind_truck_renew( 1.0f
, &inf_back50
);
1971 res_front50
= skate_grind_truck_entry( -1.0f
, &inf_front50
);
1973 else if( state
->activity
== k_skate_activity_grind_front50
){
1974 res_front50
= skate_grind_truck_renew( -1.0f
, &inf_front50
);
1977 res_back50
= skate_grind_truck_entry( 1.0f
, &inf_back50
);
1979 else if( state
->activity
== k_skate_activity_grind_5050
){
1981 res_front50
= skate_grind_truck_renew( -1.0f
, &inf_front50
);
1983 res_back50
= skate_grind_truck_renew( 1.0f
, &inf_back50
);
1986 res_slide
= skate_boardslide_entry( &inf_slide
);
1989 res_back50
= skate_grind_truck_entry( 1.0f
, &inf_back50
);
1992 res_front50
= skate_grind_truck_entry( -1.0f
, &inf_front50
);
1994 if( res_back50
!= res_front50
){
1995 int wants_to_do_that
= fabsf(steer
[1]) >= 0.25f
;
1997 res_back50
&= wants_to_do_that
;
1998 res_front50
&= wants_to_do_that
;
2002 const enum skate_activity table
[] =
2003 { /* slide | back | front */
2004 k_skate_activity_undefined
, /* 0 0 0 */
2005 k_skate_activity_grind_front50
, /* 0 0 1 */
2006 k_skate_activity_grind_back50
, /* 0 1 0 */
2007 k_skate_activity_grind_5050
, /* 0 1 1 */
2009 /* slide has priority always */
2010 k_skate_activity_grind_boardslide
, /* 1 0 0 */
2011 k_skate_activity_grind_boardslide
, /* 1 0 1 */
2012 k_skate_activity_grind_boardslide
, /* 1 1 0 */
2013 k_skate_activity_grind_boardslide
, /* 1 1 1 */
2015 , new_activity
= table
[ res_slide
<< 2 | res_back50
<< 1 | res_front50
];
2017 if( new_activity
== k_skate_activity_undefined
){
2018 if( state
->activity
>= k_skate_activity_grind_any
){
2019 state
->grind_cooldown
= 15;
2020 state
->surface_cooldown
= 10;
2023 else if( new_activity
== k_skate_activity_grind_boardslide
){
2024 skate_boardslide_apply( &inf_slide
);
2026 else if( new_activity
== k_skate_activity_grind_back50
){
2027 if( state
->activity
!= k_skate_activity_grind_back50
)
2028 skate_store_grind_vec( &inf_back50
);
2030 skate_grind_truck_apply( 1.0f
, &inf_back50
, 1.0f
);
2032 else if( new_activity
== k_skate_activity_grind_front50
){
2033 if( state
->activity
!= k_skate_activity_grind_front50
)
2034 skate_store_grind_vec( &inf_front50
);
2036 skate_grind_truck_apply( -1.0f
, &inf_front50
, 1.0f
);
2038 else if( new_activity
== k_skate_activity_grind_5050
)
2039 skate_5050_apply( &inf_front50
, &inf_back50
);
2041 return new_activity
;
2044 static void player__skate_update(void){
2045 struct player_skate_state
*state
= &player_skate
.state
;
2046 world_instance
*world
= world_current_instance();
2048 if( world
->water
.enabled
){
2049 if( localplayer
.rb
.co
[1]+0.25f
< world
->water
.height
){
2051 player__networked_sfx( k_player_subsystem_walk
, 32,
2052 k_player_walk_soundeffect_splash
,
2053 localplayer
.rb
.co
, 1.0f
);
2055 player__skate_kill_audio();
2056 player__dead_transition();
2061 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
2062 state
->activity_prev
= state
->activity
;
2064 v3_zero( normal_total
);
2066 struct board_collider
2073 enum board_collider_state
2075 k_collider_state_default
,
2076 k_collider_state_disabled
,
2077 k_collider_state_colliding
2084 { 0.0f
, 0.0f
, -k_board_length
},
2085 .radius
= k_board_radius
,
2089 { 0.0f
, 0.0f
, k_board_length
},
2090 .radius
= k_board_radius
,
2097 if( state
->activity
<= k_skate_activity_air_to_grind
){
2098 float min_dist
= 0.6f
;
2099 for( int i
=0; i
<2; i
++ ){
2101 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, wpos
);
2103 if( bh_closest_point( world
->geo_bh
, wpos
, closest
, min_dist
) != -1 ){
2104 min_dist
= vg_minf( min_dist
, v3_dist( closest
, wpos
) );
2108 float vy
= v3_dot( localplayer
.basis
[1], localplayer
.rb
.v
);
2109 vy
= vg_maxf( 0.0f
, vy
);
2111 slap
= vg_clampf( (min_dist
/0.5f
) + vy
, 0.0f
, 1.0f
)*0.3f
;
2113 state
->slap
= vg_lerpf( state
->slap
, slap
, 10.0f
*k_rb_delta
);
2115 wheels
[0].pos
[1] = state
->slap
;
2116 wheels
[1].pos
[1] = state
->slap
;
2119 const int k_wheel_count
= 2;
2121 player_skate
.substep
= k_rb_delta
;
2122 player_skate
.substep_delta
= player_skate
.substep
;
2123 player_skate
.limit_count
= 0;
2125 int substep_count
= 0;
2127 v3_zero( player_skate
.surface_picture
);
2129 int prev_contacts
[2];
2131 for( int i
=0; i
<k_wheel_count
; i
++ ){
2132 wheels
[i
].state
= k_collider_state_default
;
2133 prev_contacts
[i
] = player_skate
.wheel_contacts
[i
];
2136 /* check if we can enter or continue grind */
2137 enum skate_activity grindable_activity
= skate_availible_grind();
2138 if( grindable_activity
!= k_skate_activity_undefined
){
2139 state
->activity
= grindable_activity
;
2143 int contact_count
= 0;
2144 for( int i
=0; i
<2; i
++ ){
2146 v3_copy( localplayer
.rb
.to_world
[0], axel
);
2148 if( skate_compute_surface_alignment( wheels
[i
].pos
,
2149 wheels
[i
].colour
, normal
, axel
) )
2151 rb_effect_spring_target_vector( &localplayer
.rb
,
2152 localplayer
.rb
.to_world
[0],
2154 k_surface_spring
, k_surface_dampener
,
2155 player_skate
.substep_delta
);
2157 v3_add( normal
, player_skate
.surface_picture
,
2158 player_skate
.surface_picture
);
2160 player_skate
.wheel_contacts
[i
] = 1;
2163 player_skate
.wheel_contacts
[i
] = 0;
2166 m3x3_mulv( localplayer
.rb
.to_local
, axel
, player_skate
.truckv0
[i
] );
2169 if( state
->surface_cooldown
){
2170 state
->surface_cooldown
--;
2174 if( (prev_contacts
[0]+prev_contacts
[1] == 1) && (contact_count
== 2) ){
2175 for( int i
=0; i
<2; i
++ ){
2176 if( !prev_contacts
[i
] ){
2178 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, co
);
2179 player__networked_sfx( k_player_subsystem_skate
, 32,
2180 k_player_skate_soundeffect_tap
,
2181 localplayer
.rb
.co
, 0.75f
);
2186 if( contact_count
){
2187 state
->activity
= k_skate_activity_ground
;
2188 state
->gravity_bias
= k_gravity
;
2189 v3_normalize( player_skate
.surface_picture
);
2191 skate_apply_friction_model();
2192 skate_weight_distribute();
2195 if( state
->activity
> k_skate_activity_air_to_grind
)
2196 state
->activity
= k_skate_activity_air
;
2198 v3_zero( player_skate
.weight_distribution
);
2199 skate_apply_air_model();
2204 if( state
->activity
== k_skate_activity_grind_back50
)
2205 wheels
[1].state
= k_collider_state_disabled
;
2206 if( state
->activity
== k_skate_activity_grind_front50
)
2207 wheels
[0].state
= k_collider_state_disabled
;
2208 if( state
->activity
== k_skate_activity_grind_5050
){
2209 wheels
[0].state
= k_collider_state_disabled
;
2210 wheels
[1].state
= k_collider_state_disabled
;
2213 /* all activities */
2214 skate_apply_steering_model();
2215 skate_adjust_up_direction();
2216 skate_apply_cog_model();
2217 skate_apply_jump_model();
2218 skate_apply_grab_model();
2219 skate_apply_trick_model();
2220 skate_apply_pump_model();
2225 * Phase 0: Continous collision detection
2226 * --------------------------------------------------------------------------
2229 v3f head_wp0
, head_wp1
, start_co
;
2230 m4x3_mulv( localplayer
.rb
.to_world
, state
->head_position
, head_wp0
);
2231 v3_copy( localplayer
.rb
.co
, start_co
);
2233 /* calculate transform one step into future */
2236 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.v
, player_skate
.substep
,
2239 if( v3_length2( localplayer
.rb
.w
) > 0.0f
){
2242 v3_copy( localplayer
.rb
.w
, axis
);
2244 float mag
= v3_length( axis
);
2245 v3_divs( axis
, mag
, axis
);
2246 q_axis_angle( rotation
, axis
, mag
*player_skate
.substep
);
2247 q_mul( rotation
, localplayer
.rb
.q
, future_q
);
2248 q_normalize( future_q
);
2251 v4_copy( localplayer
.rb
.q
, future_q
);
2253 v3f future_cg
, current_cg
, cg_offset
;
2254 q_mulv( localplayer
.rb
.q
, player_skate
.weight_distribution
, current_cg
);
2255 q_mulv( future_q
, player_skate
.weight_distribution
, future_cg
);
2256 v3_sub( future_cg
, current_cg
, cg_offset
);
2258 /* calculate the minimum time we can move */
2259 float max_time
= player_skate
.substep
;
2261 for( int i
=0; i
<k_wheel_count
; i
++ ){
2262 if( wheels
[i
].state
== k_collider_state_disabled
)
2265 v3f current
, future
, r_cg
;
2267 q_mulv( future_q
, wheels
[i
].pos
, future
);
2268 v3_add( future
, future_co
, future
);
2269 v3_add( cg_offset
, future
, future
);
2271 q_mulv( localplayer
.rb
.q
, wheels
[i
].pos
, current
);
2272 v3_add( current
, localplayer
.rb
.co
, current
);
2277 float cast_radius
= wheels
[i
].radius
- k_penetration_slop
* 2.0f
;
2278 if( spherecast_world( world
, current
, future
, cast_radius
, &t
, n
,
2279 k_material_flag_walking
) != -1)
2280 max_time
= vg_minf( max_time
, t
* player_skate
.substep
);
2283 /* clamp to a fraction of delta, to prevent locking */
2284 float rate_lock
= substep_count
;
2285 rate_lock
*= k_rb_delta
* 0.1f
;
2286 rate_lock
*= rate_lock
;
2288 max_time
= vg_maxf( max_time
, rate_lock
);
2289 player_skate
.substep_delta
= max_time
;
2292 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.v
,
2293 player_skate
.substep_delta
, localplayer
.rb
.co
);
2294 if( v3_length2( localplayer
.rb
.w
) > 0.0f
){
2297 v3_copy( localplayer
.rb
.w
, axis
);
2299 float mag
= v3_length( axis
);
2300 v3_divs( axis
, mag
, axis
);
2301 q_axis_angle( rotation
, axis
, mag
*player_skate
.substep_delta
);
2302 q_mul( rotation
, localplayer
.rb
.q
, localplayer
.rb
.q
);
2303 q_normalize( localplayer
.rb
.q
);
2305 q_mulv( localplayer
.rb
.q
, player_skate
.weight_distribution
, future_cg
);
2306 v3_sub( current_cg
, future_cg
, cg_offset
);
2307 v3_add( localplayer
.rb
.co
, cg_offset
, localplayer
.rb
.co
);
2310 rb_update_transform( &localplayer
.rb
);
2311 v3_muladds( localplayer
.rb
.v
, localplayer
.basis
[1],
2312 -state
->gravity_bias
* player_skate
.substep_delta
,
2315 player_skate
.substep
-= player_skate
.substep_delta
;
2317 rb_ct manifold
[128];
2318 int manifold_len
= 0;
2320 * Phase -1: head detection
2321 * --------------------------------------------------------------------------
2323 m4x3_mulv( localplayer
.rb
.to_world
, state
->head_position
, head_wp1
);
2327 if( (v3_dist2( head_wp0
, head_wp1
) > 0.001f
) &&
2328 (spherecast_world( world
, head_wp0
, head_wp1
, 0.2f
, &t
, n
,
2329 k_material_flag_walking
) != -1) )
2331 v3_lerp( start_co
, localplayer
.rb
.co
, t
, localplayer
.rb
.co
);
2332 rb_update_transform( &localplayer
.rb
);
2334 player__skate_kill_audio();
2335 player__dead_transition();
2340 * Phase 1: Regular collision detection
2341 * --------------------------------------------------------------------------
2344 for( int i
=0; i
<k_wheel_count
; i
++ ){
2345 if( wheels
[i
].state
== k_collider_state_disabled
)
2349 m3x3_identity( mtx
);
2350 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, mtx
[3] );
2352 rb_sphere collider
= { .radius
= wheels
[i
].radius
};
2354 rb_ct
*man
= &manifold
[ manifold_len
];
2356 int l
= skate_collide_smooth( mtx
, &collider
, man
);
2358 wheels
[i
].state
= k_collider_state_colliding
;
2363 float grind_radius
= k_board_radius
* 0.75f
;
2364 rb_capsule capsule
= { .height
= (k_board_length
+0.2f
)*2.0f
,
2365 .radius
=grind_radius
};
2367 v3_muls( localplayer
.rb
.to_world
[0], 1.0f
, mtx
[0] );
2368 v3_muls( localplayer
.rb
.to_world
[2], -1.0f
, mtx
[1] );
2369 v3_muls( localplayer
.rb
.to_world
[1], 1.0f
, mtx
[2] );
2370 v3_muladds( localplayer
.rb
.to_world
[3], localplayer
.rb
.to_world
[1],
2371 grind_radius
+ k_board_radius
*0.25f
+state
->slap
, mtx
[3] );
2373 rb_ct
*cman
= &manifold
[manifold_len
];
2375 int l
= rb_capsule__scene( mtx
, &capsule
, NULL
, &world
->rb_geo
.inf
.scene
,
2376 cman
, k_material_flag_walking
);
2379 for( int i
=0; i
<l
; i
++ )
2380 cman
[l
].type
= k_contact_type_edge
;
2381 rb_manifold_filter_joint_edges( cman
, l
, 0.03f
);
2382 l
= rb_manifold_apply_filtered( cman
, l
);
2387 vg_line_capsule( mtx
, capsule
.radius
, capsule
.height
, VG__WHITE
);
2390 if( state
->activity
>= k_skate_activity_grind_any
){
2391 for( int i
=0; i
<player_skate
.limit_count
; i
++ ){
2392 struct grind_limit
*limit
= &player_skate
.limits
[i
];
2393 rb_ct
*ct
= &manifold
[ manifold_len
++ ];
2394 m4x3_mulv( localplayer
.rb
.to_world
, limit
->ra
, ct
->co
);
2395 m3x3_mulv( localplayer
.rb
.to_world
, limit
->n
, ct
->n
);
2397 ct
->type
= k_contact_type_default
;
2403 * --------------------------------------------------------------------------
2408 m4x3_mulv( localplayer
.rb
.to_world
,
2409 player_skate
.weight_distribution
, world_cog
);
2410 vg_line_point( world_cog
, 0.02f
, VG__BLACK
);
2412 for( int i
=0; i
<manifold_len
; i
++ ){
2413 rb_prepare_contact( &manifold
[i
], player_skate
.substep_delta
);
2414 rb_debug_contact( &manifold
[i
] );
2417 /* yes, we are currently rebuilding mass matrices every frame. too bad! */
2418 v3f extent
= { k_board_width
, 0.1f
, k_board_length
};
2419 float ex2
= k_board_interia
*extent
[0]*extent
[0],
2420 ey2
= k_board_interia
*extent
[1]*extent
[1],
2421 ez2
= k_board_interia
*extent
[2]*extent
[2];
2423 float mass
= 2.0f
* (extent
[0]*extent
[1]*extent
[2]);
2424 float inv_mass
= 1.0f
/mass
;
2427 I
[0] = ((1.0f
/12.0f
) * mass
* (ey2
+ez2
));
2428 I
[1] = ((1.0f
/12.0f
) * mass
* (ex2
+ez2
));
2429 I
[2] = ((1.0f
/12.0f
) * mass
* (ex2
+ey2
));
2432 m3x3_identity( iI
);
2439 m3x3_mul( iI
, localplayer
.rb
.to_local
, iIw
);
2440 m3x3_mul( localplayer
.rb
.to_world
, iIw
, iIw
);
2442 for( int j
=0; j
<10; j
++ ){
2443 for( int i
=0; i
<manifold_len
; i
++ ){
2445 * regular dance; calculate velocity & total mass, apply impulse.
2448 struct contact
*ct
= &manifold
[i
];
2451 v3_sub( ct
->co
, world_cog
, delta
);
2452 v3_cross( localplayer
.rb
.w
, delta
, rv
);
2453 v3_add( localplayer
.rb
.v
, rv
, rv
);
2456 v3_cross( delta
, ct
->n
, raCn
);
2459 m3x3_mulv( iIw
, raCn
, raCnI
);
2461 float normal_mass
= 1.0f
/ (inv_mass
+ v3_dot(raCn
,raCnI
)),
2462 vn
= v3_dot( rv
, ct
->n
),
2463 lambda
= normal_mass
* ( -vn
);
2465 float temp
= ct
->norm_impulse
;
2466 ct
->norm_impulse
= vg_maxf( temp
+ lambda
, 0.0f
);
2467 lambda
= ct
->norm_impulse
- temp
;
2470 v3_muls( ct
->n
, lambda
, impulse
);
2472 v3_muladds( normal_total
, impulse
, inv_mass
, normal_total
);
2473 v3_muladds( localplayer
.rb
.v
, impulse
, inv_mass
, localplayer
.rb
.v
);
2474 v3_cross( delta
, impulse
, impulse
);
2475 m3x3_mulv( iIw
, impulse
, impulse
);
2476 v3_add( impulse
, localplayer
.rb
.w
, localplayer
.rb
.w
);
2478 v3_cross( localplayer
.rb
.w
, delta
, rv
);
2479 v3_add( localplayer
.rb
.v
, rv
, rv
);
2480 vn
= v3_dot( rv
, ct
->n
);
2485 rb_depenetrate( manifold
, manifold_len
, dt
);
2486 v3_add( dt
, localplayer
.rb
.co
, localplayer
.rb
.co
);
2487 rb_update_transform( &localplayer
.rb
);
2491 if( player_skate
.substep
>= 0.0001f
)
2492 goto begin_collision
; /* again! */
2495 * End of collision and dynamics routine
2496 * --------------------------------------------------------------------------
2499 f32 nforce
= v3_length(normal_total
);
2500 if( nforce
> 4.0f
){
2501 if( nforce
> 17.6f
){
2502 v3_muladds( localplayer
.rb
.v
, normal_total
, -1.0f
, localplayer
.rb
.v
);
2503 player__dead_transition();
2504 player__skate_kill_audio();
2508 f32 amt
= k_cam_punch
;
2509 if( localplayer
.cam_control
.camera_mode
== k_cam_firstperson
){
2513 v3_muladds( localplayer
.cam_land_punch_v
, normal_total
, amt
,
2514 localplayer
.cam_land_punch_v
);
2517 player_skate
.surface
= k_surface_prop_concrete
;
2519 for( int i
=0; i
<manifold_len
; i
++ ){
2520 rb_ct
*ct
= &manifold
[i
];
2521 struct world_surface
*surf
= world_contact_surface( world
, ct
);
2523 if( surf
->info
.surface_prop
> player_skate
.surface
)
2524 player_skate
.surface
= surf
->info
.surface_prop
;
2527 for( int i
=0; i
<k_wheel_count
; i
++ ){
2529 m3x3_copy( localplayer
.rb
.to_world
, mtx
);
2530 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, mtx
[3] );
2531 vg_line_sphere( mtx
, wheels
[i
].radius
,
2532 (u32
[]){ VG__WHITE
, VG__BLACK
,
2533 wheels
[i
].colour
}[ wheels
[i
].state
]);
2537 vg_line_point( state
->cog
, 0.02f
, VG__WHITE
);
2539 u32 id
= world_intersect_gates( world
, localplayer
.rb
.co
, state
->prev_pos
);
2542 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, mdl_entity_id_id(id
) );
2544 m4x3_mulv( gate
->transport
, localplayer
.rb
.co
, localplayer
.rb
.co
);
2545 m3x3_mulv( gate
->transport
, localplayer
.rb
.v
, localplayer
.rb
.v
);
2546 m4x3_mulv( gate
->transport
, state
->cog
, state
->cog
);
2547 m3x3_mulv( gate
->transport
, state
->cog_v
, state
->cog_v
);
2548 m3x3_mulv( gate
->transport
, state
->throw_v
, state
->throw_v
);
2549 m3x3_mulv( gate
->transport
, state
->head_position
,
2550 state
->head_position
);
2551 m3x3_mulv( gate
->transport
, state
->up_dir
, state
->up_dir
);
2553 v4f transport_rotation
;
2554 m3x3_q( gate
->transport
, transport_rotation
);
2555 q_mul( transport_rotation
, localplayer
.rb
.q
, localplayer
.rb
.q
);
2556 q_mul( transport_rotation
, state
->smoothed_rotation
,
2557 state
->smoothed_rotation
);
2558 rb_update_transform( &localplayer
.rb
);
2559 player__pass_gate( id
);
2562 /* FIXME: Rate limit */
2563 static int stick_frames
= 0;
2565 if( state
->activity
>= k_skate_activity_ground
)
2570 if( stick_frames
> 5 ) stick_frames
= 5;
2572 if( stick_frames
== 4 ){
2573 if( state
->activity
== k_skate_activity_ground
){
2574 if( (fabsf(state
->slip
) > 0.75f
) ){
2575 player__networked_sfx( k_player_subsystem_skate
, 128,
2576 k_player_skate_soundeffect_land_bad
,
2577 localplayer
.rb
.co
, 0.6f
);
2580 player__networked_sfx( k_player_subsystem_skate
, 128,
2581 k_player_skate_soundeffect_land_good
,
2582 localplayer
.rb
.co
, 1.0f
);
2585 else if( player_skate
.surface
== k_surface_prop_metal
){
2586 player__networked_sfx( k_player_subsystem_skate
, 128,
2587 k_player_skate_soundeffect_grind_metal
,
2588 localplayer
.rb
.co
, 1.0f
);
2591 player__networked_sfx( k_player_subsystem_skate
, 128,
2592 k_player_skate_soundeffect_grind_wood
,
2593 localplayer
.rb
.co
, 1.0f
);
2595 } else if( stick_frames
== 0 ){
2596 /* TODO: EXIT SOUNDS */
2600 static void player__skate_im_gui(void){
2601 struct player_skate_state
*state
= &player_skate
.state
;
2602 player__debugtext( 1, "V: %5.2f %5.2f %5.2f",localplayer
.rb
.v
[0],
2603 localplayer
.rb
.v
[1],
2604 localplayer
.rb
.v
[2] );
2605 player__debugtext( 1, "CO: %5.2f %5.2f %5.2f",localplayer
.rb
.co
[0],
2606 localplayer
.rb
.co
[1],
2607 localplayer
.rb
.co
[2] );
2608 player__debugtext( 1, "W: %5.2f %5.2f %5.2f",localplayer
.rb
.w
[0],
2609 localplayer
.rb
.w
[1],
2610 localplayer
.rb
.w
[2] );
2612 const char *activity_txt
[] = {
2616 "undefined (INVALID)",
2617 "grind_any (INVALID)",
2619 "grind_metallic (INVALID)",
2625 player__debugtext( 1, "activity: %s", activity_txt
[state
->activity
] );
2627 player__debugtext( 1, "steer_s: %5.2f %5.2f [%.2f %.2f]",
2628 state
->steerx_s
, state
->steery_s
,
2629 k_steer_ground
, k_steer_air
);
2631 player__debugtext( 1, "flip: %.4f %.4f", state
->flip_rate
,
2633 player__debugtext( 1, "trickv: %.2f %.2f %.2f",
2634 state
->trick_vel
[0],
2635 state
->trick_vel
[1],
2636 state
->trick_vel
[2] );
2637 player__debugtext( 1, "tricke: %.2f %.2f %.2f",
2638 state
->trick_euler
[0],
2639 state
->trick_euler
[1],
2640 state
->trick_euler
[2] );
2643 static void player__skate_animate(void){
2644 struct player_skate_state
*state
= &player_skate
.state
;
2645 struct player_skate_animator
*animator
= &player_skate
.animator
;
2648 float kheight
= 2.0f
,
2651 v3_zero( animator
->offset
);
2653 v3f cog_local
, cog_ideal
;
2654 m4x3_mulv( localplayer
.rb
.to_local
, state
->cog
, cog_local
);
2656 v3_copy( state
->up_dir
, cog_ideal
);
2657 v3_normalize( cog_ideal
);
2658 m3x3_mulv( localplayer
.rb
.to_local
, cog_ideal
, cog_ideal
);
2660 v3_sub( cog_ideal
, cog_local
, animator
->offset
);
2662 v3_muls( animator
->offset
, 4.0f
, animator
->offset
);
2663 animator
->offset
[1] *= -1.0f
;
2665 float curspeed
= v3_length( localplayer
.rb
.v
),
2666 kickspeed
= vg_clampf( curspeed
*(1.0f
/40.0f
), 0.0f
, 1.0f
),
2667 kicks
= (vg_randf64()-0.5f
)*2.0f
*kickspeed
,
2668 sign
= vg_signf( kicks
);
2670 animator
->wobble
[0] = vg_lerpf( animator
->wobble
[0], kicks
*kicks
*sign
,
2671 6.0f
*vg
.time_delta
);
2672 animator
->wobble
[1] = vg_lerpf( animator
->wobble
[1], animator
->wobble
[0],
2673 2.4f
*vg
.time_delta
);
2675 animator
->offset
[0] *= 0.26f
;
2676 animator
->offset
[0] += animator
->wobble
[1]*3.0f
;
2678 animator
->offset
[1] *= -0.3f
;
2679 animator
->offset
[2] *= 0.01f
;
2681 animator
->offset
[0]=vg_clampf(animator
->offset
[0],-0.8f
,0.8f
)*
2682 (1.0f
-fabsf(animator
->slide
)*0.9f
);
2683 animator
->offset
[1]=vg_clampf(animator
->offset
[1],-0.5f
,0.0f
);
2686 v3_mul( animator
->offset
, (v3f
){1.0f
,0.3f
,1.0f
}, cam_offset
);
2687 v3_copy( cam_offset
, localplayer
.cam_control
.tpv_offset_extra
);
2689 /* localized vectors */
2690 m4x3_mulv( localplayer
.rb
.to_local
, state
->cog
, animator
->local_cog
);
2693 * Animation blending
2694 * ===========================================
2699 float desired
= 0.0f
;
2700 if( state
->activity
== k_skate_activity_ground
)
2701 desired
= vg_clampf( fabsf( state
->slip
), 0.0f
, 1.0f
);
2703 animator
->slide
= vg_lerpf( animator
->slide
, desired
, 2.4f
*vg
.time_delta
);
2706 /* movement information */
2707 int iair
= state
->activity
<= k_skate_activity_air_to_grind
;
2709 float dirz
= state
->reverse
> 0.0f
? 0.0f
: 1.0f
,
2710 dirx
= state
->slip
< 0.0f
? 0.0f
: 1.0f
,
2711 fly
= iair
? 1.0f
: 0.0f
,
2712 wdist
= player_skate
.weight_distribution
[2] / k_board_length
;
2714 if( state
->activity
>= k_skate_activity_grind_any
)
2717 animator
->z
= vg_lerpf( animator
->z
, dirz
, 2.4f
*vg
.time_delta
);
2718 animator
->x
= vg_lerpf( animator
->x
, dirx
, 0.6f
*vg
.time_delta
);
2719 animator
->fly
= vg_lerpf( animator
->fly
, fly
, 3.4f
*vg
.time_delta
);
2720 animator
->weight
= vg_lerpf( animator
->weight
, wdist
, 9.0f
*vg
.time_delta
);
2722 float stand
= 1.0f
- vg_clampf( curspeed
* 0.03f
, 0.0f
, 1.0f
);
2723 animator
->stand
= vg_lerpf( animator
->stand
, stand
, 6.0f
*vg
.time_delta
);
2724 animator
->reverse
= state
->reverse
;
2726 if( fabsf(state
->slip
) > 0.3f
){
2727 f32 slide_x
= v3_dot(localplayer
.rb
.v
, localplayer
.rb
.to_world
[0]);
2728 state
->delayed_slip_dir
= vg_signf(slide_x
);
2732 f32 grind
=state
->activity
>= k_skate_activity_grind_any
? 1.0f
: 0.0f
;
2733 animator
->grind
= vg_lerpf( animator
->grind
, grind
, 5.0f
*vg
.time_delta
);
2735 f32 grind_frame
= 0.5f
;
2737 if( state
->activity
== k_skate_activity_grind_front50
)
2739 else if( state
->activity
== k_skate_activity_grind_back50
)
2742 animator
->grind_balance
= vg_lerpf( animator
->grind_balance
, grind_frame
,
2743 5.0f
*vg
.time_delta
);
2746 animator
->push_time
= vg
.time
- state
->start_push
;
2747 animator
->push
= vg_lerpf( animator
->push
,
2748 (vg
.time
- state
->cur_push
) < 0.125,
2749 6.0f
*vg
.time_delta
);
2752 animator
->jump_charge
= state
->jump_charge
;
2753 animator
->jump
= vg_lerpf( animator
->jump
, animator
->jump_charge
,
2754 8.4f
*vg
.time_delta
);
2757 animator
->jump_dir
= state
->jump_dir
;
2758 f32 jump_start_frame
= 14.0f
/30.0f
;
2759 animator
->jump_time
= animator
->jump_charge
* jump_start_frame
;
2760 f32 jump_frame
= (vg
.time
- state
->jump_time
) + jump_start_frame
;
2761 if( jump_frame
>= jump_start_frame
&& jump_frame
<= (40.0f
/30.0f
) )
2762 animator
->jump_time
= jump_frame
;
2765 float jump_t
= vg
.time
-state
->jump_time
;
2768 float extra
= h
*exp(1.0-h
) * (state
->jump_dir
?1.0f
:-1.0f
);
2769 extra
*= state
->slap
* 4.0f
;
2771 v3_add( state
->trick_euler
, state
->trick_residuald
,
2772 animator
->board_euler
);
2773 v3_muls( animator
->board_euler
, VG_TAUf
, animator
->board_euler
);
2775 animator
->board_euler
[0] *= 0.5f
;
2776 animator
->board_euler
[1] += extra
;
2777 animator
->trick_type
= state
->trick_type
;
2780 f32 lean1
, lean2
= animator
->steer
[0] * animator
->reverse
* -0.36f
,
2783 lean1
= animator
->slide
* animator
->delayed_slip_dir
;
2784 if( fabsf(lean1
)>fabsf(lean2
) ) lean
= lean1
;
2787 if( ((int)roundf(animator
->board_euler
[0]/VG_PIf
)) % 2 ) lean
= -lean
;
2788 lean
= vg_clampf( lean
, -1.0f
, 1.0f
);
2789 animator
->board_lean
=
2790 vg_lerpf(animator
->board_lean
, lean
, vg
.time_delta
*18.0f
);
2792 /* feet placement */
2793 struct player_board
*board
=
2794 addon_cache_item_if_loaded( k_addon_type_board
,
2795 localplayer
.board_view_slot
);
2797 if( animator
->weight
> 0.0f
){
2798 animator
->foot_offset
[0] =
2799 board
->truck_positions
[k_board_truck_back
][2]+0.3f
;
2802 animator
->foot_offset
[1] =
2803 board
->truck_positions
[k_board_truck_front
][2]-0.3f
;
2807 f32 slapm
= vg_maxf( 1.0f
-v3_length2( state
->trick_vel
), 0.0f
);
2808 animator
->slap
= state
->slap
;
2809 animator
->subslap
= vg_lerpf( animator
->subslap
, slapm
,
2810 vg
.time_delta
*10.0f
);
2812 f32 l
= ((state
->activity
< k_skate_activity_ground
) &&
2813 v3_length2(state
->trick_vel
) > 0.1f
)? 1: 0;
2814 animator
->trick_foot
= vg_lerpf( animator
->trick_foot
, l
,
2815 8.4f
*vg
.time_delta
);
2819 joystick_state( k_srjoystick_grab
, grab_input
);
2820 v2_add( state
->grab_mouse_delta
, grab_input
, grab_input
);
2822 if( v2_length2( grab_input
) <= 0.001f
) grab_input
[0] = -1.0f
;
2823 else v2_normalize_clamp( grab_input
);
2824 v2_lerp( animator
->grab
, grab_input
, 2.4f
*vg
.time_delta
, animator
->grab
);
2825 animator
->grabbing
= state
->grabbing
;
2828 joystick_state( k_srjoystick_steer
, animator
->steer
);
2830 animator
->airdir
= vg_lerpf( animator
->airdir
, -animator
->steer
[0],
2831 2.4f
*vg
.time_delta
);
2835 if( (state
->activity
<= k_skate_activity_air_to_grind
) &&
2836 (fabsf(state
->flip_rate
) > 0.01f
) ){
2837 float substep
= vg
.time_fixed_extrapolate
;
2838 float t
= state
->flip_time
+state
->flip_rate
*substep
*k_rb_delta
;
2839 sign
= vg_signf( t
);
2841 t
= 1.0f
- vg_minf( 1.0f
, fabsf( t
* 1.1f
) );
2842 t
= sign
* (1.0f
-t
*t
);
2844 f32 angle
= vg_clampf( t
, -1.0f
, 1.0f
) * VG_TAUf
,
2845 distm
= state
->land_dist
* fabsf(state
->flip_rate
) * 3.0f
,
2846 blend
= vg_clampf( 1.0f
-distm
, 0.0f
, 1.0f
);
2847 angle
= vg_lerpf( angle
, vg_signf(state
->flip_rate
)*VG_TAUf
, blend
);
2848 q_axis_angle( animator
->qflip
, state
->flip_axis
, angle
);
2851 q_identity( animator
->qflip
);
2853 /* counter-rotation */
2854 if( v3_length2( state
->up_dir
) > 0.001f
){
2855 v4_lerp( state
->smoothed_rotation
, localplayer
.rb
.q
,
2856 2.0f
*vg
.time_frame_delta
,
2857 state
->smoothed_rotation
);
2858 q_normalize( state
->smoothed_rotation
);
2860 v3f yaw_smooth
= {1.0f
,0.0f
,0.0f
};
2861 q_mulv( state
->smoothed_rotation
, yaw_smooth
, yaw_smooth
);
2862 m3x3_mulv( localplayer
.rb
.to_local
, yaw_smooth
, yaw_smooth
);
2863 yaw_smooth
[1] = 0.0f
;
2864 v3_normalize( yaw_smooth
);
2866 f32 yaw_counter_rotate
= yaw_smooth
[0];
2867 yaw_counter_rotate
= vg_maxf( 0.7f
, yaw_counter_rotate
);
2868 yaw_counter_rotate
= acosf( yaw_counter_rotate
);
2869 yaw_counter_rotate
*= 1.0f
-animator
->fly
;
2872 m3x3_mulv( localplayer
.rb
.to_local
, state
->up_dir
, ndir
);
2873 v3_normalize( ndir
);
2875 v3f up
= { 0.0f
, 1.0f
, 0.0f
};
2876 float a
= v3_dot( ndir
, up
);
2877 a
= acosf( vg_clampf( a
, -1.0f
, 1.0f
) );
2880 v4f qcounteryaw
, qfixup
;
2882 v3_cross( up
, ndir
, axis
);
2883 q_axis_angle( qfixup
, axis
, a
*2.0f
);
2885 v3_cross( (v3f
){1.0f
,0.0f
,0.0f
}, yaw_smooth
, axis
);
2886 q_axis_angle( qcounteryaw
, axis
, yaw_counter_rotate
);
2888 q_mul( qcounteryaw
, qfixup
, animator
->qfixuptotal
);
2889 q_normalize( animator
->qfixuptotal
);
2892 m3x3_mulv( localplayer
.rb
.to_world
, up
, p1
);
2893 m3x3_mulv( localplayer
.rb
.to_world
, ndir
, p2
);
2895 vg_line_arrow( localplayer
.rb
.co
, p1
, 0.5f
, VG__PINK
);
2896 vg_line_arrow( localplayer
.rb
.co
, p2
, 0.5f
, VG__PINK
);
2898 else q_identity( animator
->qfixuptotal
);
2899 rb_extrapolate( &localplayer
.rb
, animator
->root_co
, animator
->root_q
);
2902 static void player__skate_pose( void *_animator
, player_pose
*pose
){
2903 struct player_avatar
*av
= localplayer
.playeravatar
;
2904 struct skeleton
*sk
= &av
->sk
;
2905 struct player_skate_animator
*animator
= _animator
;
2907 pose
->type
= k_player_pose_type_ik
;
2908 v3_copy( animator
->root_co
, pose
->root_co
);
2909 v4_copy( animator
->root_q
, pose
->root_q
);
2913 q_mulv( pose
->root_q
, (v3f
){0.0f
,1.0f
,0.0f
}, ext_up
);
2914 v3_copy( pose
->root_co
, ext_co
);
2915 v3_muladds( pose
->root_co
, ext_up
, -0.1f
, pose
->root_co
);
2917 /* apply flip rotation at midpoint */
2918 q_mul( animator
->qflip
, pose
->root_q
, pose
->root_q
);
2919 q_normalize( pose
->root_q
);
2921 v3f rotation_point
, rco
;
2922 v3_muladds( ext_co
, ext_up
, 0.5f
, rotation_point
);
2923 v3_sub( pose
->root_co
, rotation_point
, rco
);
2925 q_mulv( animator
->qflip
, rco
, rco
);
2926 v3_add( rco
, rotation_point
, pose
->root_co
);
2929 * ---------------------------------------------------------------------- */
2931 mdl_keyframe apose
[32], bpose
[32];
2932 mdl_keyframe ground_pose
[32];
2935 f32 dir_frame
= animator
->z
* (15.0f
/30.0f
),
2936 stand_blend
= animator
->offset
[1]*-2.0f
;
2938 pose
->board
.lean
= animator
->board_lean
;
2940 stand_blend
= vg_clampf( 1.0f
-animator
->local_cog
[1], 0, 1 );
2942 skeleton_sample_anim( sk
, player_skate
.anim_stand
, dir_frame
, apose
);
2943 skeleton_sample_anim( sk
, player_skate
.anim_highg
, dir_frame
, bpose
);
2944 skeleton_lerp_pose( sk
, apose
, bpose
, stand_blend
, apose
);
2947 skeleton_sample_anim( sk
, player_skate
.anim_slide
, animator
->x
* 0.5f
,
2949 skeleton_lerp_pose( sk
, apose
, bpose
, animator
->slide
, apose
);
2951 if( animator
->reverse
> 0.0f
){
2952 skeleton_sample_anim( sk
, player_skate
.anim_push
, animator
->push_time
,
2956 skeleton_sample_anim( sk
, player_skate
.anim_push_reverse
,
2957 animator
->push_time
, bpose
);
2959 skeleton_lerp_pose( sk
, apose
, bpose
, animator
->push
, apose
);
2961 struct skeleton_anim
*jump_anim
= animator
->jump_dir
?
2962 player_skate
.anim_ollie
:
2963 player_skate
.anim_ollie_reverse
;
2965 f32 setup_blend
= vg_minf( animator
->jump
, 1.0f
);
2966 skeleton_sample_anim_clamped( sk
, jump_anim
, animator
->jump_time
, bpose
);
2967 skeleton_lerp_pose( sk
, apose
, bpose
, setup_blend
, ground_pose
);
2970 mdl_keyframe air_pose
[32];
2972 float air_frame
= (animator
->airdir
*0.5f
+0.5f
) * (15.0f
/30.0f
);
2973 skeleton_sample_anim( sk
, player_skate
.anim_air
, air_frame
, apose
);
2975 float ang
= atan2f( animator
->grab
[0], animator
->grab
[1] ),
2976 ang_unit
= (ang
+VG_PIf
) * (1.0f
/VG_TAUf
),
2977 grab_frame
= ang_unit
* (15.0f
/30.0f
);
2979 skeleton_sample_anim( sk
, player_skate
.anim_grabs
, grab_frame
, bpose
);
2980 skeleton_lerp_pose( sk
, apose
, bpose
, animator
->grabbing
, air_pose
);
2983 skeleton_lerp_pose( sk
, ground_pose
, air_pose
, animator
->fly
,
2986 mdl_keyframe
*kf_board
= &pose
->keyframes
[av
->id_board
-1],
2987 *kf_foot_l
= &pose
->keyframes
[av
->id_ik_foot_l
-1],
2988 *kf_foot_r
= &pose
->keyframes
[av
->id_ik_foot_r
-1],
2989 *kf_knee_l
= &pose
->keyframes
[av
->id_ik_knee_l
-1],
2990 *kf_knee_r
= &pose
->keyframes
[av
->id_ik_knee_r
-1],
2991 *kf_hip
= &pose
->keyframes
[av
->id_hip
-1],
2992 *kf_wheels
[] = { &pose
->keyframes
[av
->id_wheel_r
-1],
2993 &pose
->keyframes
[av
->id_wheel_l
-1] };
2996 mdl_keyframe grind_pose
[32];
2998 f32 frame
= animator
->grind_balance
* 0.5f
;
3000 skeleton_sample_anim( sk
, player_skate
.anim_grind
, frame
, apose
);
3001 skeleton_sample_anim( sk
, player_skate
.anim_grind_jump
, frame
, bpose
);
3002 skeleton_lerp_pose( sk
, apose
, bpose
, animator
->jump
, grind_pose
);
3004 skeleton_lerp_pose( sk
, pose
->keyframes
, grind_pose
,
3005 animator
->grind
, pose
->keyframes
);
3006 float add_grab_mod
= 1.0f
- animator
->fly
;
3008 /* additive effects */
3009 u32 apply_to
[] = { av
->id_hip
,
3013 av
->id_ik_elbow_r
};
3015 float apply_rates
[] = { 1.0f
,
3021 for( int i
=0; i
<vg_list_size(apply_to
); i
++ ){
3022 pose
->keyframes
[apply_to
[i
]-1].co
[0] += animator
->offset
[0]*add_grab_mod
;
3023 pose
->keyframes
[apply_to
[i
]-1].co
[2] += animator
->offset
[2]*add_grab_mod
;
3026 /* angle 'correction' */
3028 v3_add( av
->sk
.bones
[av
->id_hip
].co
, kf_hip
->co
, origin
);
3030 for( int i
=0; i
<vg_list_size(apply_to
); i
++ ){
3031 mdl_keyframe
*kf
= &pose
->keyframes
[apply_to
[i
]-1];
3032 keyframe_rotate_around( kf
, origin
, av
->sk
.bones
[apply_to
[i
]].co
,
3033 animator
->qfixuptotal
);
3036 /* trick rotation */
3037 v4f qtrick
, qyaw
, qpitch
, qroll
;
3038 q_axis_angle( qyaw
, (v3f
){0.0f
,1.0f
,0.0f
}, animator
->board_euler
[0] );
3039 q_axis_angle( qpitch
, (v3f
){1.0f
,0.0f
,0.0f
}, animator
->board_euler
[1] );
3040 q_axis_angle( qroll
, (v3f
){0.0f
,0.0f
,1.0f
}, animator
->board_euler
[2] );
3042 q_mul( qyaw
, qroll
, qtrick
);
3043 q_mul( qpitch
, qtrick
, qtrick
);
3044 q_mul( kf_board
->q
, qtrick
, kf_board
->q
);
3045 q_normalize( kf_board
->q
);
3047 kf_foot_l
->co
[2] = vg_lerpf( kf_foot_l
->co
[2], animator
->foot_offset
[0],
3048 0.5f
* animator
->weight
);
3049 kf_foot_r
->co
[2] = vg_lerpf( kf_foot_r
->co
[2], animator
->foot_offset
[1],
3050 -0.5f
* animator
->weight
);
3052 kf_foot_l
->co
[1] += animator
->slap
;
3053 kf_foot_r
->co
[1] += animator
->slap
;
3054 kf_knee_l
->co
[1] += animator
->slap
;
3055 kf_knee_r
->co
[1] += animator
->slap
;
3056 kf_board
->co
[1] += animator
->slap
* animator
->subslap
;
3057 kf_hip
->co
[1] += animator
->slap
* 0.25f
;
3059 if( animator
->trick_type
== k_trick_type_kickflip
){
3060 kf_foot_l
->co
[0] += animator
->trick_foot
* 0.2f
;
3061 kf_foot_l
->co
[1] -= animator
->trick_foot
* 0.18f
;
3063 else if( animator
->trick_type
== k_trick_type_shuvit
){
3064 kf_foot_l
->co
[0] += animator
->trick_foot
* 0.1f
;
3065 kf_foot_r
->co
[0] -= animator
->trick_foot
* 0.15f
;
3066 kf_foot_l
->co
[1] -= animator
->trick_foot
* 0.18f
;
3067 kf_foot_r
->co
[1] -= animator
->trick_foot
* 0.18f
;
3069 else if( animator
->trick_type
== k_trick_type_treflip
){
3070 kf_foot_l
->co
[0] += animator
->trick_foot
* 0.2f
;
3071 kf_foot_r
->co
[0] -= animator
->trick_foot
* 0.15f
;
3072 kf_foot_l
->co
[1] -= animator
->trick_foot
* 0.18f
;
3073 kf_foot_r
->co
[1] -= animator
->trick_foot
* 0.18f
;
3077 * animation wishlist:
3078 * boardslide/grind jump animations
3079 * when tricking the slap should not appply or less apply
3080 * not animations however DONT target grinds that are vertically down.
3083 /* truck rotation */
3084 for( int i
=0; i
<2; i
++ ){
3085 float a
= vg_minf( player_skate
.truckv0
[i
][0], 1.0f
);
3086 a
= -acosf( a
) * vg_signf( player_skate
.truckv0
[i
][1] );
3089 q_axis_angle( q
, (v3f
){0.0f
,0.0f
,1.0f
}, a
);
3090 q_mul( q
, kf_wheels
[i
]->q
, kf_wheels
[i
]->q
);
3091 q_normalize( kf_wheels
[i
]->q
);
3097 *kf_head
= &pose
->keyframes
[av
->id_head
-1],
3098 *kf_elbow_l
= &pose
->keyframes
[av
->id_ik_elbow_l
-1],
3099 *kf_elbow_r
= &pose
->keyframes
[av
->id_ik_elbow_r
-1],
3100 *kf_hand_l
= &pose
->keyframes
[av
->id_ik_hand_l
-1],
3101 *kf_hand_r
= &pose
->keyframes
[av
->id_ik_hand_r
-1];
3103 float warble
= perlin1d( vg
.time
, 2.0f
, 2, 300 );
3104 warble
*= vg_maxf(animator
->grind
, fabsf(animator
->weight
)) * 0.3f
;
3107 q_axis_angle( qrot
, (v3f
){0.8f
,0.7f
,0.6f
}, warble
);
3109 v3f origin
= {0.0f
,0.2f
,0.0f
};
3110 keyframe_rotate_around( kf_hand_l
, origin
,
3111 av
->sk
.bones
[av
->id_ik_hand_l
].co
, qrot
);
3112 keyframe_rotate_around( kf_hand_r
, origin
,
3113 av
->sk
.bones
[av
->id_ik_hand_r
].co
, qrot
);
3114 keyframe_rotate_around( kf_hip
, origin
,
3115 av
->sk
.bones
[av
->id_hip
].co
, qrot
);
3116 keyframe_rotate_around( kf_elbow_r
, origin
,
3117 av
->sk
.bones
[av
->id_ik_elbow_r
].co
, qrot
);
3118 keyframe_rotate_around( kf_elbow_l
, origin
,
3119 av
->sk
.bones
[av
->id_ik_elbow_l
].co
, qrot
);
3121 q_inv( qrot
, qrot
);
3122 q_mul( qrot
, kf_head
->q
, kf_head
->q
);
3123 q_normalize( kf_head
->q
);
3128 static void player__skate_post_animate(void){
3129 struct player_avatar
*av
= localplayer
.playeravatar
;
3130 struct player_skate_state
*state
= &player_skate
.state
;
3132 localplayer
.cam_velocity_influence
= 1.0f
;
3134 v3f head
= { 0.0f
, 1.8f
, 0.0f
};
3135 m4x3_mulv( localplayer
.final_mtx
[ av
->id_head
],
3136 head
, state
->head_position
);
3137 m4x3_mulv( localplayer
.rb
.to_local
,
3138 state
->head_position
, state
->head_position
);
3141 static void player__skate_reset_animator(void){
3142 struct player_skate_state
*state
= &player_skate
.state
;
3144 memset( &player_skate
.animator
, 0, sizeof(player_skate
.animator
) );
3146 if( state
->activity
<= k_skate_activity_air_to_grind
)
3147 player_skate
.animator
.fly
= 1.0f
;
3149 player_skate
.animator
.fly
= 0.0f
;
3152 static void player__skate_clear_mechanics(void){
3153 struct player_skate_state
*state
= &player_skate
.state
;
3154 state
->jump_charge
= 0.0f
;
3155 state
->charging_jump
= 0;
3156 state
->jump_dir
= 0;
3157 v3_zero( state
->flip_axis
);
3158 state
->flip_time
= 0.0f
;
3159 state
->flip_rate
= 0.0f
;
3160 state
->reverse
= 0.0f
;
3162 state
->grabbing
= 0.0f
;
3163 v2_zero( state
->grab_mouse_delta
);
3165 state
->jump_time
= 0.0;
3166 state
->start_push
= 0.0;
3167 state
->cur_push
= 0.0;
3168 state
->air_start
= 0.0;
3170 v3_zero( state
->air_init_v
);
3171 v3_zero( state
->air_init_co
);
3173 state
->gravity_bias
= k_gravity
;
3174 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
3175 v4_copy( localplayer
.rb
.q
, state
->smoothed_rotation
);
3176 v3_zero( state
->throw_v
);
3177 v3_zero( state
->trick_vel
);
3178 v3_zero( state
->trick_euler
);
3179 v3_zero( state
->cog_v
);
3180 state
->grind_cooldown
= 0;
3181 state
->surface_cooldown
= 0;
3182 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.to_world
[1], 1.0f
, state
->cog
);
3183 v3_copy( localplayer
.rb
.to_world
[1], state
->up_dir
);
3184 v3_copy( localplayer
.rb
.to_world
[1], player_skate
.surface_picture
);
3185 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
3186 v3_zero( player_skate
.weight_distribution
);
3189 static void player__skate_reset( ent_spawn
*rp
){
3190 struct player_skate_state
*state
= &player_skate
.state
;
3191 v3_zero( localplayer
.rb
.v
);
3192 v4_copy( rp
->transform
.q
, localplayer
.rb
.q
);
3194 state
->activity
= k_skate_activity_air
;
3195 state
->activity_prev
= k_skate_activity_air
;
3197 player__skate_clear_mechanics();
3198 player__skate_reset_animator();
3200 v3_zero( state
->head_position
);
3201 state
->head_position
[1] = 1.8f
;
3204 #include "network_compression.h"
3206 static void player__skate_animator_exchange( bitpack_ctx
*ctx
, void *data
){
3207 struct player_skate_animator
*animator
= data
;
3209 bitpack_qv3f( ctx
, 24, -1024.0f
, 1024.0f
, animator
->root_co
);
3210 bitpack_qquat( ctx
, animator
->root_q
);
3212 bitpack_qv3f( ctx
, 8, -1.0f
, 1.0f
, animator
->offset
);
3213 bitpack_qv3f( ctx
, 8, -1.0f
, 1.0f
, animator
->local_cog
);
3214 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->slide
);
3215 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->z
);
3216 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->x
);
3218 /* these could likely be pressed down into single bits if needed */
3219 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->fly
);
3220 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grind
);
3221 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->stand
);
3222 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->push
);
3223 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->jump
); /*??*/
3224 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->jump_charge
); /*??*/
3226 /* just the sign bit? */
3227 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->reverse
);
3228 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->delayed_slip_dir
);
3229 bitpack_bytes( ctx
, 1, &animator
->jump_dir
);
3230 bitpack_bytes( ctx
, 1, &animator
->trick_type
);
3232 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grind_balance
);
3233 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->airdir
);
3234 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->weight
);
3235 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->trick_foot
);
3236 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->slap
);
3237 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->subslap
);
3238 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grabbing
);
3240 /* animator->wobble is ommited */
3242 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->foot_offset
);
3243 bitpack_qquat( ctx
, animator
->qfixuptotal
);
3244 bitpack_qquat( ctx
, animator
->qflip
);
3246 bitpack_qv3f( ctx
, 16, -100.0f
, 100.0f
, animator
->board_euler
);
3247 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->board_lean
);
3248 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->steer
);
3249 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->grab
);
3251 bitpack_qf32( ctx
, 16, 0.0f
, 120.0f
, &animator
->push_time
);
3252 bitpack_qf32( ctx
, 16, 0.0f
, 120.0f
, &animator
->jump_time
);
3255 static void player__skate_sfx_oneshot( u8 id
, v3f pos
, f32 volume
){
3258 if( id
== k_player_skate_soundeffect_jump
){
3259 audio_oneshot_3d( &audio_jumps
[vg_randu32()%2], pos
, 40.0f
, volume
);
3261 else if( id
== k_player_skate_soundeffect_tap
){
3262 audio_oneshot_3d( &audio_taps
[vg_randu32()%4], pos
, 40.0f
, volume
);
3264 else if( id
== k_player_skate_soundeffect_land_good
){
3265 audio_oneshot_3d( &audio_lands
[vg_randu32()%3], pos
, 40.0f
, volume
);
3267 else if( id
== k_player_skate_soundeffect_land_bad
){
3268 audio_oneshot_3d( &audio_lands
[vg_randu32()%2+3], pos
, 40.0f
, volume
);
3270 else if( id
== k_player_skate_soundeffect_grind_metal
){
3271 audio_oneshot_3d( &audio_board
[3], pos
, 40.0f
, volume
);
3273 else if( id
== k_player_skate_soundeffect_grind_wood
){
3274 audio_oneshot_3d( &audio_board
[8], pos
, 40.0f
, volume
);
3280 #endif /* PLAYER_SKATE_C */