#include "ent_skateshop.h"
#include "addon.h"
+#include "ent_tornado.c"
+#include "vg/vg_rigidbody.h"
+#include "scene_rigidbody.h"
+#include "player_glide.h"
+
static void player__skate_bind(void){
struct skeleton *sk = &localplayer.skeleton;
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
struct { struct skeleton_anim **anim; const char *name; }
bindings[] = {
* Does collision detection on a sphere vs world, and applies some smoothing
* filters to the manifold afterwards
*/
-static int skate_collide_smooth( m4x3f mtx, rb_sphere *sphere, rb_ct *man ){
+static int skate_collide_smooth( m4x3f mtx, f32 r, rb_ct *man ){
world_instance *world = world_current_instance();
int len = 0;
- len = rb_sphere__scene( mtx, sphere, NULL, &world->rb_geo.inf.scene, man,
+ len = rb_sphere__scene( mtx, r, NULL, world->geo_bh, man,
k_material_flag_walking );
for( int i=0; i<len; i++ ){
inf->gravity = gravity;
v3_copy( launch_v, inf->v );
+ /* initial conditions */
+ v3f v;
+ v3_copy( launch_v, v );
+ v3_copy( launch_co, co1 );
+
for( int i=1; i<=50; i++ ){
- float t = (float)i * k_trace_delta;
+ f32 t = (f32)i * k_trace_delta;
+
+ /* integrate forces */
+ v3f a;
+ ent_tornado_forces( co1, v, a );
+ a[1] -= gravity;
- v3_muls( launch_v, t, co1 );
- co1[1] += -0.5f * gravity * t*t;
- v3_add( launch_co, co1, co1 );
+ /* position */
+ v3_muladds( co1, v, k_trace_delta, co1 );
+ v3_muladds( co1, a, 0.5f*k_trace_delta*k_trace_delta, co1 );
- float launch_vy = launch_v[1];
+ /* velocity */
+ v3_muladds( v, a, k_trace_delta, v );
int search_for_grind = 1;
if( grind_located ) search_for_grind = 0;
- if( launch_vy - gravity*t > 0.0f ) search_for_grind = 0;
+ if( v[1] > 0.0f ) search_for_grind = 0;
/* REFACTOR */
}
if( search_for_grind ){
- v3f ve;
- v3_copy( launch_v, ve );
- ve[1] += -gravity * t;
-
- if( skate_grind_scansq( closest, ve, 0.5f, &grind ) ){
+ if( skate_grind_scansq( closest, v, 0.5f, &grind ) ){
/* check alignment */
- v2f v0 = { ve[0], ve[2] },
+ v2f v0 = { v[0], v[2] },
v1 = { grind.dir[0], grind.dir[2] };
v2_normalize( v0 );
a_min = cosf( VG_PIf * 0.05f );
/* check speed */
- if( (fabsf(v3_dot( ve, grind.dir ))>=k_grind_axel_min_vel) &&
+ if( (fabsf(v3_dot( v, grind.dir ))>=k_grind_axel_min_vel) &&
(a >= a_min) &&
(fabsf(grind.dir[1]) < 0.70710678118654752f))
{
world_tri_index_surface( trace_world, tri[0] );
inf->type = k_prediction_land;
-
- v3f ve;
- v3_copy( launch_v, ve );
- ve[1] += -gravity * t;
-
- inf->score = -v3_dot( ve, inf->n );
+ inf->score = -v3_dot( v, inf->n );
inf->land_dist = t + k_trace_delta * t1;
/* Bias prediction towords ramps */
if( (v3_length2(state->trick_vel) >= 0.0001f ) &&
state->trick_time > 0.2f)
{
- player__skate_kill_audio();
+ vg_info( "player fell off due to lack of skill\n" );
player__dead_transition( k_player_die_type_feet );
}
f32 lat = k_friction_lat;
if( fabsf(axis_state(k_sraxis_skid)) > 0.1f ){
- lat = k_friction_lat * 2.0f;
+ if( (player_skate.surface == k_surface_prop_snow) ||
+ (player_skate.surface == k_surface_prop_sand) ){
+ lat *= 8.0f;
+ }
+ else
+ lat *= 1.5f;
}
- vel[0] += vg_cfrictf( vel[0], k_friction_lat * k_rb_delta );
+ if( player_skate.surface == k_surface_prop_snow )
+ lat *= 0.5f;
+ else if( player_skate.surface == k_surface_prop_sand )
+ lat *= 0.6f;
+
+ vel[0] += vg_cfrictf( vel[0], lat * k_rb_delta );
vel[2] += vg_cfrictf( vel[2], k_friction_resistance * k_rb_delta );
/* Pushing additive force */
localplayer.rb.w );
state->flip_time += state->flip_rate * k_rb_delta;
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
}
static enum trick_type player_skate_trick_input(void){
m3x3_q( transfer, qtransfer );
q_mul( qtransfer, state->store_smoothed, state->smoothed_rotation );
q_normalize( state->smoothed_rotation );
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
if( end ){
state->activity = k_skate_activity_air;
if( button_down(k_srbind_use) && (v3_length2(state->trick_vel) < 0.01f) ){
localplayer.subsystem = k_player_subsystem_walk;
+ if( (state->activity <= k_skate_activity_air_to_grind) &&
+ localplayer.have_glider ){
+ player_glide_transition();
+ return;
+ }
+
v3f angles;
v3_copy( localplayer.cam.angles, localplayer.angles );
localplayer.angles[2] = 0.0f;
localplayer.rb.co );
player__begin_holdout( offset );
- player__skate_kill_audio();
player__walk_transition( state->activity <= k_skate_activity_air_to_grind?
0: 1, state->trick_euler[0] );
+
return;
}
state->trick_type = k_trick_type_none;
}
-static void player__skate_post_update(void){
- struct player_skate_state *state = &player_skate.state;
-
- for( int i=0; i<player_skate.possible_jump_count; i++ ){
- jump_info *jump = &player_skate.possible_jumps[i];
-
- if( jump->log_length == 0 ){
- vg_fatal_error( "assert: jump->log_length == 0\n" );
- }
-
- for( int j=0; j<jump->log_length - 1; j ++ ){
- float brightness = jump->score*jump->score*jump->score;
- v3f p1;
- v3_lerp( jump->log[j], jump->log[j+1], brightness, p1 );
- vg_line( jump->log[j], p1, jump->colour );
- }
-
- vg_line_cross( jump->log[jump->log_length-1], jump->colour, 0.25f );
-
- v3f p1;
- v3_add( jump->log[jump->log_length-1], jump->n, p1 );
- vg_line( jump->log[jump->log_length-1], p1, 0xffffffff );
-
- vg_line_point( jump->apex, 0.02f, 0xffffffff );
- }
-
+static void player__skate_comp_audio( void *_animator ){
+ struct player_skate_animator *animator = _animator;
audio_lock();
- float air = ((state->activity <= k_skate_activity_air_to_grind) ||
- (state->activity == k_skate_activity_handplant))? 1.0f: 0.0f,
- speed = v3_length( localplayer.rb.v ),
- attn = vg_minf( 1.0f, speed*0.1f ),
- slide = vg_clampf( fabsf(state->slip), 0.0f, 1.0f );
+ f32 air = ((animator->activity <= k_skate_activity_air_to_grind) ||
+ (animator->activity == k_skate_activity_handplant))? 1.0f: 0.0f,
+ speed = v3_length( animator->root_v ),
+ attn = vg_minf( 1.0f, speed*0.1f ),
+ slide = animator->slide;
- if( state->activity >= k_skate_activity_grind_any ){
+ if( animator->activity >= k_skate_activity_grind_any )
slide = 0.0f;
+
+ f32 gate = skaterift.time_rate;
+
+ if( skaterift.activity == k_skaterift_replay ){
+ gate = vg_minf( 1.0f, fabsf(skaterift.track_velocity) );
}
- f32 gate = skaterift.time_rate,
+ f32
vol_main = sqrtf( (1.0f-air)*attn*(1.0f-slide) * 0.4f ) * gate,
vol_air = sqrtf( air *attn * 0.5f ) * gate,
vol_slide = sqrtf( (1.0f-air)*attn*slide * 0.25f ) * gate;
float sidechain_amt = 0.0f,
hz = vg_maxf( speed * 2.0f, 2.0f );
- if( (player_skate.surface == k_surface_prop_tiles) &&
- (state->activity < k_skate_activity_grind_any) )
+ if( (animator->surface == k_surface_prop_tiles) &&
+ (animator->activity < k_skate_activity_grind_any) )
sidechain_amt = 1.0f;
else
sidechain_amt = 0.0f;
else{
int sample_type = k_skate_sample_concrete;
- if( state->activity == k_skate_activity_grind_5050 ){
- if( player_skate.surface == k_surface_prop_metal )
+ if( animator->activity == k_skate_activity_grind_5050 ){
+ if( animator->surface == k_surface_prop_metal )
sample_type = k_skate_sample_metal_scrape_generic;
else
sample_type = k_skate_sample_concrete_scrape_metal;
}
- else if( (state->activity == k_skate_activity_grind_back50) ||
- (state->activity == k_skate_activity_grind_front50) )
+ else if( (animator->activity == k_skate_activity_grind_back50) ||
+ (animator->activity == k_skate_activity_grind_front50) )
{
- if( player_skate.surface == k_surface_prop_metal ){
+ if( animator->surface == k_surface_prop_metal ){
sample_type = k_skate_sample_metal_scrape_generic;
}
else{
+#if 0
float a = v3_dot( localplayer.rb.to_world[2],
player_skate.grind_dir );
if( fabsf(a) > 0.70710678118654752f )
sample_type = k_skate_sample_concrete_scrape_wood;
else
sample_type = k_skate_sample_concrete_scrape_metal;
+#endif
+
+ sample_type = k_skate_sample_concrete_scrape_wood;
}
}
- else if( state->activity == k_skate_activity_grind_boardslide ){
- if( player_skate.surface == k_surface_prop_metal )
+ else if( animator->activity == k_skate_activity_grind_boardslide ){
+ if( animator->surface == k_surface_prop_metal )
sample_type = k_skate_sample_metal_scrape_generic;
else
sample_type = k_skate_sample_concrete_scrape_wood;
if( player_skate.aud_main ){
player_skate.aud_main->colour = 0x00103efe;
audio_channel_set_spacial( player_skate.aud_main,
- localplayer.rb.co, 40.0f );
+ animator->root_co, 40.0f );
//audio_channel_slope_volume( player_skate.aud_main, 0.05f, vol_main );
audio_channel_edit_volume( player_skate.aud_main, vol_main, 1 );
audio_channel_sidechain_lfo( player_skate.aud_main, 0, sidechain_amt );
if( player_skate.aud_slide ){
player_skate.aud_slide->colour = 0x00103efe;
audio_channel_set_spacial( player_skate.aud_slide,
- localplayer.rb.co, 40.0f );
+ animator->root_co, 40.0f );
//audio_channel_slope_volume( player_skate.aud_slide, 0.05f, vol_slide );
audio_channel_edit_volume( player_skate.aud_slide, vol_slide, 1 );
audio_channel_sidechain_lfo( player_skate.aud_slide, 0, sidechain_amt );
if( player_skate.aud_air ){
player_skate.aud_air->colour = 0x00103efe;
audio_channel_set_spacial( player_skate.aud_air,
- localplayer.rb.co, 40.0f );
+ animator->root_co, 40.0f );
//audio_channel_slope_volume( player_skate.aud_air, 0.05f, vol_air );
audio_channel_edit_volume( player_skate.aud_air, vol_air, 1 );
}
audio_unlock();
}
+static void player__skate_post_update(void){
+ struct player_skate_state *state = &player_skate.state;
+
+ for( int i=0; i<player_skate.possible_jump_count; i++ ){
+ jump_info *jump = &player_skate.possible_jumps[i];
+
+ if( jump->log_length == 0 ){
+ vg_fatal_error( "assert: jump->log_length == 0\n" );
+ }
+
+ for( int j=0; j<jump->log_length - 1; j ++ ){
+ float brightness = jump->score*jump->score*jump->score;
+ v3f p1;
+ v3_lerp( jump->log[j], jump->log[j+1], brightness, p1 );
+ vg_line( jump->log[j], p1, jump->colour );
+ }
+
+ vg_line_cross( jump->log[jump->log_length-1], jump->colour, 0.25f );
+
+ v3f p1;
+ v3_add( jump->log[jump->log_length-1], jump->n, p1 );
+ vg_line( jump->log[jump->log_length-1], p1, 0xffffffff );
+
+ vg_line_point( jump->apex, 0.02f, 0xffffffff );
+ }
+}
+
/*
* truck alignment model at ra(local)
* returns 1 if valid surface:
if( world->water.enabled ){
if( localplayer.rb.co[1]+0.25f < world->water.height ){
+ vg_info( "player fell off due to being in water\n" );
player__networked_sfx( k_player_subsystem_walk, 32,
k_player_walk_soundeffect_splash,
localplayer.rb.co, 1.0f );
- player__skate_kill_audio();
player__dead_transition( k_player_die_type_generic );
return;
}
skate_apply_trick_model();
skate_apply_pump_model();
+ ent_tornado_debug();
+ v3f a;
+ ent_tornado_forces( localplayer.rb.co, localplayer.rb.v, a );
+ v3_muladds( localplayer.rb.v, a, k_rb_delta, localplayer.rb.v );
+
begin_collision:;
/*
v3_add( localplayer.rb.co, cg_offset, localplayer.rb.co );
}
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
localplayer.rb.v[1] += -state->gravity_bias * player_skate.substep_delta;
player_skate.substep -= player_skate.substep_delta;
k_material_flag_walking ) != -1) )
{
v3_lerp( start_co, localplayer.rb.co, t, localplayer.rb.co );
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
- player__skate_kill_audio();
+ vg_info( "player fell of due to hitting head\n" );
player__dead_transition( k_player_die_type_head );
return;
}
m4x3f mtx;
m3x3_identity( mtx );
m4x3_mulv( localplayer.rb.to_world, wheels[i].pos, mtx[3] );
-
- rb_sphere collider = { .radius = wheels[i].radius };
rb_ct *man = &manifold[ manifold_len ];
- int l = skate_collide_smooth( mtx, &collider, man );
+ int l = skate_collide_smooth( mtx, wheels[i].radius, man );
if( l )
wheels[i].state = k_collider_state_colliding;
}
float grind_radius = k_board_radius * 0.75f;
- rb_capsule capsule = { .height = (k_board_length+0.2f)*2.0f,
- .radius=grind_radius };
+ rb_capsule capsule = { .h = (k_board_length+0.2f)*2.0f,
+ .r = grind_radius };
m4x3f mtx;
v3_muls( localplayer.rb.to_world[0], 1.0f, mtx[0] );
v3_muls( localplayer.rb.to_world[2], -1.0f, mtx[1] );
rb_ct *cman = &manifold[manifold_len];
- int l = rb_capsule__scene( mtx, &capsule, NULL, &world->rb_geo.inf.scene,
+ int l = rb_capsule__scene( mtx, &capsule, NULL, world->geo_bh,
cman, k_material_flag_walking );
/* weld joints */
l = rb_manifold_apply_filtered( cman, l );
manifold_len += l;
-
- if( vg_lines.draw )
- vg_line_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
+ vg_line_capsule( mtx, capsule.r, capsule.h, VG__WHITE );
/* add limits */
if( state->activity >= k_skate_activity_grind_any ){
* regular dance; calculate velocity & total mass, apply impulse.
*/
- struct contact *ct = &manifold[i];
+ rb_ct *ct = &manifold[i];
v3f rv, delta;
v3_sub( ct->co, world_cog, delta );
v3f dt;
rb_depenetrate( manifold, manifold_len, dt );
v3_add( dt, localplayer.rb.co, localplayer.rb.co );
- rb_update_transform( &localplayer.rb );
+ rb_update_matrices( &localplayer.rb );
substep_count ++;
f32 nforce = v3_length(normal_total);
if( nforce > 4.0f ){
if( nforce > 17.6f ){
+ vg_info( "player fell off due to hitting ground too hard\n" );
v3_muladds( localplayer.rb.v, normal_total, -1.0f, localplayer.rb.v );
player__dead_transition( k_player_die_type_feet );
- player__skate_kill_audio();
return;
}
q_mul( transport_rotation, localplayer.rb.q, localplayer.rb.q );
q_mul( transport_rotation, state->smoothed_rotation,
state->smoothed_rotation );
- rb_update_transform( &localplayer.rb );
+ q_normalize( localplayer.rb.q );
+ q_normalize( state->smoothed_rotation );
+ rb_update_matrices( &localplayer.rb );
player__pass_gate( id );
}
animator->grind_balance = vg_lerpf( animator->grind_balance, grind_frame,
5.0f*vg.time_delta );
animator->activity = state->activity;
+ animator->surface = player_skate.surface;
/* pushing */
animator->push_time = vg.time - state->start_push;
static void player__skate_effects( void *_animator, m4x3f *final_mtx,
struct player_board *board,
struct player_effects_data *effect_data ){
-
struct skeleton *sk = &localplayer.skeleton;
struct player_skate_animator *animator = _animator;
- if( animator->grind > 0.5f ){
- v3f vp0, vp1, vpc;
- if( board ){
- v3_copy((v3f){0.0f,0.02f, board->truck_positions[0][2]}, vp1 );
- v3_copy((v3f){0.0f,0.02f, board->truck_positions[1][2]}, vp0 );
- }
- else{
- v3_zero( vp0 );
- v3_zero( vp1 );
- }
+ v3f vp0, vp1, vpc;
+ if( board ){
+ v3_copy((v3f){0.0f,0.02f, board->truck_positions[0][2]}, vp1 );
+ v3_copy((v3f){0.0f,0.02f, board->truck_positions[1][2]}, vp0 );
+ }
+ else{
+ v3_zero( vp0 );
+ v3_zero( vp1 );
+ }
+
+ v3f *board_mtx = final_mtx[ localplayer.id_board ];
+ m4x3_mulv( board_mtx, vp0, vp0 );
+ m4x3_mulv( board_mtx, vp1, vp1 );
+ v3_add( vp0, vp1, vpc );
+ v3_muls( vpc, 0.5f, vpc );
+
+ if( animator->surface == k_surface_prop_sand ){
+ if( (animator->slide>0.4f) && (v3_length2(animator->root_v)>4.0f*4.0f) ){
+ v3f v, co;
+ v3_muls( animator->root_v, 0.5f, v );
+ v3_lerp( vp0, vp1, vg_randf64(&vg.rand), co );
- v3f *board_mtx = final_mtx[ localplayer.id_board ];
- m4x3_mulv( board_mtx, vp0, vp0 );
- m4x3_mulv( board_mtx, vp1, vp1 );
- v3_add( vp0, vp1, vpc );
- v3_muls( vpc, 0.5f, vpc );
+ effect_data->sand.colour = 0xff8ec4e6;
+ effect_spark_apply( &effect_data->sand, co, v, vg.time_delta * 8.0 );
+ }
+ }
+ if( animator->grind > 0.5f ){
int back = 0, front = 0, mid = 0;
if( animator->activity == k_skate_activity_grind_5050 ){
static void player__skate_post_animate(void){
struct player_skate_state *state = &player_skate.state;
localplayer.cam_velocity_influence = 1.0f;
+ localplayer.cam_dist = 1.8f;
v3f head = { 0.0f, 1.8f, 0.0f };
m4x3_mulv( localplayer.final_mtx[ localplayer.id_head ],
bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->push_time );
bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->jump_time );
+ bitpack_qf32( ctx, 16, 0.0f, 4.0f, &animator->handplant_t );
bitpack_qv3f( ctx, 16, -100.0f, 100.0f, animator->root_v );
bitpack_bytes( ctx, 1, &animator->activity );
}