support_max;
v3f support_axis;
- v3_cross( plane, localplayer.basis[1], support_axis );
+ v3_cross( plane, (v3f){0,1,0}, support_axis );
v3_normalize( support_axis );
bh_iter it;
v3_cross( va, vb, normal );
sample->normal[0] = v3_dot( support_axis, normal );
- sample->normal[1] = v3_dot( localplayer.basis[1], normal );
+ sample->normal[1] = normal[1];
sample->co[0] = v3_dot( support_axis, d );
- sample->co[1] = v3_dot( localplayer.basis[1], d );
+ sample->co[1] = d[1];
v3_copy( normal, sample->normal3 ); /* normalize later
if we want to us it */
v3_copy( sj->normal3, n1 );
v3_cross( n0, n1, dir );
- if( v3_length2( dir ) <= 0.001f )
+ if( v3_length2( dir ) <= 0.000001f )
continue;
v3_normalize( dir );
v3_muls( dir, vg_signf(v3_dot(dir,plane)), dir );
v3_add( average_direction, dir, average_direction );
- float yi = v3_dot( localplayer.basis[1], si->normal3 ),
- yj = v3_dot( localplayer.basis[1], sj->normal3 );
+ float yi = si->normal3[1],
+ yj = sj->normal3[1];
if( yi > yj ) v3_add( si->normal3, average_normal, average_normal );
else v3_add( sj->normal3, average_normal, average_normal );
v3f v0;
v3_sub( target, localplayer.rb.co, v0 );
- m3x3_mulv( localplayer.invbasis, v0, v0 );
v3f ax;
v3_copy( v0, ax );
ax[1] = 0.0f;
v3_normalize( ax );
- v3f v_local;
- m3x3_mulv( localplayer.invbasis, localplayer.rb.v, v_local );
-
- v2f d = { v3_dot( ax, v0 ), v0[1] },
- v = { v3_dot( ax, v_local ), v_local[1] };
+ v2f d = { v3_dot( ax, v0 ), v0[1] },
+ v = { v3_dot( ax, localplayer.rb.v ), localplayer.rb.v[1] };
float a = atan2f( v[1], v[0] ),
m = v2_length( v ),
v3_muls( ax, cosf( a0 ) * m, inf->v );
inf->v[1] += sinf( a0 ) * m;
- m3x3_mulv( localplayer.basis, inf->v, inf->v );
inf->land_dist = d[0] / (cosf(a0)*m);
inf->gravity = gravity;
v3_muls( ax, cosf( a1 ) * m, inf->v );
inf->v[1] += sinf( a1 ) * m;
- m3x3_mulv( localplayer.basis, inf->v, inf->v );
inf->land_dist = d[0] / (cosf(a1)*m);
inf->gravity = gravity;
v3_normalize( axis );
/* at high slopes, Y component is low */
- float upness = v3_dot( localplayer.rb.to_world[1], localplayer.basis[1] ),
+ float upness = localplayer.rb.to_world[1][1],
angle_begin = -(1.0f-fabsf( upness )),
angle_end = 1.0f;
inf->gravity = gravity;
v3_copy( launch_v, inf->v );
- m3x3f basis;
- m3x3_copy( localplayer.basis, basis );
-
for( int i=1; i<=50; i++ ){
float t = (float)i * k_trace_delta;
v3_muls( launch_v, t, co1 );
- v3_muladds( co1, basis[1], -0.5f * gravity * t*t, co1 );
+ co1[1] += -0.5f * gravity * t*t;
v3_add( launch_co, co1, co1 );
- float launch_vy = v3_dot( launch_v,basis[1] );
+ float launch_vy = launch_v[1];
int search_for_grind = 1;
if( grind_located ) search_for_grind = 0;
for( int j=0; j<2; j++ ){
v3_muls( launch_v_bounds[j], t, bound[j] );
- v3_muladds( bound[j], basis[1], -0.5f*gravity*t*t, bound[j] );
+ bound[j][1] += -0.5f*gravity*t*t;
v3_add( launch_co, bound[j], bound[j] );
}
if( search_for_grind ){
v3f ve;
v3_copy( launch_v, ve );
- v3_muladds( ve, basis[1], -gravity * t, ve );
+ ve[1] += -gravity * t;
if( skate_grind_scansq( closest, ve, 0.5f, &grind ) ){
/* check alignment */
- v2f v0 = { v3_dot( ve, basis[0] ),
- v3_dot( ve, basis[2] ) },
- v1 = { v3_dot( grind.dir, basis[0] ),
- v3_dot( grind.dir, basis[2] ) };
+ v2f v0 = { ve[0], ve[2] },
+ v1 = { grind.dir[0], grind.dir[2] };
v2_normalize( v0 );
v2_normalize( v1 );
m4x3_mulv( gate->transport, co1, co1 );
m3x3_mulv( gate->transport, launch_v, launch_v);
m4x3_mulv( gate->transport, launch_co, launch_co );
- m3x3_mul( gate->transport, basis, basis );
+
+ if( gate->flags & k_ent_gate_nonlocal )
+ trace_world = &world_static.instances[ gate->target ];
}
}
v3f ve;
v3_copy( launch_v, ve );
- v3_muladds( ve, localplayer.basis[1], -gravity * t, ve );
+ ve[1] += -gravity * t;
inf->score = -v3_dot( ve, inf->n );
inf->land_dist = t + k_trace_delta * t1;
v3_copy( jump->v, launch_v );
v3_copy( localplayer.rb.co, launch_co );
-
- m3x3f basis;
- m3x3_copy( localplayer.basis, basis );
float t = 0.05f * jump->land_dist;
v3_muls( launch_v, t, co0 );
- v3_muladds( co0, basis[1], -0.5f * jump->gravity * t*t, co0 );
+ co0[1] += -0.5f * jump->gravity * t*t;
v3_add( launch_co, co0, co0 );
/* rough scan to make sure we dont collide with anything */
t *= jump->land_dist;
v3_muls( launch_v, t, co1 );
- v3_muladds( co1, basis[1], -0.5f * jump->gravity * t*t, co1 );
+ co1[1] += -0.5f * jump->gravity * t*t;
v3_add( launch_co, co1, co1 );
float t1;
/* determine score */
v3f ve;
v3_copy( jump->v, ve );
- v3_muladds( ve, localplayer.basis[1],
- -jump->gravity*jump->land_dist, ve );
+ ve[1] += -jump->gravity*jump->land_dist;
jump->score = -v3_dot( ve, grind.n ) * 0.9f;
player_skate.possible_jumps[ player_skate.possible_jump_count ++ ] =
v3_zero( state->flip_axis );
}
}
- else{
- v3_copy( localplayer.basis[1], state->land_normal );
- }
+ else
+ v3_copy( (v3f){0,1,0}, state->land_normal );
}
/*
if( v3_length2( state->trick_vel ) < 0.0001f )
return;
- int carry_on = player_skate_trick_input();
+ int carry_on = state->trick_type == player_skate_trick_input();
/* we assume velocities share a common divisor, in which case the
* interval is the minimum value (if not zero) */
}
float interval = 1.0f / min_rate,
- current = floorf( state->trick_time / interval ),
- next_end = (current+1.0f) * interval;
+ current = floorf( state->trick_time ),
+ next_end = current+1.0f;
/* integrate trick velocities */
v3_muladds( state->trick_euler, state->trick_vel, k_rb_delta,
state->trick_euler );
- if( !carry_on && (state->trick_time + k_rb_delta >= next_end) ){
+ if( !carry_on && (state->trick_time + k_rb_delta/interval >= next_end) ){
state->trick_time = 0.0f;
state->trick_euler[0] = roundf( state->trick_euler[0] );
state->trick_euler[1] = roundf( state->trick_euler[1] );
state->trick_euler[2] = roundf( state->trick_euler[2] );
v3_copy( state->trick_vel, state->trick_residualv );
v3_zero( state->trick_vel );
- }
- state->trick_time += k_rb_delta;
+ audio_lock();
+ audio_oneshot_3d( &audio_flips[vg_randu32()%4],
+ localplayer.rb.co, 40.0f, 1.0f );
+ audio_unlock();
+ }
+ else
+ state->trick_time += k_rb_delta / interval;
}
else{
if( (v3_length2(state->trick_vel) >= 0.0001f ) &&
v3f jumpdir;
/* Launch more up if alignment is up else improve velocity */
- float aup = v3_dot( localplayer.basis[1], localplayer.rb.to_world[1] ),
+ float aup = localplayer.rb.to_world[1][1],
mod = 0.5f,
dir = mod + fabsf(aup)*(1.0f-mod);
/* Apply forces & intergrate */
v3_muladds( state->cog_v, F, -rb, state->cog_v );
- v3_muladds( state->cog_v, localplayer.basis[1], -9.8f * k_rb_delta,
- state->cog_v );
-
+ state->cog_v[1] += -9.8f * k_rb_delta;
v3_muladds( state->cog, state->cog_v, k_rb_delta, state->cog );
}
if( state->activity <= k_skate_activity_air_to_grind ){
enum trick_type trick = k_trick_type_none;
if( (trick = player_skate_trick_input()) ){
- if( (vg.time - state->jump_time) < 0.1f ){
+ if( state->trick_time == 0.0f ){
+ audio_lock();
+ audio_oneshot_3d( &audio_flips[vg_randu32()%4],
+ localplayer.rb.co, 40.0f, 1.0f );
+ audio_unlock();
+ }
+
+ if( state->trick_time < 0.1f ){
v3_zero( state->trick_vel );
- state->trick_time = 0.0f;
if( trick == k_trick_type_kickflip ){
state->trick_vel[0] = 3.0f;
}
else{
v3f avg;
- v3_add( localplayer.rb.to_world[1], localplayer.basis[1], avg );
+ v3_add( localplayer.rb.to_world[1], (v3f){0,1,0}, avg );
v3_normalize( avg );
v3_lerp( state->up_dir, avg,
static void skate_grind_truck_apply( float sign, struct grind_info *inf,
float strength ){
struct player_skate_state *state = &player_skate.state;
-
/* REFACTOR */
v3f ra = { 0.0f, -k_board_radius, sign * k_board_length };
v3f raw, wsp;
if( world->water.enabled ){
if( localplayer.rb.co[1]+0.25f < world->water.height ){
-#if 0
player__networked_sfx( k_player_subsystem_walk, 32,
k_player_walk_soundeffect_splash,
localplayer.rb.co, 1.0f );
-#endif
player__skate_kill_audio();
player__dead_transition();
return;
}
}
min_dist -= 0.2f;
- float vy = v3_dot( localplayer.basis[1], localplayer.rb.v );
- vy = vg_maxf( 0.0f, vy );
-
+ float vy = vg_maxf( 0.0f, localplayer.rb.v[1] );
slap = vg_clampf( (min_dist/0.5f) + vy, 0.0f, 1.0f )*0.3f;
}
state->slap = vg_lerpf( state->slap, slap, 10.0f*k_rb_delta );
}
rb_update_transform( &localplayer.rb );
- v3_muladds( localplayer.rb.v, localplayer.basis[1],
- -state->gravity_bias * player_skate.substep_delta,
- localplayer.rb.v );
+ localplayer.rb.v[1] += -state->gravity_bias * player_skate.substep_delta;
player_skate.substep -= player_skate.substep_delta;
}
/* yes, we are currently rebuilding mass matrices every frame. too bad! */
- v3f extent = { k_board_width, 0.1f, k_board_length };
+ v3f extent = { k_board_width*10.0f, 0.1f, k_board_length };
float ex2 = k_board_interia*extent[0]*extent[0],
ey2 = k_board_interia*extent[1]*extent[1],
ez2 = k_board_interia*extent[2]*extent[2];
} else if( stick_frames == 0 ){
/* TODO: EXIT SOUNDS */
}
+
+ if( (state->activity_prev < k_skate_activity_grind_any) &&
+ (state->activity >= k_skate_activity_grind_any) ){
+ state->velocity_limit = v3_length( localplayer.rb.v )*1.0f;
+ state->grind_y_start = localplayer.rb.co[1];
+ }
+
+ if( state->activity >= k_skate_activity_grind_any ){
+ f32 dy = localplayer.rb.co[1] - state->grind_y_start;
+ if( dy < 0.0f ){
+ state->velocity_limit += -dy*0.2f;
+ }
+ state->grind_y_start = localplayer.rb.co[1];
+
+
+ f32 speed_end = v3_length( localplayer.rb.v );
+ if( speed_end > state->velocity_limit ){
+ v3_muls( localplayer.rb.v, state->velocity_limit/speed_end,
+ localplayer.rb.v );
+ }
+ }
}
static void player__skate_im_gui(void){
state->trick_vel[0],
state->trick_vel[1],
state->trick_vel[2] );
- player__debugtext( 1, "tricke: %.2f %.2f %.2f",
+ player__debugtext( 1, "tricke: %.2fs %.2f %.2f %.2f",
+ state->trick_time,
state->trick_euler[0],
state->trick_euler[1],
state->trick_euler[2] );
animator->grind_balance = vg_lerpf( animator->grind_balance, grind_frame,
5.0f*vg.time_delta );
+ animator->activity = state->activity;
/* pushing */
animator->push_time = vg.time - state->start_push;
animator->subslap = vg_lerpf( animator->subslap, slapm,
vg.time_delta*10.0f );
+#if 0
f32 l = ((state->activity < k_skate_activity_ground) &&
v3_length2(state->trick_vel) > 0.1f )? 1: 0;
animator->trick_foot = vg_lerpf( animator->trick_foot, l,
8.4f*vg.time_delta );
+#endif
+
+ animator->trick_foot = vg_exp_impulse( state->trick_time, 5.0f );
/* grab */
v2f grab_input;
}
else q_identity( animator->qfixuptotal );
rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q );
+ v3_copy( localplayer.rb.v, animator->root_v );
}
static void player__skate_pose( void *_animator, player_pose *pose ){
kf_board->co[1] += animator->slap * animator->subslap;
kf_hip->co[1] += animator->slap * 0.25f;
+ /* kickflip and shuvit are in the wrong order for some reason */
if( animator->trick_type == k_trick_type_kickflip ){
- kf_foot_l->co[0] += animator->trick_foot * 0.2f;
+ kf_foot_l->co[0] += animator->trick_foot * 0.15f;
+ kf_foot_r->co[0] -= animator->trick_foot * 0.15f;
kf_foot_l->co[1] -= animator->trick_foot * 0.18f;
+ kf_foot_r->co[1] -= animator->trick_foot * 0.18f;
}
else if( animator->trick_type == k_trick_type_shuvit ){
- kf_foot_l->co[0] += animator->trick_foot * 0.1f;
- kf_foot_r->co[0] -= animator->trick_foot * 0.15f;
+ kf_foot_l->co[0] += animator->trick_foot * 0.2f;
kf_foot_l->co[1] -= animator->trick_foot * 0.18f;
- kf_foot_r->co[1] -= animator->trick_foot * 0.18f;
+ kf_foot_r->co[0] -= animator->trick_foot * 0.1f;
+ kf_foot_r->co[1] += animator->trick_foot * 0.09f;
}
else if( animator->trick_type == k_trick_type_treflip ){
kf_foot_l->co[0] += animator->trick_foot * 0.2f;
}
}
+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 *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 );
+
+ int back = 0, front = 0, mid = 0;
+
+ if( animator->activity == k_skate_activity_grind_5050 ){
+ back = 1;
+ front = 1;
+ }
+ else if( animator->activity == k_skate_activity_grind_back50 ){
+ back = 1;
+ }
+ else if( animator->activity == k_skate_activity_grind_front50 ){
+ front = 1;
+ }
+ else if( animator->activity == k_skate_activity_grind_boardslide ){
+ mid = 1;
+ }
+
+ if( back ){
+ effect_spark_apply( &effect_data->spark, vp0,
+ animator->root_v, vg.time_delta );
+ }
+
+ if( front ){
+ effect_spark_apply( &effect_data->spark, vp1,
+ animator->root_v, vg.time_delta );
+ }
+
+ if( mid ){
+ effect_spark_apply( &effect_data->spark, vpc,
+ animator->root_v, vg.time_delta );
+ }
+ }
+}
+
static void player__skate_post_animate(void){
struct player_skate_state *state = &player_skate.state;
localplayer.cam_velocity_influence = 1.0f;
bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->push_time );
bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->jump_time );
+ bitpack_qv3f( ctx, 16, -100.0f, 100.0f, animator->root_v );
+ bitpack_bytes( ctx, 1, &animator->activity );
}
static void player__skate_sfx_oneshot( u8 id, v3f pos, f32 volume ){