6 #include "vg/vg_perlin.h"
8 #include "ent_skateshop.h"
11 static void player__skate_bind(void){
12 struct skeleton
*sk
= &localplayer
.skeleton
;
13 rb_update_transform( &localplayer
.rb
);
15 struct { struct skeleton_anim
**anim
; const char *name
; }
17 { &player_skate
.anim_grind
, "pose_grind" },
18 { &player_skate
.anim_grind_jump
, "pose_grind_jump" },
19 { &player_skate
.anim_stand
, "pose_stand" },
20 { &player_skate
.anim_highg
, "pose_highg" },
21 { &player_skate
.anim_air
, "pose_air" },
22 { &player_skate
.anim_slide
, "pose_slide" },
23 { &player_skate
.anim_push
, "push" },
24 { &player_skate
.anim_push_reverse
, "push_reverse" },
25 { &player_skate
.anim_ollie
, "ollie" },
26 { &player_skate
.anim_ollie_reverse
,"ollie_reverse" },
27 { &player_skate
.anim_grabs
, "grabs" }
30 for( u32 i
=0; i
<vg_list_size(bindings
); i
++ )
31 *bindings
[i
].anim
= skeleton_get_anim( sk
, bindings
[i
].name
);
34 static void player__skate_kill_audio(void){
36 if( player_skate
.aud_main
){
37 player_skate
.aud_main
=
38 audio_channel_fadeout( player_skate
.aud_main
, 0.1f
);
40 if( player_skate
.aud_air
){
41 player_skate
.aud_air
=
42 audio_channel_fadeout( player_skate
.aud_air
, 0.1f
);
44 if( player_skate
.aud_slide
){
45 player_skate
.aud_slide
=
46 audio_channel_fadeout( player_skate
.aud_slide
, 0.1f
);
52 * Collision detection routines
58 * Does collision detection on a sphere vs world, and applies some smoothing
59 * filters to the manifold afterwards
61 static int skate_collide_smooth( m4x3f mtx
, rb_sphere
*sphere
, rb_ct
*man
){
62 world_instance
*world
= world_current_instance();
65 len
= rb_sphere__scene( mtx
, sphere
, NULL
, &world
->rb_geo
.inf
.scene
, man
,
66 k_material_flag_walking
);
68 for( int i
=0; i
<len
; i
++ ){
69 man
[i
].rba
= &localplayer
.rb
;
73 rb_manifold_filter_coplanar( man
, len
, 0.03f
);
76 rb_manifold_filter_backface( man
, len
);
77 rb_manifold_filter_joint_edges( man
, len
, 0.03f
);
78 rb_manifold_filter_pairs( man
, len
, 0.03f
);
80 int new_len
= rb_manifold_apply_filtered( man
, len
);
94 static int skate_grind_scansq( v3f pos
, v3f dir
, float r
,
95 struct grind_info
*inf
){
96 world_instance
*world
= world_current_instance();
99 v3_copy( dir
, plane
);
100 v3_normalize( plane
);
101 plane
[3] = v3_dot( plane
, pos
);
104 v3_add( pos
, (v3f
){ r
, r
, r
}, box
[1] );
105 v3_sub( pos
, (v3f
){ r
, r
, r
}, box
[0] );
114 int sample_count
= 0;
120 v3_cross( plane
, localplayer
.basis
[1], support_axis
);
121 v3_normalize( support_axis
);
124 bh_iter_init_box( 0, &it
, box
);
127 while( bh_next( world
->geo_bh
, &it
, &idx
) ){
128 u32
*ptri
= &world
->scene_geo
.arrindices
[ idx
*3 ];
131 struct world_surface
*surf
= world_tri_index_surface(world
,ptri
[0]);
132 if( !(surf
->info
.flags
& k_material_flag_grindable
) )
135 for( int j
=0; j
<3; j
++ )
136 v3_copy( world
->scene_geo
.arrvertices
[ptri
[j
]].co
, tri
[j
] );
138 for( int j
=0; j
<3; j
++ ){
142 struct grind_sample
*sample
= &samples
[ sample_count
];
145 if( plane_segment( plane
, tri
[i0
], tri
[i1
], co
) ){
147 v3_sub( co
, pos
, d
);
148 if( v3_length2( d
) > r
*r
)
152 v3_sub( tri
[1], tri
[0], va
);
153 v3_sub( tri
[2], tri
[0], vb
);
154 v3_cross( va
, vb
, normal
);
156 sample
->normal
[0] = v3_dot( support_axis
, normal
);
157 sample
->normal
[1] = v3_dot( localplayer
.basis
[1], normal
);
158 sample
->co
[0] = v3_dot( support_axis
, d
);
159 sample
->co
[1] = v3_dot( localplayer
.basis
[1], d
);
161 v3_copy( normal
, sample
->normal3
); /* normalize later
162 if we want to us it */
164 v3_muls( tri
[0], 1.0f
/3.0f
, sample
->centroid
);
165 v3_muladds( sample
->centroid
, tri
[1], 1.0f
/3.0f
, sample
->centroid
);
166 v3_muladds( sample
->centroid
, tri
[2], 1.0f
/3.0f
, sample
->centroid
);
168 v2_normalize( sample
->normal
);
171 if( sample_count
== vg_list_size( samples
) )
172 goto too_many_samples
;
179 if( sample_count
< 2 )
182 v3f average_direction
,
186 v2_fill( min_co
, INFINITY
);
187 v2_fill( max_co
, -INFINITY
);
189 v3_zero( average_direction
);
190 v3_zero( average_normal
);
192 int passed_samples
= 0;
194 for( int i
=0; i
<sample_count
-1; i
++ ){
195 struct grind_sample
*si
, *sj
;
199 for( int j
=i
+1; j
<sample_count
; j
++ ){
205 /* non overlapping */
206 if( v2_dist2( si
->co
, sj
->co
) >= (0.01f
*0.01f
) )
209 /* not sharp angle */
210 if( v2_dot( si
->normal
, sj
->normal
) >= 0.7f
)
215 v3_sub( sj
->centroid
, si
->centroid
, v0
);
216 if( v3_dot( v0
, si
->normal3
) >= 0.0f
||
217 v3_dot( v0
, sj
->normal3
) <= 0.0f
)
220 v2_minv( sj
->co
, min_co
, min_co
);
221 v2_maxv( sj
->co
, max_co
, max_co
);
224 v3_copy( si
->normal3
, n0
);
225 v3_copy( sj
->normal3
, n1
);
226 v3_cross( n0
, n1
, dir
);
228 if( v3_length2( dir
) <= 0.001f
)
233 /* make sure the directions all face a common hemisphere */
234 v3_muls( dir
, vg_signf(v3_dot(dir
,plane
)), dir
);
235 v3_add( average_direction
, dir
, average_direction
);
237 float yi
= v3_dot( localplayer
.basis
[1], si
->normal3
),
238 yj
= v3_dot( localplayer
.basis
[1], sj
->normal3
);
240 if( yi
> yj
) v3_add( si
->normal3
, average_normal
, average_normal
);
241 else v3_add( sj
->normal3
, average_normal
, average_normal
);
247 if( !passed_samples
)
250 if( (v3_length2( average_direction
) <= 0.001f
) ||
251 (v3_length2( average_normal
) <= 0.001f
) )
254 float div
= 1.0f
/(float)passed_samples
;
255 v3_normalize( average_direction
);
256 v3_normalize( average_normal
);
259 v2_add( min_co
, max_co
, average_coord
);
260 v2_muls( average_coord
, 0.5f
, average_coord
);
262 v3_muls( support_axis
, average_coord
[0], inf
->co
);
263 inf
->co
[1] += average_coord
[1];
264 v3_add( pos
, inf
->co
, inf
->co
);
265 v3_copy( average_normal
, inf
->n
);
266 v3_copy( average_direction
, inf
->dir
);
268 vg_line_point( inf
->co
, 0.02f
, VG__GREEN
);
269 vg_line_arrow( inf
->co
, average_direction
, 0.3f
, VG__GREEN
);
270 vg_line_arrow( inf
->co
, inf
->n
, 0.2f
, VG__CYAN
);
272 return passed_samples
;
275 static void reset_jump_info( jump_info
*inf
){
277 inf
->land_dist
= 0.0f
;
279 inf
->type
= k_prediction_unset
;
280 v3_zero( inf
->apex
);
283 static int create_jumps_to_hit_target( jump_info
*jumps
,
284 v3f target
, float max_angle_delta
,
286 /* calculate the exact 2 solutions to jump onto that grind spot */
289 v3_sub( target
, localplayer
.rb
.co
, v0
);
290 m3x3_mulv( localplayer
.invbasis
, v0
, v0
);
298 m3x3_mulv( localplayer
.invbasis
, localplayer
.rb
.v
, v_local
);
300 v2f d
= { v3_dot( ax
, v0
), v0
[1] },
301 v
= { v3_dot( ax
, v_local
), v_local
[1] };
303 float a
= atan2f( v
[1], v
[0] ),
305 root
= m
*m
*m
*m
- gravity
*(gravity
*d
[0]*d
[0] + 2.0f
*d
[1]*m
*m
);
310 root
= sqrtf( root
);
311 float a0
= atanf( (m
*m
+ root
) / (gravity
* d
[0]) ),
312 a1
= atanf( (m
*m
- root
) / (gravity
* d
[0]) );
314 if( fabsf(a0
-a
) < max_angle_delta
){
315 jump_info
*inf
= &jumps
[ valid_count
++ ];
316 reset_jump_info( inf
);
318 v3_muls( ax
, cosf( a0
) * m
, inf
->v
);
319 inf
->v
[1] += sinf( a0
) * m
;
320 m3x3_mulv( localplayer
.basis
, inf
->v
, inf
->v
);
321 inf
->land_dist
= d
[0] / (cosf(a0
)*m
);
322 inf
->gravity
= gravity
;
324 v3_copy( target
, inf
->log
[inf
->log_length
++] );
327 if( fabsf(a1
-a
) < max_angle_delta
){
328 jump_info
*inf
= &jumps
[ valid_count
++ ];
329 reset_jump_info( inf
);
331 v3_muls( ax
, cosf( a1
) * m
, inf
->v
);
332 inf
->v
[1] += sinf( a1
) * m
;
333 m3x3_mulv( localplayer
.basis
, inf
->v
, inf
->v
);
334 inf
->land_dist
= d
[0] / (cosf(a1
)*m
);
335 inf
->gravity
= gravity
;
337 v3_copy( target
, inf
->log
[inf
->log_length
++] );
344 static void player__approximate_best_trajectory(void){
345 world_instance
*world0
= world_current_instance();
347 float k_trace_delta
= k_rb_delta
* 10.0f
;
348 struct player_skate_state
*state
= &player_skate
.state
;
350 state
->air_start
= vg
.time
;
351 v3_copy( localplayer
.rb
.v
, state
->air_init_v
);
352 v3_copy( localplayer
.rb
.co
, state
->air_init_co
);
354 player_skate
.possible_jump_count
= 0;
357 v3_cross( localplayer
.rb
.v
, localplayer
.rb
.to_world
[1], axis
);
358 v3_normalize( axis
);
360 /* at high slopes, Y component is low */
361 float upness
= v3_dot( localplayer
.rb
.to_world
[1], localplayer
.basis
[1] ),
362 angle_begin
= -(1.0f
-fabsf( upness
)),
365 struct grind_info grind
;
366 int grind_located
= 0;
367 float grind_located_gravity
= k_gravity
;
370 v3f launch_v_bounds
[2];
372 for( int i
=0; i
<2; i
++ ){
373 v3_copy( localplayer
.rb
.v
, launch_v_bounds
[i
] );
374 float ang
= (float[]){ angle_begin
, angle_end
}[ i
];
378 q_axis_angle( qbias
, axis
, ang
);
379 q_mulv( qbias
, launch_v_bounds
[i
], launch_v_bounds
[i
] );
382 for( int m
=0;m
<=30; m
++ ){
384 &player_skate
.possible_jumps
[ player_skate
.possible_jump_count
++ ];
385 reset_jump_info( inf
);
387 v3f launch_co
, launch_v
, co0
, co1
;
388 v3_copy( localplayer
.rb
.co
, launch_co
);
389 v3_copy( localplayer
.rb
.v
, launch_v
);
390 v3_copy( launch_co
, co0
);
391 world_instance
*trace_world
= world0
;
393 float vt
= (float)m
* (1.0f
/30.0f
),
394 ang
= vg_lerpf( angle_begin
, angle_end
, vt
) * 0.15f
;
397 q_axis_angle( qbias
, axis
, ang
);
398 q_mulv( qbias
, launch_v
, launch_v
);
400 float yaw_sketch
= 1.0f
-fabsf(upness
);
402 float yaw_bias
= ((float)(m
%3) - 1.0f
) * 0.08f
* yaw_sketch
;
403 q_axis_angle( qbias
, localplayer
.rb
.to_world
[1], yaw_bias
);
404 q_mulv( qbias
, launch_v
, launch_v
);
406 float gravity_bias
= vg_lerpf( 0.85f
, 1.4f
, vt
),
407 gravity
= k_gravity
* gravity_bias
;
408 inf
->gravity
= gravity
;
409 v3_copy( launch_v
, inf
->v
);
412 m3x3_copy( localplayer
.basis
, basis
);
414 for( int i
=1; i
<=50; i
++ ){
415 float t
= (float)i
* k_trace_delta
;
417 v3_muls( launch_v
, t
, co1
);
418 v3_muladds( co1
, basis
[1], -0.5f
* gravity
* t
*t
, co1
);
419 v3_add( launch_co
, co1
, co1
);
421 float launch_vy
= v3_dot( launch_v
,basis
[1] );
423 int search_for_grind
= 1;
424 if( grind_located
) search_for_grind
= 0;
425 if( launch_vy
- gravity
*t
> 0.0f
) search_for_grind
= 0;
429 v3f closest
={0.0f
,0.0f
,0.0f
};
430 if( search_for_grind
){
431 if( bh_closest_point(trace_world
->geo_bh
,co1
,closest
,1.0f
) != -1 ){
432 float min_dist
= 0.75f
;
433 min_dist
*= min_dist
;
435 if( v3_dist2( closest
, launch_co
) < min_dist
)
436 search_for_grind
= 0;
440 for( int j
=0; j
<2; j
++ ){
441 v3_muls( launch_v_bounds
[j
], t
, bound
[j
] );
442 v3_muladds( bound
[j
], basis
[1], -0.5f
*gravity
*t
*t
, bound
[j
] );
443 v3_add( launch_co
, bound
[j
], bound
[j
] );
446 float limh
= vg_minf( 2.0f
, t
),
447 minh
= vg_minf( bound
[0][1], bound
[1][1] )-limh
,
448 maxh
= vg_maxf( bound
[0][1], bound
[1][1] )+limh
;
450 if( (closest
[1] < minh
) || (closest
[1] > maxh
) ){
451 search_for_grind
= 0;
455 search_for_grind
= 0;
458 if( search_for_grind
){
460 v3_copy( launch_v
, ve
);
461 v3_muladds( ve
, basis
[1], -gravity
* t
, ve
);
463 if( skate_grind_scansq( closest
, ve
, 0.5f
, &grind
) ){
464 /* check alignment */
465 v2f v0
= { v3_dot( ve
, basis
[0] ),
466 v3_dot( ve
, basis
[2] ) },
467 v1
= { v3_dot( grind
.dir
, basis
[0] ),
468 v3_dot( grind
.dir
, basis
[2] ) };
473 float a
= v2_dot( v0
, v1
);
475 float a_min
= cosf( VG_PIf
* 0.185f
);
476 if( state
->grind_cooldown
)
477 a_min
= cosf( VG_PIf
* 0.05f
);
480 if( (fabsf(v3_dot( ve
, grind
.dir
))>=k_grind_axel_min_vel
) &&
482 (fabsf(grind
.dir
[1]) < 0.70710678118654752f
))
485 grind_located_gravity
= inf
->gravity
;
490 if( trace_world
->rendering_gate
){
491 ent_gate
*gate
= trace_world
->rendering_gate
;
492 if( gate_intersect( gate
, co1
, co0
) ){
493 m4x3_mulv( gate
->transport
, co0
, co0
);
494 m4x3_mulv( gate
->transport
, co1
, co1
);
495 m3x3_mulv( gate
->transport
, launch_v
, launch_v
);
496 m4x3_mulv( gate
->transport
, launch_co
, launch_co
);
497 m3x3_mul( gate
->transport
, basis
, basis
);
499 if( gate
->flags
& k_ent_gate_nonlocal
){
500 trace_world
= &world_static
.instances
[ gate
->target
];
508 float scan_radius
= k_board_radius
;
509 scan_radius
*= vg_clampf( t
, 0.02f
, 1.0f
);
511 int idx
= spherecast_world( trace_world
, co0
, co1
, scan_radius
, &t1
, n
,
512 k_material_flag_walking
);
515 v3_lerp( co0
, co1
, t1
, co
);
516 v3_copy( co
, inf
->log
[ inf
->log_length
++ ] );
518 v3_copy( n
, inf
->n
);
519 u32
*tri
= &trace_world
->scene_geo
.arrindices
[ idx
*3 ];
520 struct world_surface
*surf
=
521 world_tri_index_surface( trace_world
, tri
[0] );
523 inf
->type
= k_prediction_land
;
526 v3_copy( launch_v
, ve
);
527 v3_muladds( ve
, localplayer
.basis
[1], -gravity
* t
, ve
);
529 inf
->score
= -v3_dot( ve
, inf
->n
);
530 inf
->land_dist
= t
+ k_trace_delta
* t1
;
532 /* Bias prediction towords ramps */
533 if( !(surf
->info
.flags
& k_material_flag_skate_target
) )
536 if( surf
->info
.flags
& k_material_flag_boundary
)
537 player_skate
.possible_jump_count
--;
543 v3_copy( co1
, inf
->log
[ inf
->log_length
++ ] );
547 if( inf
->type
== k_prediction_unset
)
548 player_skate
.possible_jump_count
--;
552 jump_info grind_jumps
[2];
555 create_jumps_to_hit_target( grind_jumps
, grind
.co
,
556 0.175f
*VG_PIf
, grind_located_gravity
);
558 /* knock out original landing points in the 1m area */
559 for( u32 j
=0; j
<player_skate
.possible_jump_count
; j
++ ){
560 jump_info
*jump
= &player_skate
.possible_jumps
[ j
];
561 float dist
= v3_dist2( jump
->log
[jump
->log_length
-1], grind
.co
);
562 float descale
= 1.0f
-vg_minf(1.0f
,dist
);
563 jump
->score
+= descale
*3.0f
;
566 for( int i
=0; i
<valid_count
; i
++ ){
567 jump_info
*jump
= &grind_jumps
[i
];
568 jump
->type
= k_prediction_grind
;
570 v3f launch_v
, launch_co
, co0
, co1
;
572 v3_copy( jump
->v
, launch_v
);
573 v3_copy( localplayer
.rb
.co
, launch_co
);
576 m3x3_copy( localplayer
.basis
, basis
);
578 float t
= 0.05f
* jump
->land_dist
;
579 v3_muls( launch_v
, t
, co0
);
580 v3_muladds( co0
, basis
[1], -0.5f
* jump
->gravity
* t
*t
, co0
);
581 v3_add( launch_co
, co0
, co0
);
583 /* rough scan to make sure we dont collide with anything */
584 for( int j
=1; j
<=16; j
++ ){
585 t
= (float)j
*(1.0f
/16.0f
);
588 t
*= jump
->land_dist
;
590 v3_muls( launch_v
, t
, co1
);
591 v3_muladds( co1
, basis
[1], -0.5f
* jump
->gravity
* t
*t
, co1
);
592 v3_add( launch_co
, co1
, co1
);
597 int idx
= spherecast_world( world0
, co0
,co1
,
598 k_board_radius
*0.1f
, &t1
, n
,
599 k_material_flag_walking
);
601 goto invalidated_grind
;
607 v3_copy( grind
.n
, jump
->n
);
609 /* determine score */
611 v3_copy( jump
->v
, ve
);
612 v3_muladds( ve
, localplayer
.basis
[1],
613 -jump
->gravity
*jump
->land_dist
, ve
);
614 jump
->score
= -v3_dot( ve
, grind
.n
) * 0.9f
;
616 player_skate
.possible_jumps
[ player_skate
.possible_jump_count
++ ] =
625 float score_min
= INFINITY
,
626 score_max
= -INFINITY
;
628 jump_info
*best
= NULL
;
630 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
631 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
633 if( jump
->score
< score_min
)
636 score_min
= vg_minf( score_min
, jump
->score
);
637 score_max
= vg_maxf( score_max
, jump
->score
);
640 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
641 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
642 float s
= jump
->score
;
645 s
/= (score_max
-score_min
);
649 jump
->colour
= s
* 255.0f
;
653 else if( jump
->type
== k_prediction_land
)
656 jump
->colour
|= 0xff000000;
660 v3_copy( best
->n
, state
->land_normal
);
661 v3_copy( best
->v
, localplayer
.rb
.v
);
662 state
->land_dist
= best
->land_dist
;
663 state
->gravity_bias
= best
->gravity
;
665 if( best
->type
== k_prediction_grind
){
666 state
->activity
= k_skate_activity_air_to_grind
;
670 joystick_state( k_srjoystick_steer
, steer
);
671 v2_normalize_clamp( steer
);
673 if( (fabsf(steer
[1]) > 0.5f
) && (state
->land_dist
>= 1.5f
) ){
674 state
->flip_rate
= (1.0f
/state
->land_dist
) * vg_signf(steer
[1]) *
676 state
->flip_time
= 0.0f
;
677 v3_copy( localplayer
.rb
.to_world
[0], state
->flip_axis
);
680 state
->flip_rate
= 0.0f
;
681 v3_zero( state
->flip_axis
);
685 v3_copy( localplayer
.basis
[1], state
->land_normal
);
691 * Varius physics models
692 * ------------------------------------------------
696 * Air control, no real physics
698 static void skate_apply_air_model(void){
699 struct player_skate_state
*state
= &player_skate
.state
;
701 if( state
->activity_prev
> k_skate_activity_air_to_grind
)
702 player__approximate_best_trajectory();
704 float angle
= v3_dot( localplayer
.rb
.to_world
[1], state
->land_normal
);
705 angle
= vg_clampf( angle
, -1.0f
, 1.0f
);
707 v3_cross( localplayer
.rb
.to_world
[1], state
->land_normal
, axis
);
710 q_axis_angle( correction
, axis
,
711 acosf(angle
)*2.0f
*VG_TIMESTEP_FIXED
);
712 q_mul( correction
, localplayer
.rb
.q
, localplayer
.rb
.q
);
715 static enum trick_type
player_skate_trick_input(void);
716 static void skate_apply_trick_model(void){
717 struct player_skate_state
*state
= &player_skate
.state
;
720 v3f strength
= { 3.7f
, 3.6f
, 8.0f
};
722 v3_muls( state
->trick_residualv
, -4.0f
, Fd
);
723 v3_muls( state
->trick_residuald
, -10.0f
, Fs
);
725 v3_mul( strength
, F
, F
);
727 v3_muladds( state
->trick_residualv
, F
, k_rb_delta
,
728 state
->trick_residualv
);
729 v3_muladds( state
->trick_residuald
, state
->trick_residualv
,
730 k_rb_delta
, state
->trick_residuald
);
732 if( state
->activity
<= k_skate_activity_air_to_grind
){
733 if( v3_length2( state
->trick_vel
) < 0.0001f
)
736 int carry_on
= player_skate_trick_input();
738 /* we assume velocities share a common divisor, in which case the
739 * interval is the minimum value (if not zero) */
741 float min_rate
= 99999.0f
;
743 for( int i
=0; i
<3; i
++ ){
744 float v
= state
->trick_vel
[i
];
745 if( (v
> 0.0f
) && (v
< min_rate
) )
749 float interval
= 1.0f
/ min_rate
,
750 current
= floorf( state
->trick_time
/ interval
),
751 next_end
= (current
+1.0f
) * interval
;
754 /* integrate trick velocities */
755 v3_muladds( state
->trick_euler
, state
->trick_vel
, k_rb_delta
,
756 state
->trick_euler
);
758 if( !carry_on
&& (state
->trick_time
+ k_rb_delta
>= next_end
) ){
759 state
->trick_time
= 0.0f
;
760 state
->trick_euler
[0] = roundf( state
->trick_euler
[0] );
761 state
->trick_euler
[1] = roundf( state
->trick_euler
[1] );
762 state
->trick_euler
[2] = roundf( state
->trick_euler
[2] );
763 v3_copy( state
->trick_vel
, state
->trick_residualv
);
764 v3_zero( state
->trick_vel
);
767 state
->trick_time
+= k_rb_delta
;
770 if( (v3_length2(state
->trick_vel
) >= 0.0001f
) &&
771 state
->trick_time
> 0.2f
)
773 player__skate_kill_audio();
774 player__dead_transition();
777 state
->trick_euler
[0] = roundf( state
->trick_euler
[0] );
778 state
->trick_euler
[1] = roundf( state
->trick_euler
[1] );
779 state
->trick_euler
[2] = roundf( state
->trick_euler
[2] );
780 state
->trick_time
= 0.0f
;
781 v3_zero( state
->trick_vel
);
785 static void skate_apply_grab_model(void){
786 struct player_skate_state
*state
= &player_skate
.state
;
788 float grabt
= axis_state( k_sraxis_grab
);
791 v2_muladds( state
->grab_mouse_delta
, vg
.mouse_delta
, 0.02f
,
792 state
->grab_mouse_delta
);
794 v2_normalize_clamp( state
->grab_mouse_delta
);
797 v2_zero( state
->grab_mouse_delta
);
799 state
->grabbing
= vg_lerpf( state
->grabbing
, grabt
, 8.4f
*k_rb_delta
);
802 static void skate_apply_steering_model(void){
803 struct player_skate_state
*state
= &player_skate
.state
;
806 joystick_state( k_srjoystick_steer
, jsteer
);
809 float steer
= jsteer
[0],
810 grab
= axis_state( k_sraxis_grab
);
812 steer
= vg_signf( steer
) * steer
*steer
* k_steer_ground
;
815 v3_muls( localplayer
.rb
.to_world
[1], -vg_signf( steer
), steer_axis
);
820 if( state
->activity
<= k_skate_activity_air_to_grind
){
821 rate
= 6.0f
* fabsf(steer
);
825 /* rotate slower when grabbing on ground */
826 steer
*= (1.0f
-(state
->jump_charge
+grab
)*0.4f
);
828 if( state
->activity
== k_skate_activity_grind_5050
){
833 else if( state
->activity
>= k_skate_activity_grind_any
){
834 rate
*= fabsf(steer
);
836 float a
= 0.8f
* -steer
* k_rb_delta
;
839 q_axis_angle( q
, localplayer
.rb
.to_world
[1], a
);
840 q_mulv( q
, player_skate
.grind_vec
, player_skate
.grind_vec
);
842 v3_normalize( player_skate
.grind_vec
);
845 else if( state
->manual_direction
){
851 top
*= 1.0f
+v3_length( state
->throw_v
)*k_mmthrow_steer
;
855 float current
= v3_dot( localplayer
.rb
.to_world
[1], localplayer
.rb
.w
),
856 addspeed
= (steer
* -top
) - current
,
857 maxaccel
= rate
* k_rb_delta
,
858 accel
= vg_clampf( addspeed
, -maxaccel
, maxaccel
);
860 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1],
861 accel
, localplayer
.rb
.w
);
865 * Computes friction and surface interface model
867 static void skate_apply_friction_model(void){
868 struct player_skate_state
*state
= &player_skate
.state
;
871 * Computing localized friction forces for controlling the character
872 * Friction across X is significantly more than Z
876 m3x3_mulv( localplayer
.rb
.to_local
, localplayer
.rb
.v
, vel
);
879 if( fabsf(vel
[2]) > 0.01f
)
880 slip
= fabsf(-vel
[0] / vel
[2]) * vg_signf(vel
[0]);
882 if( fabsf( slip
) > 1.2f
)
883 slip
= vg_signf( slip
) * 1.2f
;
886 state
->reverse
= -vg_signf(vel
[2]);
888 vel
[0] += vg_cfrictf( vel
[0], k_friction_lat
* k_rb_delta
);
889 vel
[2] += vg_cfrictf( vel
[2], k_friction_resistance
* k_rb_delta
);
891 /* Pushing additive force */
893 if( !button_press( k_srbind_jump
) ){
894 if( button_press( k_srbind_push
) || (vg
.time
-state
->start_push
<0.75) )
896 if( (vg
.time
- state
->cur_push
) > 0.25 )
897 state
->start_push
= vg
.time
;
899 state
->cur_push
= vg
.time
;
901 double push_time
= vg
.time
- state
->start_push
;
903 float cycle_time
= push_time
*k_push_cycle_rate
,
904 accel
= k_push_accel
* (sinf(cycle_time
)*0.5f
+0.5f
),
905 amt
= accel
* VG_TIMESTEP_FIXED
,
906 current
= v3_length( vel
),
907 new_vel
= vg_minf( current
+ amt
, k_max_push_speed
),
908 delta
= new_vel
- vg_minf( current
, k_max_push_speed
);
910 vel
[2] += delta
* -state
->reverse
;
914 /* Send back to velocity */
915 m3x3_mulv( localplayer
.rb
.to_world
, vel
, localplayer
.rb
.v
);
918 static void skate_apply_jump_model(void){
919 struct player_skate_state
*state
= &player_skate
.state
;
920 int charging_jump_prev
= state
->charging_jump
;
921 state
->charging_jump
= button_press( k_srbind_jump
);
923 /* Cannot charge this in air */
924 if( state
->activity
<= k_skate_activity_air_to_grind
){
925 state
->charging_jump
= 0;
929 if( state
->charging_jump
){
930 state
->jump_charge
+= k_rb_delta
* k_jump_charge_speed
;
932 if( !charging_jump_prev
)
933 state
->jump_dir
= state
->reverse
>0.0f
? 1: 0;
936 state
->jump_charge
-= k_jump_charge_speed
* k_rb_delta
;
939 state
->jump_charge
= vg_clampf( state
->jump_charge
, 0.0f
, 1.0f
);
941 /* player let go after charging past 0.2: trigger jump */
942 if( (!state
->charging_jump
) && (state
->jump_charge
> 0.2f
) ){
945 /* Launch more up if alignment is up else improve velocity */
946 float aup
= v3_dot( localplayer
.basis
[1], localplayer
.rb
.to_world
[1] ),
948 dir
= mod
+ fabsf(aup
)*(1.0f
-mod
);
950 if( state
->activity
== k_skate_activity_ground
){
951 v3_copy( localplayer
.rb
.v
, jumpdir
);
952 v3_normalize( jumpdir
);
953 v3_muls( jumpdir
, 1.0f
-dir
, jumpdir
);
954 v3_muladds( jumpdir
, localplayer
.rb
.to_world
[1], dir
, jumpdir
);
955 v3_normalize( jumpdir
);
957 v3_copy( state
->up_dir
, jumpdir
);
958 state
->grind_cooldown
= 30;
959 state
->activity
= k_skate_activity_ground
;
962 joystick_state( k_srjoystick_steer
, steer
);
964 float tilt
= steer
[0] * 0.3f
;
965 tilt
*= vg_signf(v3_dot( localplayer
.rb
.v
,
966 player_skate
.grind_dir
));
969 q_axis_angle( qtilt
, player_skate
.grind_dir
, tilt
);
970 q_mulv( qtilt
, jumpdir
, jumpdir
);
972 state
->surface_cooldown
= 10;
974 float force
= k_jump_force
*state
->jump_charge
;
975 v3_muladds( localplayer
.rb
.v
, jumpdir
, force
, localplayer
.rb
.v
);
976 state
->jump_charge
= 0.0f
;
977 state
->jump_time
= vg
.time
;
978 player__networked_sfx( k_player_subsystem_skate
, 32,
979 k_player_skate_soundeffect_jump
,
980 localplayer
.rb
.co
, 1.0f
);
984 static void skate_apply_pump_model(void){
985 struct player_skate_state
*state
= &player_skate
.state
;
987 if( state
->activity
!= k_skate_activity_ground
){
988 v3_zero( state
->throw_v
);
992 /* Throw / collect routine
994 if( axis_state( k_sraxis_grab
) > 0.5f
){
995 if( state
->activity
== k_skate_activity_ground
){
997 v3_muls( localplayer
.rb
.to_world
[1], k_mmthrow_scale
, state
->throw_v
);
1002 float doty
= v3_dot( localplayer
.rb
.to_world
[1], state
->throw_v
);
1005 v3_muladds( state
->throw_v
, localplayer
.rb
.to_world
[1], -doty
, Fl
);
1007 if( state
->activity
== k_skate_activity_ground
){
1008 if( v3_length2(localplayer
.rb
.v
)<(20.0f
*20.0f
) ){
1009 v3_muladds( localplayer
.rb
.v
, Fl
,
1010 k_mmcollect_lat
, localplayer
.rb
.v
);
1012 v3_muladds( state
->throw_v
, Fl
, -k_mmcollect_lat
, state
->throw_v
);
1015 v3_muls( localplayer
.rb
.to_world
[1], -doty
, Fv
);
1016 v3_muladds( localplayer
.rb
.v
, Fv
, k_mmcollect_vert
, localplayer
.rb
.v
);
1017 v3_muladds( state
->throw_v
, Fv
, k_mmcollect_vert
, state
->throw_v
);
1021 if( v3_length2( state
->throw_v
) > 0.0001f
){
1023 v3_copy( state
->throw_v
, dir
);
1024 v3_normalize( dir
);
1026 float max
= v3_dot( dir
, state
->throw_v
),
1027 amt
= vg_minf( k_mmdecay
* k_rb_delta
, max
);
1028 v3_muladds( state
->throw_v
, dir
, -amt
, state
->throw_v
);
1032 static void skate_apply_cog_model(void){
1033 struct player_skate_state
*state
= &player_skate
.state
;
1035 v3f ideal_cog
, ideal_diff
, ideal_dir
;
1036 v3_copy( state
->up_dir
, ideal_dir
);
1037 v3_normalize( ideal_dir
);
1039 float grab
= axis_state( k_sraxis_grab
);
1040 v3_muladds( localplayer
.rb
.co
, ideal_dir
, 1.0f
-grab
, ideal_cog
);
1041 v3_sub( ideal_cog
, state
->cog
, ideal_diff
);
1043 /* Apply velocities */
1045 v3_sub( localplayer
.rb
.v
, state
->cog_v
, rv
);
1048 v3_muls( ideal_diff
, -k_cog_spring
* k_rb_rate
, F
);
1049 v3_muladds( F
, rv
, -k_cog_damp
* k_rb_rate
, F
);
1051 float ra
= k_cog_mass_ratio
,
1052 rb
= 1.0f
-k_cog_mass_ratio
;
1054 /* Apply forces & intergrate */
1055 v3_muladds( state
->cog_v
, F
, -rb
, state
->cog_v
);
1056 v3_muladds( state
->cog_v
, localplayer
.basis
[1], -9.8f
* k_rb_delta
,
1059 v3_muladds( state
->cog
, state
->cog_v
, k_rb_delta
, state
->cog
);
1062 static void skate_integrate(void){
1063 struct player_skate_state
*state
= &player_skate
.state
;
1065 float rate_x
= 1.0f
- (k_rb_delta
* 3.0f
),
1069 if( state
->activity
>= k_skate_activity_grind_any
){
1070 rate_x
= 1.0f
-(16.0f
*k_rb_delta
);
1071 rate_y
= 1.0f
-(10.0f
*k_rb_delta
);
1072 rate_z
= 1.0f
-(40.0f
*k_rb_delta
);
1075 float wx
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[0] ) * rate_x
,
1076 wy
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1] ) * rate_y
,
1077 wz
= v3_dot( localplayer
.rb
.w
, localplayer
.rb
.to_world
[2] ) * rate_z
;
1079 v3_muls( localplayer
.rb
.to_world
[0], wx
, localplayer
.rb
.w
);
1080 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[1], wy
,
1082 v3_muladds( localplayer
.rb
.w
, localplayer
.rb
.to_world
[2], wz
,
1085 state
->flip_time
+= state
->flip_rate
* k_rb_delta
;
1086 rb_update_transform( &localplayer
.rb
);
1089 static enum trick_type
player_skate_trick_input(void){
1090 return (button_press( k_srbind_trick0
) ) |
1091 (button_press( k_srbind_trick1
) << 1) |
1092 (button_press( k_srbind_trick2
) << 1) |
1093 (button_press( k_srbind_trick2
) );
1096 static void player__skate_pre_update(void){
1097 struct player_skate_state
*state
= &player_skate
.state
;
1099 if( button_down( k_srbind_use
) ){
1100 localplayer
.subsystem
= k_player_subsystem_walk
;
1103 v3_copy( localplayer
.cam
.angles
, localplayer
.angles
);
1104 localplayer
.angles
[2] = 0.0f
;
1107 m4x3_mulv( localplayer
.rb
.to_world
, (v3f
){0.0f
,1.0f
,0.0f
}, newpos
);
1108 v3_add( newpos
, (v3f
){0.0f
,-1.0f
,0.0f
}, newpos
);
1109 v3_sub( localplayer
.rb
.co
, newpos
, offset
);
1110 v3_copy( newpos
, localplayer
.rb
.co
);
1112 player__begin_holdout( offset
);
1113 player__skate_kill_audio();
1114 player__walk_transition();
1118 if( state
->activity
<= k_skate_activity_air_to_grind
){
1119 enum trick_type trick
= k_trick_type_none
;
1120 if( (trick
= player_skate_trick_input()) ){
1121 if( (vg
.time
- state
->jump_time
) < 0.1f
){
1122 v3_zero( state
->trick_vel
);
1123 state
->trick_time
= 0.0f
;
1125 if( trick
== k_trick_type_kickflip
){
1126 state
->trick_vel
[0] = 3.0f
;
1128 else if( trick
== k_trick_type_shuvit
){
1129 state
->trick_vel
[2] = 3.0f
;
1131 else if( trick
== k_trick_type_treflip
){
1132 state
->trick_vel
[0] = 2.0f
;
1133 state
->trick_vel
[2] = 2.0f
;
1135 state
->trick_type
= trick
;
1140 state
->trick_type
= k_trick_type_none
;
1143 static void player__skate_post_update(void){
1144 struct player_skate_state
*state
= &player_skate
.state
;
1146 for( int i
=0; i
<player_skate
.possible_jump_count
; i
++ ){
1147 jump_info
*jump
= &player_skate
.possible_jumps
[i
];
1149 if( jump
->log_length
== 0 ){
1150 vg_fatal_error( "assert: jump->log_length == 0\n" );
1153 for( int j
=0; j
<jump
->log_length
- 1; j
++ ){
1154 float brightness
= jump
->score
*jump
->score
*jump
->score
;
1156 v3_lerp( jump
->log
[j
], jump
->log
[j
+1], brightness
, p1
);
1157 vg_line( jump
->log
[j
], p1
, jump
->colour
);
1160 vg_line_cross( jump
->log
[jump
->log_length
-1], jump
->colour
, 0.25f
);
1163 v3_add( jump
->log
[jump
->log_length
-1], jump
->n
, p1
);
1164 vg_line( jump
->log
[jump
->log_length
-1], p1
, 0xffffffff );
1166 vg_line_point( jump
->apex
, 0.02f
, 0xffffffff );
1171 float air
= state
->activity
<= k_skate_activity_air_to_grind
? 1.0f
: 0.0f
,
1172 speed
= v3_length( localplayer
.rb
.v
),
1173 attn
= vg_minf( 1.0f
, speed
*0.1f
),
1174 slide
= vg_clampf( fabsf(state
->slip
), 0.0f
, 1.0f
);
1176 if( state
->activity
>= k_skate_activity_grind_any
){
1180 f32 gate
= skaterift
.time_rate
,
1181 vol_main
= sqrtf( (1.0f
-air
)*attn
*(1.0f
-slide
) * 0.4f
) * gate
,
1182 vol_air
= sqrtf( air
*attn
* 0.5f
) * gate
,
1183 vol_slide
= sqrtf( (1.0f
-air
)*attn
*slide
* 0.25f
) * gate
;
1185 const u32 flags
= AUDIO_FLAG_SPACIAL_3D
|AUDIO_FLAG_LOOP
;
1187 if( !player_skate
.aud_air
){
1188 player_skate
.aud_air
= audio_get_first_idle_channel();
1189 if( player_skate
.aud_air
)
1190 audio_channel_init( player_skate
.aud_air
, &audio_board
[1], flags
);
1193 if( !player_skate
.aud_slide
){
1194 player_skate
.aud_slide
= audio_get_first_idle_channel();
1195 if( player_skate
.aud_slide
)
1196 audio_channel_init( player_skate
.aud_slide
, &audio_board
[2], flags
);
1200 /* brrrrrrrrrrrt sound for tiles and stuff
1201 * --------------------------------------------------------*/
1202 float sidechain_amt
= 0.0f
,
1203 hz
= vg_maxf( speed
* 2.0f
, 2.0f
);
1205 if( (player_skate
.surface
== k_surface_prop_tiles
) &&
1206 (state
->activity
< k_skate_activity_grind_any
) )
1207 sidechain_amt
= 1.0f
;
1209 sidechain_amt
= 0.0f
;
1211 audio_set_lfo_frequency( 0, hz
);
1212 audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar
,
1213 vg_lerpf( 250.0f
, 80.0f
, attn
) );
1215 if( player_skate
.sample_change_cooldown
> 0.0f
){
1216 player_skate
.sample_change_cooldown
-= vg
.time_frame_delta
;
1219 int sample_type
= k_skate_sample_concrete
;
1221 if( state
->activity
== k_skate_activity_grind_5050
){
1222 if( player_skate
.surface
== k_surface_prop_metal
)
1223 sample_type
= k_skate_sample_metal_scrape_generic
;
1225 sample_type
= k_skate_sample_concrete_scrape_metal
;
1227 else if( (state
->activity
== k_skate_activity_grind_back50
) ||
1228 (state
->activity
== k_skate_activity_grind_front50
) )
1230 if( player_skate
.surface
== k_surface_prop_metal
){
1231 sample_type
= k_skate_sample_metal_scrape_generic
;
1234 float a
= v3_dot( localplayer
.rb
.to_world
[2],
1235 player_skate
.grind_dir
);
1236 if( fabsf(a
) > 0.70710678118654752f
)
1237 sample_type
= k_skate_sample_concrete_scrape_wood
;
1239 sample_type
= k_skate_sample_concrete_scrape_metal
;
1242 else if( state
->activity
== k_skate_activity_grind_boardslide
){
1243 if( player_skate
.surface
== k_surface_prop_metal
)
1244 sample_type
= k_skate_sample_metal_scrape_generic
;
1246 sample_type
= k_skate_sample_concrete_scrape_wood
;
1249 audio_clip
*relevant_samples
[] = {
1257 if( (player_skate
.main_sample_type
!= sample_type
) ||
1258 (!player_skate
.aud_main
) ){
1260 player_skate
.aud_main
=
1261 audio_channel_crossfade( player_skate
.aud_main
,
1262 relevant_samples
[sample_type
],
1264 player_skate
.sample_change_cooldown
= 0.1f
;
1265 player_skate
.main_sample_type
= sample_type
;
1269 if( player_skate
.aud_main
){
1270 player_skate
.aud_main
->colour
= 0x00103efe;
1271 audio_channel_set_spacial( player_skate
.aud_main
,
1272 localplayer
.rb
.co
, 40.0f
);
1273 //audio_channel_slope_volume( player_skate.aud_main, 0.05f, vol_main );
1274 audio_channel_edit_volume( player_skate
.aud_main
, vol_main
, 1 );
1275 audio_channel_sidechain_lfo( player_skate
.aud_main
, 0, sidechain_amt
);
1277 float rate
= 1.0f
+ (attn
-0.5f
)*0.2f
;
1278 audio_channel_set_sampling_rate( player_skate
.aud_main
, rate
);
1281 if( player_skate
.aud_slide
){
1282 player_skate
.aud_slide
->colour
= 0x00103efe;
1283 audio_channel_set_spacial( player_skate
.aud_slide
,
1284 localplayer
.rb
.co
, 40.0f
);
1285 //audio_channel_slope_volume( player_skate.aud_slide, 0.05f, vol_slide );
1286 audio_channel_edit_volume( player_skate
.aud_slide
, vol_slide
, 1 );
1287 audio_channel_sidechain_lfo( player_skate
.aud_slide
, 0, sidechain_amt
);
1290 if( player_skate
.aud_air
){
1291 player_skate
.aud_air
->colour
= 0x00103efe;
1292 audio_channel_set_spacial( player_skate
.aud_air
,
1293 localplayer
.rb
.co
, 40.0f
);
1294 //audio_channel_slope_volume( player_skate.aud_air, 0.05f, vol_air );
1295 audio_channel_edit_volume( player_skate
.aud_air
, vol_air
, 1 );
1302 * truck alignment model at ra(local)
1303 * returns 1 if valid surface:
1304 * surface_normal will be filled out with an averaged normal vector
1305 * axel_dir will be the direction from left to right wheels
1307 * returns 0 if no good surface found
1310 int skate_compute_surface_alignment( v3f ra
, u32 colour
,
1311 v3f surface_normal
, v3f axel_dir
){
1312 world_instance
*world
= world_current_instance();
1314 v3f truck
, left
, right
;
1315 m4x3_mulv( localplayer
.rb
.to_world
, ra
, truck
);
1317 v3_muladds( truck
, localplayer
.rb
.to_world
[0], -k_board_width
, left
);
1318 v3_muladds( truck
, localplayer
.rb
.to_world
[0], k_board_width
, right
);
1319 vg_line( left
, right
, colour
);
1321 float k_max_truck_flex
= VG_PIf
* 0.25f
;
1323 ray_hit ray_l
, ray_r
;
1326 v3_muls( localplayer
.rb
.to_world
[1], -1.0f
, dir
);
1328 int res_l
= 0, res_r
= 0;
1330 for( int i
=0; i
<8; i
++ ){
1331 float t
= 1.0f
- (float)i
* (1.0f
/8.0f
);
1332 v3_muladds( truck
, localplayer
.rb
.to_world
[0], -k_board_radius
*t
, left
);
1333 v3_muladds( left
, localplayer
.rb
.to_world
[1], k_board_radius
, left
);
1334 ray_l
.dist
= 2.1f
* k_board_radius
;
1336 res_l
= ray_world( world
, left
, dir
, &ray_l
, k_material_flag_walking
);
1342 for( int i
=0; i
<8; i
++ ){
1343 float t
= 1.0f
- (float)i
* (1.0f
/8.0f
);
1344 v3_muladds( truck
, localplayer
.rb
.to_world
[0], k_board_radius
*t
, right
);
1345 v3_muladds( right
, localplayer
.rb
.to_world
[1], k_board_radius
, right
);
1346 ray_r
.dist
= 2.1f
* k_board_radius
;
1348 res_r
= ray_world( world
, right
, dir
, &ray_r
, k_material_flag_walking
);
1356 v3f tangent_average
;
1357 v3_muladds( truck
, localplayer
.rb
.to_world
[1], -k_board_radius
, midpoint
);
1358 v3_zero( tangent_average
);
1360 if( res_l
|| res_r
){
1362 v3_copy( midpoint
, p0
);
1363 v3_copy( midpoint
, p1
);
1366 v3_copy( ray_l
.pos
, p0
);
1367 v3_cross( ray_l
.normal
, localplayer
.rb
.to_world
[0], t
);
1368 v3_add( t
, tangent_average
, tangent_average
);
1371 v3_copy( ray_r
.pos
, p1
);
1372 v3_cross( ray_r
.normal
, localplayer
.rb
.to_world
[0], t
);
1373 v3_add( t
, tangent_average
, tangent_average
);
1376 v3_sub( p1
, p0
, v0
);
1380 /* fallback: use the closes point to the trucks */
1382 int idx
= bh_closest_point( world
->geo_bh
, midpoint
, closest
, 0.1f
);
1385 u32
*tri
= &world
->scene_geo
.arrindices
[ idx
* 3 ];
1388 for( int j
=0; j
<3; j
++ )
1389 v3_copy( world
->scene_geo
.arrvertices
[ tri
[j
] ].co
, verts
[j
] );
1391 v3f vert0
, vert1
, n
;
1392 v3_sub( verts
[1], verts
[0], vert0
);
1393 v3_sub( verts
[2], verts
[0], vert1
);
1394 v3_cross( vert0
, vert1
, n
);
1397 if( v3_dot( n
, localplayer
.rb
.to_world
[1] ) < 0.3f
)
1400 v3_cross( n
, localplayer
.rb
.to_world
[2], v0
);
1401 v3_muladds( v0
, localplayer
.rb
.to_world
[2],
1402 -v3_dot( localplayer
.rb
.to_world
[2], v0
), v0
);
1406 v3_cross( n
, localplayer
.rb
.to_world
[0], t
);
1407 v3_add( t
, tangent_average
, tangent_average
);
1413 v3_muladds( truck
, v0
, k_board_width
, right
);
1414 v3_muladds( truck
, v0
, -k_board_width
, left
);
1416 vg_line( left
, right
, VG__WHITE
);
1418 v3_normalize( tangent_average
);
1419 v3_cross( v0
, tangent_average
, surface_normal
);
1420 v3_copy( v0
, axel_dir
);
1425 static void skate_weight_distribute(void){
1426 struct player_skate_state
*state
= &player_skate
.state
;
1427 v3_zero( player_skate
.weight_distribution
);
1429 int reverse_dir
= v3_dot( localplayer
.rb
.to_world
[2],
1430 localplayer
.rb
.v
) < 0.0f
?1:-1;
1433 joystick_state( k_srjoystick_steer
, steer
);
1435 if( state
->manual_direction
== 0 ){
1436 if( (steer
[1] > 0.7f
) && (state
->activity
== k_skate_activity_ground
) &&
1437 (state
->jump_charge
<= 0.01f
) )
1438 state
->manual_direction
= reverse_dir
;
1441 if( steer
[1] < 0.1f
){
1442 state
->manual_direction
= 0;
1445 if( reverse_dir
!= state
->manual_direction
){
1451 if( state
->manual_direction
){
1452 float amt
= vg_minf( steer
[1] * 8.0f
, 1.0f
);
1453 player_skate
.weight_distribution
[2] = k_board_length
* amt
*
1454 (float)state
->manual_direction
;
1457 if( state
->manual_direction
){
1460 m3x3_mulv( localplayer
.rb
.to_world
, player_skate
.weight_distribution
,
1462 v3_negate( plane_z
, plane_z
);
1464 v3_muladds( plane_z
, player_skate
.surface_picture
,
1465 -v3_dot( plane_z
, player_skate
.surface_picture
), plane_z
);
1466 v3_normalize( plane_z
);
1468 v3_muladds( plane_z
, player_skate
.surface_picture
, 0.3f
, plane_z
);
1469 v3_normalize( plane_z
);
1472 v3_muladds( localplayer
.rb
.co
, plane_z
, 1.5f
, p1
);
1473 vg_line( localplayer
.rb
.co
, p1
, VG__GREEN
);
1476 v3_muls( localplayer
.rb
.to_world
[2], -(float)state
->manual_direction
,
1479 rb_effect_spring_target_vector( &localplayer
.rb
, refdir
, plane_z
,
1480 k_manul_spring
, k_manul_dampener
,
1481 player_skate
.substep_delta
);
1485 static void skate_adjust_up_direction(void){
1486 struct player_skate_state
*state
= &player_skate
.state
;
1488 if( state
->activity
== k_skate_activity_ground
){
1490 v3_copy( player_skate
.surface_picture
, target
);
1492 target
[1] += 2.0f
* player_skate
.surface_picture
[1];
1493 v3_normalize( target
);
1495 v3_lerp( state
->up_dir
, target
,
1496 8.0f
* player_skate
.substep_delta
, state
->up_dir
);
1498 else if( state
->activity
<= k_skate_activity_air_to_grind
){
1499 v3_lerp( state
->up_dir
, localplayer
.rb
.to_world
[1],
1500 8.0f
* player_skate
.substep_delta
, state
->up_dir
);
1504 v3_add( localplayer
.rb
.to_world
[1], localplayer
.basis
[1], avg
);
1505 v3_normalize( avg
);
1507 v3_lerp( state
->up_dir
, avg
,
1508 6.0f
* player_skate
.substep_delta
, state
->up_dir
);
1512 static int skate_point_visible( v3f origin
, v3f target
){
1514 v3_sub( target
, origin
, dir
);
1517 ray
.dist
= v3_length( dir
);
1518 v3_muls( dir
, 1.0f
/ray
.dist
, dir
);
1521 if( ray_world( world_current_instance(), origin
, dir
, &ray
,
1522 k_material_flag_walking
) )
1528 static void skate_grind_orient( struct grind_info
*inf
, m3x3f mtx
){
1529 v3_copy( inf
->dir
, mtx
[0] );
1530 v3_copy( inf
->n
, mtx
[1] );
1531 v3_cross( mtx
[0], mtx
[1], mtx
[2] );
1534 static void skate_grind_friction( struct grind_info
*inf
, float strength
){
1536 v3_muladds( localplayer
.rb
.to_world
[2], inf
->n
,
1537 -v3_dot( localplayer
.rb
.to_world
[2], inf
->n
), v2
);
1539 float a
= 1.0f
-fabsf( v3_dot( v2
, inf
->dir
) ),
1540 dir
= vg_signf( v3_dot( localplayer
.rb
.v
, inf
->dir
) ),
1541 F
= a
* -dir
* k_grind_max_friction
;
1543 v3_muladds( localplayer
.rb
.v
, inf
->dir
, F
*k_rb_delta
*strength
,
1547 static void skate_grind_decay( struct grind_info
*inf
, float strength
){
1549 skate_grind_orient( inf
, mtx
);
1550 m3x3_transpose( mtx
, mtx_inv
);
1553 m3x3_mulv( mtx_inv
, localplayer
.rb
.v
, v_grind
);
1555 float decay
= 1.0f
- ( k_rb_delta
* k_grind_decayxy
* strength
);
1556 v3_mul( v_grind
, (v3f
){ 1.0f
, decay
, decay
}, v_grind
);
1557 m3x3_mulv( mtx
, v_grind
, localplayer
.rb
.v
);
1560 static void skate_grind_truck_apply( float sign
, struct grind_info
*inf
,
1562 struct player_skate_state
*state
= &player_skate
.state
;
1565 v3f ra
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1567 m3x3_mulv( localplayer
.rb
.to_world
, ra
, raw
);
1568 v3_add( localplayer
.rb
.co
, raw
, wsp
);
1570 v3_copy( ra
, player_skate
.weight_distribution
);
1573 v3_sub( inf
->co
, wsp
, delta
);
1576 v3_muladds( localplayer
.rb
.v
, delta
, k_spring_force
*strength
*k_rb_delta
,
1579 skate_grind_decay( inf
, strength
);
1580 skate_grind_friction( inf
, strength
);
1582 /* yeah yeah yeah yeah */
1583 v3f raw_nplane
, axis
;
1584 v3_muladds( raw
, inf
->n
, -v3_dot( inf
->n
, raw
), raw_nplane
);
1585 v3_cross( raw_nplane
, inf
->n
, axis
);
1586 v3_normalize( axis
);
1590 skate_grind_orient( inf
, mtx
);
1591 v3f target_fwd
, fwd
, up
, target_up
;
1592 m3x3_mulv( mtx
, player_skate
.grind_vec
, target_fwd
);
1593 v3_copy( raw_nplane
, fwd
);
1594 v3_copy( localplayer
.rb
.to_world
[1], up
);
1595 v3_copy( inf
->n
, target_up
);
1597 v3_muladds( target_fwd
, inf
->n
, -v3_dot(inf
->n
,target_fwd
), target_fwd
);
1598 v3_muladds( fwd
, inf
->n
, -v3_dot(inf
->n
,fwd
), fwd
);
1600 v3_normalize( target_fwd
);
1601 v3_normalize( fwd
);
1604 joystick_state( k_srjoystick_steer
, steer
);
1606 float way
= steer
[1] * vg_signf( v3_dot( raw_nplane
, localplayer
.rb
.v
) );
1609 q_axis_angle( q
, axis
, VG_PIf
*0.125f
* way
);
1610 q_mulv( q
, target_up
, target_up
);
1611 q_mulv( q
, target_fwd
, target_fwd
);
1613 rb_effect_spring_target_vector( &localplayer
.rb
, up
, target_up
,
1618 rb_effect_spring_target_vector( &localplayer
.rb
, fwd
, target_fwd
,
1619 k_grind_spring
*strength
,
1620 k_grind_dampener
*strength
,
1623 vg_line_arrow( localplayer
.rb
.co
, target_up
, 1.0f
, VG__GREEN
);
1624 vg_line_arrow( localplayer
.rb
.co
, fwd
, 0.8f
, VG__RED
);
1625 vg_line_arrow( localplayer
.rb
.co
, target_fwd
, 1.0f
, VG__YELOW
);
1627 player_skate
.grind_strength
= strength
;
1630 struct grind_limit
*limit
=
1631 &player_skate
.limits
[ player_skate
.limit_count
++ ];
1632 m4x3_mulv( localplayer
.rb
.to_local
, wsp
, limit
->ra
);
1633 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, limit
->n
);
1636 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1639 static void skate_5050_apply( struct grind_info
*inf_front
,
1640 struct grind_info
*inf_back
){
1641 struct player_skate_state
*state
= &player_skate
.state
;
1642 struct grind_info inf_avg
;
1644 v3_sub( inf_front
->co
, inf_back
->co
, inf_avg
.dir
);
1645 v3_muladds( inf_back
->co
, inf_avg
.dir
, 0.5f
, inf_avg
.co
);
1646 v3_normalize( inf_avg
.dir
);
1649 v3_muls( inf_avg
.dir
, vg_signf(v3_dot(inf_avg
.dir
,localplayer
.rb
.v
)),
1652 v3f axis_front
, axis_back
, axis
;
1653 v3_cross( inf_front
->dir
, inf_front
->n
, axis_front
);
1654 v3_cross( inf_back
->dir
, inf_back
->n
, axis_back
);
1655 v3_add( axis_front
, axis_back
, axis
);
1656 v3_normalize( axis
);
1658 v3_cross( axis
, inf_avg
.dir
, inf_avg
.n
);
1659 skate_grind_decay( &inf_avg
, 1.0f
);
1662 joystick_state( k_srjoystick_steer
, steer
);
1664 float way
= steer
[1] * vg_signf( v3_dot( localplayer
.rb
.to_world
[2],
1665 localplayer
.rb
.v
) );
1668 v3_copy( localplayer
.rb
.to_world
[1], up
);
1669 v3_copy( inf_avg
.n
, target_up
);
1670 q_axis_angle( q
, localplayer
.rb
.to_world
[0], VG_PIf
*0.25f
* -way
);
1671 q_mulv( q
, target_up
, target_up
);
1673 v3_zero( player_skate
.weight_distribution
);
1674 player_skate
.weight_distribution
[2] = k_board_length
* -way
;
1676 rb_effect_spring_target_vector( &localplayer
.rb
, up
, target_up
,
1680 vg_line_arrow( localplayer
.rb
.co
, up
, 1.0f
, VG__GREEN
);
1681 vg_line_arrow( localplayer
.rb
.co
, target_up
, 1.0f
, VG__GREEN
);
1683 v3f fwd_nplane
, dir_nplane
;
1684 v3_muladds( localplayer
.rb
.to_world
[2], inf_avg
.n
,
1685 -v3_dot( localplayer
.rb
.to_world
[2], inf_avg
.n
), fwd_nplane
);
1688 v3_muls( inf_avg
.dir
, v3_dot( fwd_nplane
, inf_avg
.dir
), dir
);
1689 v3_muladds( dir
, inf_avg
.n
, -v3_dot( dir
, inf_avg
.n
), dir_nplane
);
1691 v3_normalize( fwd_nplane
);
1692 v3_normalize( dir_nplane
);
1694 rb_effect_spring_target_vector( &localplayer
.rb
, fwd_nplane
, dir_nplane
,
1698 vg_line_arrow( localplayer
.rb
.co
, fwd_nplane
, 0.8f
, VG__RED
);
1699 vg_line_arrow( localplayer
.rb
.co
, dir_nplane
, 0.8f
, VG__RED
);
1701 v3f pos_front
= { 0.0f
, -k_board_radius
, -1.0f
* k_board_length
},
1702 pos_back
= { 0.0f
, -k_board_radius
, 1.0f
* k_board_length
},
1703 delta_front
, delta_back
, delta_total
;
1705 m4x3_mulv( localplayer
.rb
.to_world
, pos_front
, pos_front
);
1706 m4x3_mulv( localplayer
.rb
.to_world
, pos_back
, pos_back
);
1708 v3_sub( inf_front
->co
, pos_front
, delta_front
);
1709 v3_sub( inf_back
->co
, pos_back
, delta_back
);
1710 v3_add( delta_front
, delta_back
, delta_total
);
1712 v3_muladds( localplayer
.rb
.v
, delta_total
, 50.0f
* k_rb_delta
,
1716 struct grind_limit
*limit
=
1717 &player_skate
.limits
[ player_skate
.limit_count
++ ];
1718 v3_zero( limit
->ra
);
1719 m3x3_mulv( localplayer
.rb
.to_local
, inf_avg
.n
, limit
->n
);
1722 v3_copy( inf_avg
.dir
, player_skate
.grind_dir
);
1725 static int skate_grind_truck_renew( f32 sign
, struct grind_info
*inf
){
1726 struct player_skate_state
*state
= &player_skate
.state
;
1728 v3f wheel_co
= { 0.0f
, 0.0f
, sign
* k_board_length
},
1729 grind_co
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1731 m4x3_mulv( localplayer
.rb
.to_world
, wheel_co
, wheel_co
);
1732 m4x3_mulv( localplayer
.rb
.to_world
, grind_co
, grind_co
);
1734 /* Exit condition: lost grind tracking */
1735 if( !skate_grind_scansq( grind_co
, localplayer
.rb
.v
, 0.3f
, inf
) )
1738 /* Exit condition: cant see grind target directly */
1739 if( !skate_point_visible( wheel_co
, inf
->co
) )
1742 /* Exit condition: minimum velocity not reached, but allow a bit of error */
1743 float dv
= fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)),
1744 minv
= k_grind_axel_min_vel
*0.8f
;
1749 if( fabsf(v3_dot( inf
->dir
, player_skate
.grind_dir
)) < k_grind_max_edge_angle
)
1752 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1756 static int skate_grind_truck_entry( f32 sign
, struct grind_info
*inf
){
1757 struct player_skate_state
*state
= &player_skate
.state
;
1760 v3f ra
= { 0.0f
, -k_board_radius
, sign
* k_board_length
};
1763 m3x3_mulv( localplayer
.rb
.to_world
, ra
, raw
);
1764 v3_add( localplayer
.rb
.co
, raw
, wsp
);
1766 if( skate_grind_scansq( wsp
, localplayer
.rb
.v
, 0.3, inf
) ){
1767 if( fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)) < k_grind_axel_min_vel
)
1770 /* velocity should be at least 60% aligned */
1772 v3_cross( inf
->n
, inf
->dir
, axis
);
1773 v3_muladds( localplayer
.rb
.v
, inf
->n
,
1774 -v3_dot( localplayer
.rb
.v
, inf
->n
), pv
);
1776 if( v3_length2( pv
) < 0.0001f
)
1780 if( fabsf(v3_dot( pv
, inf
->dir
)) < k_grind_axel_max_angle
)
1783 if( v3_dot( localplayer
.rb
.v
, inf
->n
) > 0.5f
)
1786 v3f local_co
, local_dir
, local_n
;
1787 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1788 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1789 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, local_n
);
1791 v2f delta
= { local_co
[0], local_co
[2] - k_board_length
*sign
};
1793 float truck_height
= -(k_board_radius
+0.03f
);
1796 v3_cross( localplayer
.rb
.w
, raw
, rv
);
1797 v3_add( localplayer
.rb
.v
, rv
, rv
);
1799 if( (local_co
[1] >= truck_height
) &&
1800 (v2_length2( delta
) <= k_board_radius
*k_board_radius
) )
1809 static void skate_boardslide_apply( struct grind_info
*inf
){
1810 struct player_skate_state
*state
= &player_skate
.state
;
1812 v3f local_co
, local_dir
, local_n
;
1813 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1814 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1815 m3x3_mulv( localplayer
.rb
.to_local
, inf
->n
, local_n
);
1818 v3_muladds( local_co
, local_dir
, local_co
[0]/-local_dir
[0],
1820 v3_copy( intersection
, player_skate
.weight_distribution
);
1822 skate_grind_decay( inf
, 0.0125f
);
1823 skate_grind_friction( inf
, 0.25f
);
1825 /* direction alignment */
1827 v3_cross( local_dir
, local_n
, perp
);
1828 v3_muls( local_dir
, vg_signf(local_dir
[0]), dir
);
1829 v3_muls( perp
, vg_signf(perp
[2]), perp
);
1831 m3x3_mulv( localplayer
.rb
.to_world
, dir
, dir
);
1832 m3x3_mulv( localplayer
.rb
.to_world
, perp
, perp
);
1835 q_axis_angle( qbalance
, dir
, local_co
[0]*k_grind_balance
);
1836 q_mulv( qbalance
, perp
, perp
);
1838 rb_effect_spring_target_vector( &localplayer
.rb
, localplayer
.rb
.to_world
[0],
1840 k_grind_spring
, k_grind_dampener
,
1843 rb_effect_spring_target_vector( &localplayer
.rb
, localplayer
.rb
.to_world
[2],
1845 k_grind_spring
, k_grind_dampener
,
1848 vg_line_arrow( localplayer
.rb
.co
, dir
, 0.5f
, VG__GREEN
);
1849 vg_line_arrow( localplayer
.rb
.co
, perp
, 0.5f
, VG__BLUE
);
1851 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1854 static int skate_boardslide_entry( struct grind_info
*inf
){
1855 struct player_skate_state
*state
= &player_skate
.state
;
1857 if( skate_grind_scansq( localplayer
.rb
.co
,
1858 localplayer
.rb
.to_world
[0], k_board_length
,
1861 v3f local_co
, local_dir
;
1862 m4x3_mulv( localplayer
.rb
.to_local
, inf
->co
, local_co
);
1863 m3x3_mulv( localplayer
.rb
.to_local
, inf
->dir
, local_dir
);
1865 if( (fabsf(local_co
[2]) <= k_board_length
) && /* within wood area */
1866 (local_co
[1] >= 0.0f
) && /* at deck level */
1867 (fabsf(local_dir
[0]) >= 0.25f
) ) /* perpendicular to us */
1869 if( fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)) < k_grind_axel_min_vel
)
1879 static int skate_boardslide_renew( struct grind_info
*inf
){
1880 struct player_skate_state
*state
= &player_skate
.state
;
1882 if( !skate_grind_scansq( localplayer
.rb
.co
,
1883 localplayer
.rb
.to_world
[0], k_board_length
,
1887 /* Exit condition: cant see grind target directly */
1889 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.to_world
[1], 0.2f
, vis
);
1890 if( !skate_point_visible( vis
, inf
->co
) )
1893 /* Exit condition: minimum velocity not reached, but allow a bit of error */
1894 float dv
= fabsf(v3_dot( localplayer
.rb
.v
, inf
->dir
)),
1895 minv
= k_grind_axel_min_vel
*0.8f
;
1900 if( fabsf(v3_dot( inf
->dir
, player_skate
.grind_dir
)) < k_grind_max_edge_angle
)
1906 static void skate_store_grind_vec( struct grind_info
*inf
){
1907 struct player_skate_state
*state
= &player_skate
.state
;
1910 skate_grind_orient( inf
, mtx
);
1911 m3x3_transpose( mtx
, mtx
);
1914 v3_sub( inf
->co
, localplayer
.rb
.co
, raw
);
1916 m3x3_mulv( mtx
, raw
, player_skate
.grind_vec
);
1917 v3_normalize( player_skate
.grind_vec
);
1918 v3_copy( inf
->dir
, player_skate
.grind_dir
);
1921 static enum skate_activity
skate_availible_grind(void){
1922 struct player_skate_state
*state
= &player_skate
.state
;
1924 if( state
->grind_cooldown
> 100 ){
1925 vg_fatal_error( "wth!\n" );
1928 /* debounces this state manager a little bit */
1929 if( state
->grind_cooldown
){
1930 state
->grind_cooldown
--;
1931 return k_skate_activity_undefined
;
1934 struct grind_info inf_back50
,
1946 joystick_state( k_srjoystick_steer
, steer
);
1948 if( state
->activity
== k_skate_activity_grind_5050
||
1949 state
->activity
== k_skate_activity_grind_back50
||
1950 state
->activity
== k_skate_activity_grind_front50
)
1952 float tilt
= steer
[1];
1954 if( fabsf(tilt
) >= 0.25f
){
1955 v3f raw
= {0.0f
,0.0f
,tilt
};
1956 m3x3_mulv( localplayer
.rb
.to_world
, raw
, raw
);
1958 float way
= tilt
* vg_signf( v3_dot( raw
, localplayer
.rb
.v
) );
1960 if( way
< 0.0f
) allow_front
= 0;
1961 else allow_back
= 0;
1965 if( state
->activity
== k_skate_activity_grind_boardslide
){
1966 res_slide
= skate_boardslide_renew( &inf_slide
);
1968 else if( state
->activity
== k_skate_activity_grind_back50
){
1969 res_back50
= skate_grind_truck_renew( 1.0f
, &inf_back50
);
1972 res_front50
= skate_grind_truck_entry( -1.0f
, &inf_front50
);
1974 else if( state
->activity
== k_skate_activity_grind_front50
){
1975 res_front50
= skate_grind_truck_renew( -1.0f
, &inf_front50
);
1978 res_back50
= skate_grind_truck_entry( 1.0f
, &inf_back50
);
1980 else if( state
->activity
== k_skate_activity_grind_5050
){
1982 res_front50
= skate_grind_truck_renew( -1.0f
, &inf_front50
);
1984 res_back50
= skate_grind_truck_renew( 1.0f
, &inf_back50
);
1987 res_slide
= skate_boardslide_entry( &inf_slide
);
1990 res_back50
= skate_grind_truck_entry( 1.0f
, &inf_back50
);
1993 res_front50
= skate_grind_truck_entry( -1.0f
, &inf_front50
);
1995 if( res_back50
!= res_front50
){
1996 int wants_to_do_that
= fabsf(steer
[1]) >= 0.25f
;
1998 res_back50
&= wants_to_do_that
;
1999 res_front50
&= wants_to_do_that
;
2003 const enum skate_activity table
[] =
2004 { /* slide | back | front */
2005 k_skate_activity_undefined
, /* 0 0 0 */
2006 k_skate_activity_grind_front50
, /* 0 0 1 */
2007 k_skate_activity_grind_back50
, /* 0 1 0 */
2008 k_skate_activity_grind_5050
, /* 0 1 1 */
2010 /* slide has priority always */
2011 k_skate_activity_grind_boardslide
, /* 1 0 0 */
2012 k_skate_activity_grind_boardslide
, /* 1 0 1 */
2013 k_skate_activity_grind_boardslide
, /* 1 1 0 */
2014 k_skate_activity_grind_boardslide
, /* 1 1 1 */
2016 , new_activity
= table
[ res_slide
<< 2 | res_back50
<< 1 | res_front50
];
2018 if( new_activity
== k_skate_activity_undefined
){
2019 if( state
->activity
>= k_skate_activity_grind_any
){
2020 state
->grind_cooldown
= 15;
2021 state
->surface_cooldown
= 10;
2024 else if( new_activity
== k_skate_activity_grind_boardslide
){
2025 skate_boardslide_apply( &inf_slide
);
2027 else if( new_activity
== k_skate_activity_grind_back50
){
2028 if( state
->activity
!= k_skate_activity_grind_back50
)
2029 skate_store_grind_vec( &inf_back50
);
2031 skate_grind_truck_apply( 1.0f
, &inf_back50
, 1.0f
);
2033 else if( new_activity
== k_skate_activity_grind_front50
){
2034 if( state
->activity
!= k_skate_activity_grind_front50
)
2035 skate_store_grind_vec( &inf_front50
);
2037 skate_grind_truck_apply( -1.0f
, &inf_front50
, 1.0f
);
2039 else if( new_activity
== k_skate_activity_grind_5050
)
2040 skate_5050_apply( &inf_front50
, &inf_back50
);
2042 return new_activity
;
2045 static void player__skate_update(void){
2046 struct player_skate_state
*state
= &player_skate
.state
;
2047 world_instance
*world
= world_current_instance();
2049 if( world
->water
.enabled
){
2050 if( localplayer
.rb
.co
[1]+0.25f
< world
->water
.height
){
2052 player__networked_sfx( k_player_subsystem_walk
, 32,
2053 k_player_walk_soundeffect_splash
,
2054 localplayer
.rb
.co
, 1.0f
);
2056 player__skate_kill_audio();
2057 player__dead_transition();
2062 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
2063 state
->activity_prev
= state
->activity
;
2065 v3_zero( normal_total
);
2067 struct board_collider
2074 enum board_collider_state
2076 k_collider_state_default
,
2077 k_collider_state_disabled
,
2078 k_collider_state_colliding
2085 { 0.0f
, 0.0f
, -k_board_length
},
2086 .radius
= k_board_radius
,
2090 { 0.0f
, 0.0f
, k_board_length
},
2091 .radius
= k_board_radius
,
2098 if( state
->activity
<= k_skate_activity_air_to_grind
){
2099 float min_dist
= 0.6f
;
2100 for( int i
=0; i
<2; i
++ ){
2102 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, wpos
);
2104 if( bh_closest_point( world
->geo_bh
, wpos
, closest
, min_dist
) != -1 ){
2105 min_dist
= vg_minf( min_dist
, v3_dist( closest
, wpos
) );
2109 float vy
= v3_dot( localplayer
.basis
[1], localplayer
.rb
.v
);
2110 vy
= vg_maxf( 0.0f
, vy
);
2112 slap
= vg_clampf( (min_dist
/0.5f
) + vy
, 0.0f
, 1.0f
)*0.3f
;
2114 state
->slap
= vg_lerpf( state
->slap
, slap
, 10.0f
*k_rb_delta
);
2116 wheels
[0].pos
[1] = state
->slap
;
2117 wheels
[1].pos
[1] = state
->slap
;
2120 const int k_wheel_count
= 2;
2122 player_skate
.substep
= k_rb_delta
;
2123 player_skate
.substep_delta
= player_skate
.substep
;
2124 player_skate
.limit_count
= 0;
2126 int substep_count
= 0;
2128 v3_zero( player_skate
.surface_picture
);
2130 int prev_contacts
[2];
2132 for( int i
=0; i
<k_wheel_count
; i
++ ){
2133 wheels
[i
].state
= k_collider_state_default
;
2134 prev_contacts
[i
] = player_skate
.wheel_contacts
[i
];
2137 /* check if we can enter or continue grind */
2138 enum skate_activity grindable_activity
= skate_availible_grind();
2139 if( grindable_activity
!= k_skate_activity_undefined
){
2140 state
->activity
= grindable_activity
;
2144 int contact_count
= 0;
2145 for( int i
=0; i
<2; i
++ ){
2147 v3_copy( localplayer
.rb
.to_world
[0], axel
);
2149 if( skate_compute_surface_alignment( wheels
[i
].pos
,
2150 wheels
[i
].colour
, normal
, axel
) )
2152 rb_effect_spring_target_vector( &localplayer
.rb
,
2153 localplayer
.rb
.to_world
[0],
2155 k_surface_spring
, k_surface_dampener
,
2156 player_skate
.substep_delta
);
2158 v3_add( normal
, player_skate
.surface_picture
,
2159 player_skate
.surface_picture
);
2161 player_skate
.wheel_contacts
[i
] = 1;
2164 player_skate
.wheel_contacts
[i
] = 0;
2167 m3x3_mulv( localplayer
.rb
.to_local
, axel
, player_skate
.truckv0
[i
] );
2170 if( state
->surface_cooldown
){
2171 state
->surface_cooldown
--;
2175 if( (prev_contacts
[0]+prev_contacts
[1] == 1) && (contact_count
== 2) ){
2176 for( int i
=0; i
<2; i
++ ){
2177 if( !prev_contacts
[i
] ){
2179 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, co
);
2180 player__networked_sfx( k_player_subsystem_skate
, 32,
2181 k_player_skate_soundeffect_tap
,
2182 localplayer
.rb
.co
, 0.75f
);
2187 if( contact_count
){
2188 state
->activity
= k_skate_activity_ground
;
2189 state
->gravity_bias
= k_gravity
;
2190 v3_normalize( player_skate
.surface_picture
);
2192 skate_apply_friction_model();
2193 skate_weight_distribute();
2196 if( state
->activity
> k_skate_activity_air_to_grind
)
2197 state
->activity
= k_skate_activity_air
;
2199 v3_zero( player_skate
.weight_distribution
);
2200 skate_apply_air_model();
2205 if( state
->activity
== k_skate_activity_grind_back50
)
2206 wheels
[1].state
= k_collider_state_disabled
;
2207 if( state
->activity
== k_skate_activity_grind_front50
)
2208 wheels
[0].state
= k_collider_state_disabled
;
2209 if( state
->activity
== k_skate_activity_grind_5050
){
2210 wheels
[0].state
= k_collider_state_disabled
;
2211 wheels
[1].state
= k_collider_state_disabled
;
2214 /* all activities */
2215 skate_apply_steering_model();
2216 skate_adjust_up_direction();
2217 skate_apply_cog_model();
2218 skate_apply_jump_model();
2219 skate_apply_grab_model();
2220 skate_apply_trick_model();
2221 skate_apply_pump_model();
2226 * Phase 0: Continous collision detection
2227 * --------------------------------------------------------------------------
2230 v3f head_wp0
, head_wp1
, start_co
;
2231 m4x3_mulv( localplayer
.rb
.to_world
, state
->head_position
, head_wp0
);
2232 v3_copy( localplayer
.rb
.co
, start_co
);
2234 /* calculate transform one step into future */
2237 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.v
, player_skate
.substep
,
2240 if( v3_length2( localplayer
.rb
.w
) > 0.0f
){
2243 v3_copy( localplayer
.rb
.w
, axis
);
2245 float mag
= v3_length( axis
);
2246 v3_divs( axis
, mag
, axis
);
2247 q_axis_angle( rotation
, axis
, mag
*player_skate
.substep
);
2248 q_mul( rotation
, localplayer
.rb
.q
, future_q
);
2249 q_normalize( future_q
);
2252 v4_copy( localplayer
.rb
.q
, future_q
);
2254 v3f future_cg
, current_cg
, cg_offset
;
2255 q_mulv( localplayer
.rb
.q
, player_skate
.weight_distribution
, current_cg
);
2256 q_mulv( future_q
, player_skate
.weight_distribution
, future_cg
);
2257 v3_sub( future_cg
, current_cg
, cg_offset
);
2259 /* calculate the minimum time we can move */
2260 float max_time
= player_skate
.substep
;
2262 for( int i
=0; i
<k_wheel_count
; i
++ ){
2263 if( wheels
[i
].state
== k_collider_state_disabled
)
2266 v3f current
, future
, r_cg
;
2268 q_mulv( future_q
, wheels
[i
].pos
, future
);
2269 v3_add( future
, future_co
, future
);
2270 v3_add( cg_offset
, future
, future
);
2272 q_mulv( localplayer
.rb
.q
, wheels
[i
].pos
, current
);
2273 v3_add( current
, localplayer
.rb
.co
, current
);
2278 float cast_radius
= wheels
[i
].radius
- k_penetration_slop
* 2.0f
;
2279 if( spherecast_world( world
, current
, future
, cast_radius
, &t
, n
,
2280 k_material_flag_walking
) != -1)
2281 max_time
= vg_minf( max_time
, t
* player_skate
.substep
);
2284 /* clamp to a fraction of delta, to prevent locking */
2285 float rate_lock
= substep_count
;
2286 rate_lock
*= k_rb_delta
* 0.1f
;
2287 rate_lock
*= rate_lock
;
2289 max_time
= vg_maxf( max_time
, rate_lock
);
2290 player_skate
.substep_delta
= max_time
;
2293 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.v
,
2294 player_skate
.substep_delta
, localplayer
.rb
.co
);
2295 if( v3_length2( localplayer
.rb
.w
) > 0.0f
){
2298 v3_copy( localplayer
.rb
.w
, axis
);
2300 float mag
= v3_length( axis
);
2301 v3_divs( axis
, mag
, axis
);
2302 q_axis_angle( rotation
, axis
, mag
*player_skate
.substep_delta
);
2303 q_mul( rotation
, localplayer
.rb
.q
, localplayer
.rb
.q
);
2304 q_normalize( localplayer
.rb
.q
);
2306 q_mulv( localplayer
.rb
.q
, player_skate
.weight_distribution
, future_cg
);
2307 v3_sub( current_cg
, future_cg
, cg_offset
);
2308 v3_add( localplayer
.rb
.co
, cg_offset
, localplayer
.rb
.co
);
2311 rb_update_transform( &localplayer
.rb
);
2312 v3_muladds( localplayer
.rb
.v
, localplayer
.basis
[1],
2313 -state
->gravity_bias
* player_skate
.substep_delta
,
2316 player_skate
.substep
-= player_skate
.substep_delta
;
2318 rb_ct manifold
[128];
2319 int manifold_len
= 0;
2321 * Phase -1: head detection
2322 * --------------------------------------------------------------------------
2324 m4x3_mulv( localplayer
.rb
.to_world
, state
->head_position
, head_wp1
);
2328 if( (v3_dist2( head_wp0
, head_wp1
) > 0.001f
) &&
2329 (spherecast_world( world
, head_wp0
, head_wp1
, 0.2f
, &t
, n
,
2330 k_material_flag_walking
) != -1) )
2332 v3_lerp( start_co
, localplayer
.rb
.co
, t
, localplayer
.rb
.co
);
2333 rb_update_transform( &localplayer
.rb
);
2335 player__skate_kill_audio();
2336 player__dead_transition();
2341 * Phase 1: Regular collision detection
2342 * --------------------------------------------------------------------------
2345 for( int i
=0; i
<k_wheel_count
; i
++ ){
2346 if( wheels
[i
].state
== k_collider_state_disabled
)
2350 m3x3_identity( mtx
);
2351 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, mtx
[3] );
2353 rb_sphere collider
= { .radius
= wheels
[i
].radius
};
2355 rb_ct
*man
= &manifold
[ manifold_len
];
2357 int l
= skate_collide_smooth( mtx
, &collider
, man
);
2359 wheels
[i
].state
= k_collider_state_colliding
;
2364 float grind_radius
= k_board_radius
* 0.75f
;
2365 rb_capsule capsule
= { .height
= (k_board_length
+0.2f
)*2.0f
,
2366 .radius
=grind_radius
};
2368 v3_muls( localplayer
.rb
.to_world
[0], 1.0f
, mtx
[0] );
2369 v3_muls( localplayer
.rb
.to_world
[2], -1.0f
, mtx
[1] );
2370 v3_muls( localplayer
.rb
.to_world
[1], 1.0f
, mtx
[2] );
2371 v3_muladds( localplayer
.rb
.to_world
[3], localplayer
.rb
.to_world
[1],
2372 grind_radius
+ k_board_radius
*0.25f
+state
->slap
, mtx
[3] );
2374 rb_ct
*cman
= &manifold
[manifold_len
];
2376 int l
= rb_capsule__scene( mtx
, &capsule
, NULL
, &world
->rb_geo
.inf
.scene
,
2377 cman
, k_material_flag_walking
);
2380 for( int i
=0; i
<l
; i
++ )
2381 cman
[l
].type
= k_contact_type_edge
;
2382 rb_manifold_filter_joint_edges( cman
, l
, 0.03f
);
2383 l
= rb_manifold_apply_filtered( cman
, l
);
2388 vg_line_capsule( mtx
, capsule
.radius
, capsule
.height
, VG__WHITE
);
2391 if( state
->activity
>= k_skate_activity_grind_any
){
2392 for( int i
=0; i
<player_skate
.limit_count
; i
++ ){
2393 struct grind_limit
*limit
= &player_skate
.limits
[i
];
2394 rb_ct
*ct
= &manifold
[ manifold_len
++ ];
2395 m4x3_mulv( localplayer
.rb
.to_world
, limit
->ra
, ct
->co
);
2396 m3x3_mulv( localplayer
.rb
.to_world
, limit
->n
, ct
->n
);
2398 ct
->type
= k_contact_type_default
;
2404 * --------------------------------------------------------------------------
2409 m4x3_mulv( localplayer
.rb
.to_world
,
2410 player_skate
.weight_distribution
, world_cog
);
2411 vg_line_point( world_cog
, 0.02f
, VG__BLACK
);
2413 for( int i
=0; i
<manifold_len
; i
++ ){
2414 rb_prepare_contact( &manifold
[i
], player_skate
.substep_delta
);
2415 rb_debug_contact( &manifold
[i
] );
2418 /* yes, we are currently rebuilding mass matrices every frame. too bad! */
2419 v3f extent
= { k_board_width
, 0.1f
, k_board_length
};
2420 float ex2
= k_board_interia
*extent
[0]*extent
[0],
2421 ey2
= k_board_interia
*extent
[1]*extent
[1],
2422 ez2
= k_board_interia
*extent
[2]*extent
[2];
2424 float mass
= 2.0f
* (extent
[0]*extent
[1]*extent
[2]);
2425 float inv_mass
= 1.0f
/mass
;
2428 I
[0] = ((1.0f
/12.0f
) * mass
* (ey2
+ez2
));
2429 I
[1] = ((1.0f
/12.0f
) * mass
* (ex2
+ez2
));
2430 I
[2] = ((1.0f
/12.0f
) * mass
* (ex2
+ey2
));
2433 m3x3_identity( iI
);
2440 m3x3_mul( iI
, localplayer
.rb
.to_local
, iIw
);
2441 m3x3_mul( localplayer
.rb
.to_world
, iIw
, iIw
);
2443 for( int j
=0; j
<10; j
++ ){
2444 for( int i
=0; i
<manifold_len
; i
++ ){
2446 * regular dance; calculate velocity & total mass, apply impulse.
2449 struct contact
*ct
= &manifold
[i
];
2452 v3_sub( ct
->co
, world_cog
, delta
);
2453 v3_cross( localplayer
.rb
.w
, delta
, rv
);
2454 v3_add( localplayer
.rb
.v
, rv
, rv
);
2457 v3_cross( delta
, ct
->n
, raCn
);
2460 m3x3_mulv( iIw
, raCn
, raCnI
);
2462 float normal_mass
= 1.0f
/ (inv_mass
+ v3_dot(raCn
,raCnI
)),
2463 vn
= v3_dot( rv
, ct
->n
),
2464 lambda
= normal_mass
* ( -vn
);
2466 float temp
= ct
->norm_impulse
;
2467 ct
->norm_impulse
= vg_maxf( temp
+ lambda
, 0.0f
);
2468 lambda
= ct
->norm_impulse
- temp
;
2471 v3_muls( ct
->n
, lambda
, impulse
);
2473 v3_muladds( normal_total
, impulse
, inv_mass
, normal_total
);
2474 v3_muladds( localplayer
.rb
.v
, impulse
, inv_mass
, localplayer
.rb
.v
);
2475 v3_cross( delta
, impulse
, impulse
);
2476 m3x3_mulv( iIw
, impulse
, impulse
);
2477 v3_add( impulse
, localplayer
.rb
.w
, localplayer
.rb
.w
);
2479 v3_cross( localplayer
.rb
.w
, delta
, rv
);
2480 v3_add( localplayer
.rb
.v
, rv
, rv
);
2481 vn
= v3_dot( rv
, ct
->n
);
2486 rb_depenetrate( manifold
, manifold_len
, dt
);
2487 v3_add( dt
, localplayer
.rb
.co
, localplayer
.rb
.co
);
2488 rb_update_transform( &localplayer
.rb
);
2492 if( player_skate
.substep
>= 0.0001f
)
2493 goto begin_collision
; /* again! */
2496 * End of collision and dynamics routine
2497 * --------------------------------------------------------------------------
2500 f32 nforce
= v3_length(normal_total
);
2501 if( nforce
> 4.0f
){
2502 if( nforce
> 17.6f
){
2503 v3_muladds( localplayer
.rb
.v
, normal_total
, -1.0f
, localplayer
.rb
.v
);
2504 player__dead_transition();
2505 player__skate_kill_audio();
2509 f32 amt
= k_cam_punch
;
2510 if( localplayer
.cam_control
.camera_mode
== k_cam_firstperson
){
2514 v3_muladds( localplayer
.cam_land_punch_v
, normal_total
, amt
,
2515 localplayer
.cam_land_punch_v
);
2518 player_skate
.surface
= k_surface_prop_concrete
;
2520 for( int i
=0; i
<manifold_len
; i
++ ){
2521 rb_ct
*ct
= &manifold
[i
];
2522 struct world_surface
*surf
= world_contact_surface( world
, ct
);
2524 if( surf
->info
.surface_prop
> player_skate
.surface
)
2525 player_skate
.surface
= surf
->info
.surface_prop
;
2528 for( int i
=0; i
<k_wheel_count
; i
++ ){
2530 m3x3_copy( localplayer
.rb
.to_world
, mtx
);
2531 m4x3_mulv( localplayer
.rb
.to_world
, wheels
[i
].pos
, mtx
[3] );
2532 vg_line_sphere( mtx
, wheels
[i
].radius
,
2533 (u32
[]){ VG__WHITE
, VG__BLACK
,
2534 wheels
[i
].colour
}[ wheels
[i
].state
]);
2538 vg_line_point( state
->cog
, 0.02f
, VG__WHITE
);
2540 u32 id
= world_intersect_gates( world
, localplayer
.rb
.co
, state
->prev_pos
);
2543 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, mdl_entity_id_id(id
) );
2545 m4x3_mulv( gate
->transport
, localplayer
.rb
.co
, localplayer
.rb
.co
);
2546 m3x3_mulv( gate
->transport
, localplayer
.rb
.v
, localplayer
.rb
.v
);
2547 m4x3_mulv( gate
->transport
, state
->cog
, state
->cog
);
2548 m3x3_mulv( gate
->transport
, state
->cog_v
, state
->cog_v
);
2549 m3x3_mulv( gate
->transport
, state
->throw_v
, state
->throw_v
);
2550 m3x3_mulv( gate
->transport
, state
->head_position
,
2551 state
->head_position
);
2552 m3x3_mulv( gate
->transport
, state
->up_dir
, state
->up_dir
);
2554 v4f transport_rotation
;
2555 m3x3_q( gate
->transport
, transport_rotation
);
2556 q_mul( transport_rotation
, localplayer
.rb
.q
, localplayer
.rb
.q
);
2557 q_mul( transport_rotation
, state
->smoothed_rotation
,
2558 state
->smoothed_rotation
);
2559 rb_update_transform( &localplayer
.rb
);
2560 player__pass_gate( id
);
2563 /* FIXME: Rate limit */
2564 static int stick_frames
= 0;
2566 if( state
->activity
>= k_skate_activity_ground
)
2571 if( stick_frames
> 5 ) stick_frames
= 5;
2573 if( stick_frames
== 4 ){
2574 if( state
->activity
== k_skate_activity_ground
){
2575 if( (fabsf(state
->slip
) > 0.75f
) ){
2576 player__networked_sfx( k_player_subsystem_skate
, 128,
2577 k_player_skate_soundeffect_land_bad
,
2578 localplayer
.rb
.co
, 0.6f
);
2581 player__networked_sfx( k_player_subsystem_skate
, 128,
2582 k_player_skate_soundeffect_land_good
,
2583 localplayer
.rb
.co
, 1.0f
);
2586 else if( player_skate
.surface
== k_surface_prop_metal
){
2587 player__networked_sfx( k_player_subsystem_skate
, 128,
2588 k_player_skate_soundeffect_grind_metal
,
2589 localplayer
.rb
.co
, 1.0f
);
2592 player__networked_sfx( k_player_subsystem_skate
, 128,
2593 k_player_skate_soundeffect_grind_wood
,
2594 localplayer
.rb
.co
, 1.0f
);
2596 } else if( stick_frames
== 0 ){
2597 /* TODO: EXIT SOUNDS */
2601 static void player__skate_im_gui(void){
2602 struct player_skate_state
*state
= &player_skate
.state
;
2603 player__debugtext( 1, "V: %5.2f %5.2f %5.2f",localplayer
.rb
.v
[0],
2604 localplayer
.rb
.v
[1],
2605 localplayer
.rb
.v
[2] );
2606 player__debugtext( 1, "CO: %5.2f %5.2f %5.2f",localplayer
.rb
.co
[0],
2607 localplayer
.rb
.co
[1],
2608 localplayer
.rb
.co
[2] );
2609 player__debugtext( 1, "W: %5.2f %5.2f %5.2f",localplayer
.rb
.w
[0],
2610 localplayer
.rb
.w
[1],
2611 localplayer
.rb
.w
[2] );
2613 const char *activity_txt
[] = {
2617 "undefined (INVALID)",
2618 "grind_any (INVALID)",
2620 "grind_metallic (INVALID)",
2626 player__debugtext( 1, "activity: %s", activity_txt
[state
->activity
] );
2628 player__debugtext( 1, "steer_s: %5.2f %5.2f [%.2f %.2f]",
2629 state
->steerx_s
, state
->steery_s
,
2630 k_steer_ground
, k_steer_air
);
2632 player__debugtext( 1, "flip: %.4f %.4f", state
->flip_rate
,
2634 player__debugtext( 1, "trickv: %.2f %.2f %.2f",
2635 state
->trick_vel
[0],
2636 state
->trick_vel
[1],
2637 state
->trick_vel
[2] );
2638 player__debugtext( 1, "tricke: %.2f %.2f %.2f",
2639 state
->trick_euler
[0],
2640 state
->trick_euler
[1],
2641 state
->trick_euler
[2] );
2644 static void player__skate_animate(void){
2645 struct player_skate_state
*state
= &player_skate
.state
;
2646 struct player_skate_animator
*animator
= &player_skate
.animator
;
2649 float kheight
= 2.0f
,
2652 v3_zero( animator
->offset
);
2654 v3f cog_local
, cog_ideal
;
2655 m4x3_mulv( localplayer
.rb
.to_local
, state
->cog
, cog_local
);
2657 v3_copy( state
->up_dir
, cog_ideal
);
2658 v3_normalize( cog_ideal
);
2659 m3x3_mulv( localplayer
.rb
.to_local
, cog_ideal
, cog_ideal
);
2661 v3_sub( cog_ideal
, cog_local
, animator
->offset
);
2663 v3_muls( animator
->offset
, 4.0f
, animator
->offset
);
2664 animator
->offset
[1] *= -1.0f
;
2666 float curspeed
= v3_length( localplayer
.rb
.v
),
2667 kickspeed
= vg_clampf( curspeed
*(1.0f
/40.0f
), 0.0f
, 1.0f
),
2668 kicks
= (vg_randf64()-0.5f
)*2.0f
*kickspeed
,
2669 sign
= vg_signf( kicks
);
2671 animator
->wobble
[0] = vg_lerpf( animator
->wobble
[0], kicks
*kicks
*sign
,
2672 6.0f
*vg
.time_delta
);
2673 animator
->wobble
[1] = vg_lerpf( animator
->wobble
[1], animator
->wobble
[0],
2674 2.4f
*vg
.time_delta
);
2676 animator
->offset
[0] *= 0.26f
;
2677 animator
->offset
[0] += animator
->wobble
[1]*3.0f
;
2679 animator
->offset
[1] *= -0.3f
;
2680 animator
->offset
[2] *= 0.01f
;
2682 animator
->offset
[0]=vg_clampf(animator
->offset
[0],-0.8f
,0.8f
)*
2683 (1.0f
-fabsf(animator
->slide
)*0.9f
);
2684 animator
->offset
[1]=vg_clampf(animator
->offset
[1],-0.5f
,0.0f
);
2687 v3_mul( animator
->offset
, (v3f
){1.0f
,0.3f
,1.0f
}, cam_offset
);
2688 v3_copy( cam_offset
, localplayer
.cam_control
.tpv_offset_extra
);
2690 /* localized vectors */
2691 m4x3_mulv( localplayer
.rb
.to_local
, state
->cog
, animator
->local_cog
);
2694 * Animation blending
2695 * ===========================================
2700 float desired
= 0.0f
;
2701 if( state
->activity
== k_skate_activity_ground
)
2702 desired
= vg_clampf( fabsf( state
->slip
), 0.0f
, 1.0f
);
2704 animator
->slide
= vg_lerpf( animator
->slide
, desired
, 2.4f
*vg
.time_delta
);
2707 /* movement information */
2708 int iair
= state
->activity
<= k_skate_activity_air_to_grind
;
2710 float dirz
= state
->reverse
> 0.0f
? 0.0f
: 1.0f
,
2711 dirx
= state
->slip
< 0.0f
? 0.0f
: 1.0f
,
2712 fly
= iair
? 1.0f
: 0.0f
,
2713 wdist
= player_skate
.weight_distribution
[2] / k_board_length
;
2715 if( state
->activity
>= k_skate_activity_grind_any
)
2718 animator
->z
= vg_lerpf( animator
->z
, dirz
, 2.4f
*vg
.time_delta
);
2719 animator
->x
= vg_lerpf( animator
->x
, dirx
, 0.6f
*vg
.time_delta
);
2720 animator
->fly
= vg_lerpf( animator
->fly
, fly
, 3.4f
*vg
.time_delta
);
2721 animator
->weight
= vg_lerpf( animator
->weight
, wdist
, 9.0f
*vg
.time_delta
);
2723 float stand
= 1.0f
- vg_clampf( curspeed
* 0.03f
, 0.0f
, 1.0f
);
2724 animator
->stand
= vg_lerpf( animator
->stand
, stand
, 6.0f
*vg
.time_delta
);
2725 animator
->reverse
= state
->reverse
;
2727 if( fabsf(state
->slip
) > 0.3f
){
2728 f32 slide_x
= v3_dot(localplayer
.rb
.v
, localplayer
.rb
.to_world
[0]);
2729 state
->delayed_slip_dir
= vg_signf(slide_x
);
2733 f32 grind
=state
->activity
>= k_skate_activity_grind_any
? 1.0f
: 0.0f
;
2734 animator
->grind
= vg_lerpf( animator
->grind
, grind
, 5.0f
*vg
.time_delta
);
2736 f32 grind_frame
= 0.5f
;
2738 if( state
->activity
== k_skate_activity_grind_front50
)
2740 else if( state
->activity
== k_skate_activity_grind_back50
)
2743 animator
->grind_balance
= vg_lerpf( animator
->grind_balance
, grind_frame
,
2744 5.0f
*vg
.time_delta
);
2747 animator
->push_time
= vg
.time
- state
->start_push
;
2748 animator
->push
= vg_lerpf( animator
->push
,
2749 (vg
.time
- state
->cur_push
) < 0.125,
2750 6.0f
*vg
.time_delta
);
2753 animator
->jump_charge
= state
->jump_charge
;
2754 animator
->jump
= vg_lerpf( animator
->jump
, animator
->jump_charge
,
2755 8.4f
*vg
.time_delta
);
2758 animator
->jump_dir
= state
->jump_dir
;
2759 f32 jump_start_frame
= 14.0f
/30.0f
;
2760 animator
->jump_time
= animator
->jump_charge
* jump_start_frame
;
2761 f32 jump_frame
= (vg
.time
- state
->jump_time
) + jump_start_frame
;
2762 if( jump_frame
>= jump_start_frame
&& jump_frame
<= (40.0f
/30.0f
) )
2763 animator
->jump_time
= jump_frame
;
2766 float jump_t
= vg
.time
-state
->jump_time
;
2769 float extra
= h
*exp(1.0-h
) * (state
->jump_dir
?1.0f
:-1.0f
);
2770 extra
*= state
->slap
* 4.0f
;
2772 v3_add( state
->trick_euler
, state
->trick_residuald
,
2773 animator
->board_euler
);
2774 v3_muls( animator
->board_euler
, VG_TAUf
, animator
->board_euler
);
2776 animator
->board_euler
[0] *= 0.5f
;
2777 animator
->board_euler
[1] += extra
;
2778 animator
->trick_type
= state
->trick_type
;
2781 f32 lean1
, lean2
= animator
->steer
[0] * animator
->reverse
* -0.36f
,
2784 lean1
= animator
->slide
* animator
->delayed_slip_dir
;
2785 if( fabsf(lean1
)>fabsf(lean2
) ) lean
= lean1
;
2788 if( ((int)roundf(animator
->board_euler
[0]/VG_PIf
)) % 2 ) lean
= -lean
;
2789 lean
= vg_clampf( lean
, -1.0f
, 1.0f
);
2790 animator
->board_lean
=
2791 vg_lerpf(animator
->board_lean
, lean
, vg
.time_delta
*18.0f
);
2793 /* feet placement */
2794 struct player_board
*board
=
2795 addon_cache_item_if_loaded( k_addon_type_board
,
2796 localplayer
.board_view_slot
);
2798 if( animator
->weight
> 0.0f
){
2799 animator
->foot_offset
[0] =
2800 board
->truck_positions
[k_board_truck_back
][2]+0.3f
;
2803 animator
->foot_offset
[1] =
2804 board
->truck_positions
[k_board_truck_front
][2]-0.3f
;
2808 f32 slapm
= vg_maxf( 1.0f
-v3_length2( state
->trick_vel
), 0.0f
);
2809 animator
->slap
= state
->slap
;
2810 animator
->subslap
= vg_lerpf( animator
->subslap
, slapm
,
2811 vg
.time_delta
*10.0f
);
2813 f32 l
= ((state
->activity
< k_skate_activity_ground
) &&
2814 v3_length2(state
->trick_vel
) > 0.1f
)? 1: 0;
2815 animator
->trick_foot
= vg_lerpf( animator
->trick_foot
, l
,
2816 8.4f
*vg
.time_delta
);
2820 joystick_state( k_srjoystick_grab
, grab_input
);
2821 v2_add( state
->grab_mouse_delta
, grab_input
, grab_input
);
2823 if( v2_length2( grab_input
) <= 0.001f
) grab_input
[0] = -1.0f
;
2824 else v2_normalize_clamp( grab_input
);
2825 v2_lerp( animator
->grab
, grab_input
, 2.4f
*vg
.time_delta
, animator
->grab
);
2826 animator
->grabbing
= state
->grabbing
;
2829 joystick_state( k_srjoystick_steer
, animator
->steer
);
2831 animator
->airdir
= vg_lerpf( animator
->airdir
, -animator
->steer
[0],
2832 2.4f
*vg
.time_delta
);
2836 if( (state
->activity
<= k_skate_activity_air_to_grind
) &&
2837 (fabsf(state
->flip_rate
) > 0.01f
) ){
2838 float substep
= vg
.time_fixed_extrapolate
;
2839 float t
= state
->flip_time
+state
->flip_rate
*substep
*k_rb_delta
;
2840 sign
= vg_signf( t
);
2842 t
= 1.0f
- vg_minf( 1.0f
, fabsf( t
* 1.1f
) );
2843 t
= sign
* (1.0f
-t
*t
);
2845 f32 angle
= vg_clampf( t
, -1.0f
, 1.0f
) * VG_TAUf
,
2846 distm
= state
->land_dist
* fabsf(state
->flip_rate
) * 3.0f
,
2847 blend
= vg_clampf( 1.0f
-distm
, 0.0f
, 1.0f
);
2848 angle
= vg_lerpf( angle
, vg_signf(state
->flip_rate
)*VG_TAUf
, blend
);
2849 q_axis_angle( animator
->qflip
, state
->flip_axis
, angle
);
2852 q_identity( animator
->qflip
);
2854 /* counter-rotation */
2855 if( v3_length2( state
->up_dir
) > 0.001f
){
2856 v4_lerp( state
->smoothed_rotation
, localplayer
.rb
.q
,
2857 2.0f
*vg
.time_frame_delta
,
2858 state
->smoothed_rotation
);
2859 q_normalize( state
->smoothed_rotation
);
2861 v3f yaw_smooth
= {1.0f
,0.0f
,0.0f
};
2862 q_mulv( state
->smoothed_rotation
, yaw_smooth
, yaw_smooth
);
2863 m3x3_mulv( localplayer
.rb
.to_local
, yaw_smooth
, yaw_smooth
);
2864 yaw_smooth
[1] = 0.0f
;
2865 v3_normalize( yaw_smooth
);
2867 f32 yaw_counter_rotate
= yaw_smooth
[0];
2868 yaw_counter_rotate
= vg_maxf( 0.7f
, yaw_counter_rotate
);
2869 yaw_counter_rotate
= acosf( yaw_counter_rotate
);
2870 yaw_counter_rotate
*= 1.0f
-animator
->fly
;
2873 m3x3_mulv( localplayer
.rb
.to_local
, state
->up_dir
, ndir
);
2874 v3_normalize( ndir
);
2876 v3f up
= { 0.0f
, 1.0f
, 0.0f
};
2877 float a
= v3_dot( ndir
, up
);
2878 a
= acosf( vg_clampf( a
, -1.0f
, 1.0f
) );
2881 v4f qcounteryaw
, qfixup
;
2883 v3_cross( up
, ndir
, axis
);
2884 q_axis_angle( qfixup
, axis
, a
*2.0f
);
2886 v3_cross( (v3f
){1.0f
,0.0f
,0.0f
}, yaw_smooth
, axis
);
2887 q_axis_angle( qcounteryaw
, axis
, yaw_counter_rotate
);
2889 q_mul( qcounteryaw
, qfixup
, animator
->qfixuptotal
);
2890 q_normalize( animator
->qfixuptotal
);
2893 m3x3_mulv( localplayer
.rb
.to_world
, up
, p1
);
2894 m3x3_mulv( localplayer
.rb
.to_world
, ndir
, p2
);
2896 vg_line_arrow( localplayer
.rb
.co
, p1
, 0.5f
, VG__PINK
);
2897 vg_line_arrow( localplayer
.rb
.co
, p2
, 0.5f
, VG__PINK
);
2899 else q_identity( animator
->qfixuptotal
);
2900 rb_extrapolate( &localplayer
.rb
, animator
->root_co
, animator
->root_q
);
2903 static void player__skate_pose( void *_animator
, player_pose
*pose
){
2904 struct skeleton
*sk
= &localplayer
.skeleton
;
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
[localplayer
.id_board
-1],
2987 *kf_foot_l
= &pose
->keyframes
[localplayer
.id_ik_foot_l
-1],
2988 *kf_foot_r
= &pose
->keyframes
[localplayer
.id_ik_foot_r
-1],
2989 *kf_knee_l
= &pose
->keyframes
[localplayer
.id_ik_knee_l
-1],
2990 *kf_knee_r
= &pose
->keyframes
[localplayer
.id_ik_knee_r
-1],
2991 *kf_hip
= &pose
->keyframes
[localplayer
.id_hip
-1],
2992 *kf_wheels
[] = { &pose
->keyframes
[localplayer
.id_wheel_r
-1],
2993 &pose
->keyframes
[localplayer
.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
[] = { localplayer
.id_hip
,
3010 localplayer
.id_ik_hand_l
,
3011 localplayer
.id_ik_hand_r
,
3012 localplayer
.id_ik_elbow_l
,
3013 localplayer
.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( sk
->bones
[localplayer
.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
, 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
);
3096 *kf_head
= &pose
->keyframes
[localplayer
.id_head
-1],
3097 *kf_elbow_l
= &pose
->keyframes
[localplayer
.id_ik_elbow_l
-1],
3098 *kf_elbow_r
= &pose
->keyframes
[localplayer
.id_ik_elbow_r
-1],
3099 *kf_hand_l
= &pose
->keyframes
[localplayer
.id_ik_hand_l
-1],
3100 *kf_hand_r
= &pose
->keyframes
[localplayer
.id_ik_hand_r
-1];
3102 float warble
= perlin1d( vg
.time
, 2.0f
, 2, 300 );
3103 warble
*= vg_maxf(animator
->grind
, fabsf(animator
->weight
)) * 0.3f
;
3106 q_axis_angle( qrot
, (v3f
){0.8f
,0.7f
,0.6f
}, warble
);
3108 v3f origin
= {0.0f
,0.2f
,0.0f
};
3109 keyframe_rotate_around( kf_hand_l
, origin
,
3110 sk
->bones
[localplayer
.id_ik_hand_l
].co
, qrot
);
3111 keyframe_rotate_around( kf_hand_r
, origin
,
3112 sk
->bones
[localplayer
.id_ik_hand_r
].co
, qrot
);
3113 keyframe_rotate_around( kf_hip
, origin
,
3114 sk
->bones
[localplayer
.id_hip
].co
, qrot
);
3115 keyframe_rotate_around( kf_elbow_r
, origin
,
3116 sk
->bones
[localplayer
.id_ik_elbow_r
].co
, qrot
);
3117 keyframe_rotate_around( kf_elbow_l
, origin
,
3118 sk
->bones
[localplayer
.id_ik_elbow_l
].co
, qrot
);
3120 q_inv( qrot
, qrot
);
3121 q_mul( qrot
, kf_head
->q
, kf_head
->q
);
3122 q_normalize( kf_head
->q
);
3126 static void player__skate_post_animate(void){
3127 struct player_skate_state
*state
= &player_skate
.state
;
3128 localplayer
.cam_velocity_influence
= 1.0f
;
3130 v3f head
= { 0.0f
, 1.8f
, 0.0f
};
3131 m4x3_mulv( localplayer
.final_mtx
[ localplayer
.id_head
],
3132 head
, state
->head_position
);
3133 m4x3_mulv( localplayer
.rb
.to_local
,
3134 state
->head_position
, state
->head_position
);
3137 static void player__skate_reset_animator(void){
3138 struct player_skate_state
*state
= &player_skate
.state
;
3140 memset( &player_skate
.animator
, 0, sizeof(player_skate
.animator
) );
3142 if( state
->activity
<= k_skate_activity_air_to_grind
)
3143 player_skate
.animator
.fly
= 1.0f
;
3145 player_skate
.animator
.fly
= 0.0f
;
3148 static void player__skate_clear_mechanics(void){
3149 struct player_skate_state
*state
= &player_skate
.state
;
3150 state
->jump_charge
= 0.0f
;
3151 state
->charging_jump
= 0;
3152 state
->jump_dir
= 0;
3153 v3_zero( state
->flip_axis
);
3154 state
->flip_time
= 0.0f
;
3155 state
->flip_rate
= 0.0f
;
3156 state
->reverse
= 0.0f
;
3158 state
->grabbing
= 0.0f
;
3159 v2_zero( state
->grab_mouse_delta
);
3161 state
->jump_time
= 0.0;
3162 state
->start_push
= 0.0;
3163 state
->cur_push
= 0.0;
3164 state
->air_start
= 0.0;
3166 v3_zero( state
->air_init_v
);
3167 v3_zero( state
->air_init_co
);
3169 state
->gravity_bias
= k_gravity
;
3170 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
3171 v4_copy( localplayer
.rb
.q
, state
->smoothed_rotation
);
3172 v3_zero( state
->throw_v
);
3173 v3_zero( state
->trick_vel
);
3174 v3_zero( state
->trick_euler
);
3175 v3_zero( state
->cog_v
);
3176 state
->grind_cooldown
= 0;
3177 state
->surface_cooldown
= 0;
3178 v3_muladds( localplayer
.rb
.co
, localplayer
.rb
.to_world
[1], 1.0f
, state
->cog
);
3179 v3_copy( localplayer
.rb
.to_world
[1], state
->up_dir
);
3180 v3_copy( localplayer
.rb
.to_world
[1], player_skate
.surface_picture
);
3181 v3_copy( localplayer
.rb
.co
, state
->prev_pos
);
3182 v3_zero( player_skate
.weight_distribution
);
3185 static void player__skate_reset( ent_spawn
*rp
){
3186 struct player_skate_state
*state
= &player_skate
.state
;
3187 v3_zero( localplayer
.rb
.v
);
3188 v4_copy( rp
->transform
.q
, localplayer
.rb
.q
);
3190 state
->activity
= k_skate_activity_air
;
3191 state
->activity_prev
= k_skate_activity_air
;
3193 player__skate_clear_mechanics();
3194 player__skate_reset_animator();
3196 v3_zero( state
->head_position
);
3197 state
->head_position
[1] = 1.8f
;
3200 #include "network_compression.h"
3202 static void player__skate_animator_exchange( bitpack_ctx
*ctx
, void *data
){
3203 struct player_skate_animator
*animator
= data
;
3205 bitpack_qv3f( ctx
, 24, -1024.0f
, 1024.0f
, animator
->root_co
);
3206 bitpack_qquat( ctx
, animator
->root_q
);
3208 bitpack_qv3f( ctx
, 8, -1.0f
, 1.0f
, animator
->offset
);
3209 bitpack_qv3f( ctx
, 8, -1.0f
, 1.0f
, animator
->local_cog
);
3210 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->slide
);
3211 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->z
);
3212 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->x
);
3214 /* these could likely be pressed down into single bits if needed */
3215 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->fly
);
3216 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grind
);
3217 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->stand
);
3218 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->push
);
3219 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->jump
); /*??*/
3220 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->jump_charge
); /*??*/
3222 /* just the sign bit? */
3223 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->reverse
);
3224 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->delayed_slip_dir
);
3225 bitpack_bytes( ctx
, 1, &animator
->jump_dir
);
3226 bitpack_bytes( ctx
, 1, &animator
->trick_type
);
3228 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grind_balance
);
3229 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->airdir
);
3230 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->weight
);
3231 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->trick_foot
);
3232 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->slap
);
3233 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->subslap
);
3234 bitpack_qf32( ctx
, 8, 0.0f
, 1.0f
, &animator
->grabbing
);
3236 /* animator->wobble is ommited */
3238 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->foot_offset
);
3239 bitpack_qquat( ctx
, animator
->qfixuptotal
);
3240 bitpack_qquat( ctx
, animator
->qflip
);
3242 bitpack_qv3f( ctx
, 16, -100.0f
, 100.0f
, animator
->board_euler
);
3243 bitpack_qf32( ctx
, 8, -1.0f
, 1.0f
, &animator
->board_lean
);
3244 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->steer
);
3245 bitpack_qv2f( ctx
, 8, -1.0f
, 1.0f
, animator
->grab
);
3247 bitpack_qf32( ctx
, 16, 0.0f
, 120.0f
, &animator
->push_time
);
3248 bitpack_qf32( ctx
, 16, 0.0f
, 120.0f
, &animator
->jump_time
);
3251 static void player__skate_sfx_oneshot( u8 id
, v3f pos
, f32 volume
){
3254 if( id
== k_player_skate_soundeffect_jump
){
3255 audio_oneshot_3d( &audio_jumps
[vg_randu32()%2], pos
, 40.0f
, volume
);
3257 else if( id
== k_player_skate_soundeffect_tap
){
3258 audio_oneshot_3d( &audio_taps
[vg_randu32()%4], pos
, 40.0f
, volume
);
3260 else if( id
== k_player_skate_soundeffect_land_good
){
3261 audio_oneshot_3d( &audio_lands
[vg_randu32()%3], pos
, 40.0f
, volume
);
3263 else if( id
== k_player_skate_soundeffect_land_bad
){
3264 audio_oneshot_3d( &audio_lands
[vg_randu32()%2+3], pos
, 40.0f
, volume
);
3266 else if( id
== k_player_skate_soundeffect_grind_metal
){
3267 audio_oneshot_3d( &audio_board
[3], pos
, 40.0f
, volume
);
3269 else if( id
== k_player_skate_soundeffect_grind_wood
){
3270 audio_oneshot_3d( &audio_board
[8], pos
, 40.0f
, volume
);
3276 #endif /* PLAYER_SKATE_C */