+
+ float min_a = 0.70710678118654752f;
+ ray_hit *candidate = NULL;
+
+ if( sample_count >= 2 ){
+ for( int i=0; i<sample_count-1; i++ ){
+ ray_hit *s0 = &samples[i],
+ *s1 = &samples[i+1];
+
+ float a = v3_dot( s0->normal, s1->normal );
+
+ if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) ){
+ min_a = a;
+ candidate = s0;
+ }
+ }
+ }
+
+ if( candidate ){
+ v4f pa, pb, pc;
+
+ ray_hit *s0 = candidate,
+ *s1 = candidate+1;
+
+ vg_line( s0->pos, s1->pos, VG__WHITE );
+
+ v3_copy( s0->normal, pa );
+ v3_copy( s1->normal, pb );
+ v3_cross( localplayer.rb.to_world[1], dir, pc );
+ v3_normalize( pc );
+
+ pa[3] = v3_dot( pa, s0->pos );
+ pb[3] = v3_dot( pb, s1->pos );
+ pc[3] = v3_dot( pc, localplayer.rb.co );
+
+ v3f edge;
+ if( plane_intersect3( pa, pb, pc, edge ) ){
+ v3_copy( edge, player_walk.state.drop_in_target );
+ v3_copy( s1->normal, player_walk.state.drop_in_normal );
+ v3_copy( localplayer.rb.co, player_walk.state.drop_in_start );
+
+ player_walk.state.drop_in_start_angle = player_get_heading_yaw();
+ player_walk.state.drop_in_angle =
+ atan2f( player_walk.state.drop_in_normal[0],
+ player_walk.state.drop_in_normal[2] );
+
+ /* TODO: scan multiple of these? */
+ v3f oco;
+ v4f oq;
+ player_walk_drop_in_overhang_transform( 1.0f, oco, oq );
+
+ v3f va = {0.0f,0.0f,-k_board_length - 0.3f},
+ vb = {0.0f,0.0f, k_board_length + 0.3f};
+
+ q_mulv( oq, va, va );
+ q_mulv( oq, vb, vb );
+ v3_add( oco, va, va );
+ v3_add( oco, vb, vb );
+
+ v3f v0;
+ v3_sub( vb, va, v0 );
+ v3_normalize( v0 );
+
+ ray_hit ray;
+ ray.dist = k_board_length*2.0f + 0.6f;
+
+ if( ray_world( world, va, v0, &ray, 0 ) ){
+ vg_line( va, vb, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
+ vg_error( "invalidated\n" );
+ return 0;
+ }
+
+ v3_muls( v0, -1.0f, v0 );
+ if( ray_world( world, vb, v0, &ray, 0 ) ){
+ vg_line( va, vb, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
+ vg_error( "invalidated\n" );
+ return 0;
+ }
+
+ player_walk_drop_in_vector( localplayer.rb.v );
+ return 1;
+ }
+ else{
+ vg_error( "failed to find intersection of drop in\n" );
+ }
+ }
+
+ return 0;
+}
+
+static struct skeleton_anim *player_walk_outro_anim( enum walk_outro type ){
+ struct player_walk *w = &player_walk;
+
+ if( type >= k_walk_outro_max )
+ return NULL;
+
+ return (struct skeleton_anim *[]){
+ [k_walk_outro_none] = NULL,
+ [k_walk_outro_jump_to_air] = w->anim_jump_to_air,
+ [k_walk_outro_regular] = w->anim_intro,
+ [k_walk_outro_drop_in] = w->anim_drop_in
+ }[ type ];
+}
+
+
+static void player__walk_pre_update(void){
+ struct player_walk *w = &player_walk;
+
+ if( !localplayer.immobile )
+ player_look( localplayer.angles, skaterift.time_rate );
+
+ v2f steer;
+ joystick_state( k_srjoystick_steer, steer );
+
+ if( w->state.activity == k_walk_activity_sit ){
+ if( w->state.sit_t < 1.0f )
+ w->state.sit_t = vg_minf( 1.0f, w->state.sit_t + vg.time_delta );
+
+ if( button_down(k_srbind_sit) || (v2_length2(steer)>0.2f) ||
+ button_down(k_srbind_jump) ){
+ w->state.activity = k_walk_activity_sit_up;
+ }
+ return;
+ }
+ else if( w->state.activity == k_walk_activity_sit_up ){
+ if( w->state.sit_t > 0.0f )
+ w->state.sit_t = vg_maxf( 0.0f, w->state.sit_t - vg.time_delta );
+ else
+ w->state.activity = k_walk_activity_ground;
+
+ if( button_down(k_srbind_sit) )
+ w->state.activity = k_walk_activity_sit;
+
+ return;
+ }
+ else if( w->state.activity == k_walk_activity_ground ){
+ if( button_down(k_srbind_sit) ){
+ v3_zero( localplayer.rb.v );
+ w->state.activity = k_walk_activity_sit;
+ return;