now fall in immobile mode
[carveJwlIkooP6JGAAIwe30JlM.git] / player_skate.c
index fe34de2441ce6b3d40a5bbe5542b448fc5d2f4fa..7da738ef6419013c0bff9dc460d94abc9bb62d47 100644 (file)
@@ -59,18 +59,17 @@ VG_STATIC int skate_collide_smooth( player_instance *player,
    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, sphere, NULL, &world->rb_geo.inf.scene, man,
+                           k_material_flag_walking );
 
-   for( int i=0; i<len; i++ )
-   {
+   for( int i=0; i<len; i++ ){
       man[i].rba = &player->rb;
       man[i].rbb = NULL;
    }
 
    rb_manifold_filter_coplanar( man, len, 0.03f );
 
-   if( len > 1 )
-   {
+   if( len > 1 ){
       rb_manifold_filter_backface( man, len );
       rb_manifold_filter_joint_edges( man, len, 0.03f );
       rb_manifold_filter_pairs( man, len, 0.03f );
@@ -499,8 +498,8 @@ void player__approximate_best_trajectory( player_instance *player )
                m4x3_mulv( gate->transport, launch_co, launch_co );
                m3x3_mul( gate->transport, basis, basis );
 
-               if( gate->type == k_gate_type_nonlocel ){
-                  trace_world = &world_static.worlds[ gate->target ];
+               if( gate->flags & k_ent_gate_nonlocal ){
+                  trace_world = &world_static.instances[ gate->target ];
                }
             }
          }
@@ -511,7 +510,8 @@ void player__approximate_best_trajectory( player_instance *player )
          float scan_radius = k_board_radius;
                scan_radius *= vg_clampf( t, 0.02f, 1.0f );
 
-         int idx = spherecast_world(trace_world, co0, co1, scan_radius, &t1, n);
+         int idx = spherecast_world( trace_world, co0, co1, scan_radius, &t1, n,
+                                     k_material_flag_walking );
          if( idx != -1 ){
             v3f co;
             v3_lerp( co0, co1, t1, co );
@@ -598,7 +598,8 @@ void player__approximate_best_trajectory( player_instance *player )
             v3f n;
 
             int idx = spherecast_world( world0, co0,co1,
-                                        k_board_radius*0.1f, &t1, n);
+                                        k_board_radius*0.1f, &t1, n, 
+                                        k_material_flag_walking );
             if( idx != -1 ){
                goto invalidated_grind;
             }
@@ -1110,36 +1111,38 @@ VG_STATIC void player__skate_pre_update( player_instance *player ){
       player->subsystem = k_player_subsystem_walk;
 
       v3f angles;
-      v3_copy( player->cam.angles, angles );
-      angles[2] = 0.0f;
+      v3_copy( player->cam.angles, player->angles );
+      player->angles[2] = 0.0f;
 
       player__begin_holdout( player );
       player__skate_kill_audio( player );
-      player__walk_transition( player, angles );
+      player__walk_transition( player );
       return;
    }
 
-   enum trick_type trick = k_trick_type_none;
-   if( (s->state.activity <= k_skate_activity_air_to_grind) && 
-       (trick = player_skate_trick_input( player )) )
-   {
-      if( (vg.time - s->state.jump_time) < 0.1f ){
-         v3_zero( s->state.trick_vel );
-         s->state.trick_time = 0.0f;
-
-         if( trick == k_trick_type_kickflip ){
-            s->state.trick_vel[0] = 3.0f;
-         }
-         else if( trick == k_trick_type_shuvit ){
-            s->state.trick_vel[2] = 3.0f;
-         }
-         else if( trick == k_trick_type_treflip ){
-            s->state.trick_vel[0] = 2.0f;
-            s->state.trick_vel[2] = 2.0f;
+   if( s->state.activity <= k_skate_activity_air_to_grind ){
+      enum trick_type trick = k_trick_type_none;
+      if( (trick = player_skate_trick_input( player )) ){
+         if( (vg.time - s->state.jump_time) < 0.1f ){
+            v3_zero( s->state.trick_vel );
+            s->state.trick_time = 0.0f;
+
+            if( trick == k_trick_type_kickflip ){
+               s->state.trick_vel[0] = 3.0f;
+            }
+            else if( trick == k_trick_type_shuvit ){
+               s->state.trick_vel[2] = 3.0f;
+            }
+            else if( trick == k_trick_type_treflip ){
+               s->state.trick_vel[0] = 2.0f;
+               s->state.trick_vel[2] = 2.0f;
+            }
+            s->state.trick_type = trick;
          }
-         s->state.trick_type = trick;
       }
    }
+   else
+      s->state.trick_type = k_trick_type_none;
 }
 
 VG_STATIC void player__skate_post_update( player_instance *player ){
@@ -1330,7 +1333,7 @@ int skate_compute_surface_alignment( player_instance *player,
       v3_muladds( left,  player->rb.to_world[1],  k_board_radius,   left );
       ray_l.dist = 2.1f * k_board_radius;
 
-      res_l = ray_world( world, left, dir, &ray_l );
+      res_l = ray_world( world, left, dir, &ray_l, k_material_flag_walking );
 
       if( res_l )
          break;
@@ -1342,7 +1345,7 @@ int skate_compute_surface_alignment( player_instance *player,
       v3_muladds( right, player->rb.to_world[1],  k_board_radius,   right );
       ray_r.dist = 2.1f * k_board_radius;
 
-      res_r = ray_world( world, right, dir, &ray_r );
+      res_r = ray_world( world, right, dir, &ray_r, k_material_flag_walking );
 
       if( res_r )
          break;
@@ -1509,7 +1512,8 @@ VG_STATIC int skate_point_visible( v3f origin, v3f target ){
    v3_muls( dir, 1.0f/ray.dist, dir );
    ray.dist -= 0.025f;
 
-   if( ray_world( world_current_instance(), origin, dir, &ray ) )
+   if( ray_world( world_current_instance(), origin, dir, &ray, 
+                  k_material_flag_walking ) )
       return 0;
 
    return 1;
@@ -2280,7 +2284,8 @@ begin_collision:;
       v3f n;
 
       float cast_radius = wheels[i].radius - k_penetration_slop * 2.0f;
-      if( spherecast_world( world, current, future, cast_radius, &t, n ) != -1)
+      if( spherecast_world( world, current, future, cast_radius, &t, n,
+                            k_material_flag_walking ) != -1)
          max_time = vg_minf( max_time, t * s->substep );
    }
 
@@ -2327,7 +2332,8 @@ begin_collision:;
    float t;
    v3f n;
    if( (v3_dist2( head_wp0, head_wp1 ) > 0.001f) &&
-       (spherecast_world( world, head_wp0, head_wp1, 0.2f, &t, n ) != -1) )
+       (spherecast_world( world, head_wp0, head_wp1, 0.2f, &t, n,
+                          k_material_flag_walking ) != -1) )
    {
       v3_lerp( start_co, player->rb.co, t, player->rb.co );
       rb_update_transform( &player->rb );
@@ -2374,7 +2380,7 @@ begin_collision:;
    rb_ct *cman = &manifold[manifold_len];
 
    int l = rb_capsule__scene( mtx, &capsule, NULL, &world->rb_geo.inf.scene,
-                              cman );
+                              cman, k_material_flag_walking );
 
    /* weld joints */
    for( int i=0; i<l; i ++ )
@@ -2773,6 +2779,19 @@ VG_STATIC void player__skate_animate( player_instance *player ){
    animator->board_euler[1] += extra;
    animator->trick_type = s->state.trick_type;
 
+   /* board lean */
+   f32 lean1, lean2 = animator->steer[0] * animator->reverse * -0.36f,
+       lean;
+
+   lean1 = animator->slide * animator->delayed_slip_dir;
+   if( fabsf(lean1)>fabsf(lean2) ) lean = lean1;
+   else                            lean = lean2;
+
+   if( ((int)roundf(animator->board_euler[0]/VG_PIf)) % 2 ) lean = -lean;
+   lean = vg_clampf( lean, -1.0f, 1.0f );
+   animator->board_lean = 
+      vg_lerpf(animator->board_lean, lean, vg.time_delta*18.0f);
+
    /* feet placement */
    struct player_board *board = 
       addon_cache_item_if_loaded( k_addon_type_board,
@@ -2811,6 +2830,10 @@ VG_STATIC void player__skate_animate( player_instance *player ){
    /* steer */
    joystick_state( k_srjoystick_steer, animator->steer );
 
+   animator->airdir = vg_lerpf( animator->airdir, -animator->steer[0],
+                                2.4f*vg.time_delta );
+      
+
    /* flip angle */
    if( (s->state.activity <= k_skate_activity_air_to_grind) &&
        (fabsf(s->state.flip_rate) > 0.01f) ){
@@ -2832,25 +2855,19 @@ VG_STATIC void player__skate_animate( player_instance *player ){
 
    /* counter-rotation */
    if( v3_length2( s->state.up_dir ) > 0.001f ){
-      if( v4_length(s->state.smoothed_rotation) <= 0.1f ||
-          v4_length(s->state.smoothed_rotation) >= 1.1f ){
-         vg_warn( "FIX THIS! CARROT\n" ); /* this never happens anymore? */
-         v4_copy( player->rb.q, s->state.smoothed_rotation );
-      }
       v4_lerp( s->state.smoothed_rotation, player->rb.q, 
                2.0f*vg.time_frame_delta,
                s->state.smoothed_rotation );
       q_normalize( s->state.smoothed_rotation );
 
-      v3f yaw_ref    = {1.0f,0.0f,0.0f}, 
-          yaw_smooth = {1.0f,0.0f,0.0f};
-      q_mulv( player->rb.q, yaw_ref, yaw_ref );
+      v3f yaw_smooth = {1.0f,0.0f,0.0f};
       q_mulv( s->state.smoothed_rotation, yaw_smooth, yaw_smooth );
       m3x3_mulv( player->rb.to_local, yaw_smooth, yaw_smooth );
-      m3x3_mulv( player->rb.to_local, yaw_ref, yaw_ref );
+      yaw_smooth[1] = 0.0f;
+      v3_normalize( yaw_smooth );
 
-      f32 yaw_counter_rotate  = v3_dot(yaw_ref,yaw_smooth);
-          yaw_counter_rotate  = vg_clampf(yaw_counter_rotate,-0.7f,0.7f);
+      f32 yaw_counter_rotate  = yaw_smooth[0];
+          yaw_counter_rotate  = vg_maxf( 0.7f, yaw_counter_rotate );
           yaw_counter_rotate  = acosf( yaw_counter_rotate );
           yaw_counter_rotate *= 1.0f-animator->fly;
 
@@ -2859,7 +2876,6 @@ VG_STATIC void player__skate_animate( player_instance *player ){
       v3_normalize( ndir );
 
       v3f up = { 0.0f, 1.0f, 0.0f };
-
       float a = v3_dot( ndir, up );
       a = acosf( vg_clampf( a, -1.0f, 1.0f ) );
 
@@ -2867,9 +2883,11 @@ VG_STATIC void player__skate_animate( player_instance *player ){
       v4f qcounteryaw, qfixup;
       
       v3_cross( up, ndir, axis );
-      q_axis_angle( qfixup, axis, a );
+      q_axis_angle( qfixup, axis, a*2.0f );
+
+      v3_cross( (v3f){1.0f,0.0f,0.0f}, yaw_smooth, axis );
+      q_axis_angle( qcounteryaw, axis, yaw_counter_rotate );
 
-      q_axis_angle( qcounteryaw, (v3f){0.0f,1.0f,0.0f}, yaw_counter_rotate );
       q_mul( qcounteryaw, qfixup, animator->qfixuptotal );
       q_normalize( animator->qfixuptotal );
 
@@ -2877,22 +2895,19 @@ VG_STATIC void player__skate_animate( player_instance *player ){
       m3x3_mulv( player->rb.to_world, up, p1 );
       m3x3_mulv( player->rb.to_world, ndir, p2 );
 
-      vg_line_arrow( player->rb.co, p1, 0.25f, VG__PINK );
-      vg_line_arrow( player->rb.co, p2, 0.25f, VG__PINK );
-
+      vg_line_arrow( player->rb.co, p1, 0.5f, VG__PINK );
+      vg_line_arrow( player->rb.co, p2, 0.5f, VG__PINK );
    }
    else q_identity( animator->qfixuptotal );
-   q_identity( animator->qfixuptotal );
    rb_extrapolate( &player->rb, animator->root_co, animator->root_q );
 }
                         
-VG_STATIC void player__skate_pose( player_instance *player ){
+VG_STATIC void player__skate_pose( player_instance *player, player_pose *pose ){
    struct player_avatar *av = player->playeravatar;
    struct skeleton *sk = &av->sk;
    struct player_skate *s = &player->_skate;
    struct player_skate_animator *animator = &s->animator;
-   player_pose *pose = &player->pose;
-   pose->type = k_player_pose_type_fk;
+   pose->type = k_player_pose_type_ik;
    v3_copy( animator->root_co, pose->root_co );
    v4_copy( animator->root_q, pose->root_q );
 
@@ -2923,17 +2938,7 @@ VG_STATIC void player__skate_pose( player_instance *player ){
       f32 dir_frame   = animator->z * (15.0f/30.0f),
           stand_blend = animator->offset[1]*-2.0f;
 
-      f32 lean1,
-          lean2 = animator->steer[0] * animator->reverse * -0.36f,
-          lean;
-
-      lean1 = animator->slide * animator->delayed_slip_dir;
-      if( fabsf(lean1)>fabsf(lean2) ) lean = lean1;
-      else                            lean = lean2;
-
-      if( ((int)roundf(animator->board_euler[0])) % 2 ) lean = -lean;
-      lean = vg_clampf( lean, -1.0f, 1.0f );
-      pose->board.lean = vg_lerpf(pose->board.lean, lean, vg.time_delta*18.0f);
+      pose->board.lean = animator->board_lean;
 
       stand_blend = vg_clampf( 1.0f-animator->local_cog[1], 0, 1 );
 
@@ -2964,10 +2969,6 @@ VG_STATIC void player__skate_pose( player_instance *player ){
    
    mdl_keyframe air_pose[32];
    {
-      float target = -animator->steer[1];
-      animator->airdir = vg_lerpf( animator->airdir, target, 
-                                   2.4f*vg.time_delta );
-      
       float air_frame = (animator->airdir*0.5f+0.5f) * (15.0f/30.0f);
       skeleton_sample_anim( sk, s->anim_air, air_frame, apose );
 
@@ -3057,14 +3058,19 @@ VG_STATIC void player__skate_pose( player_instance *player ){
 
    if( animator->trick_type == k_trick_type_kickflip ){
       kf_foot_l->co[0] += animator->trick_foot * 0.2f;
+      kf_foot_l->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[1] -= animator->trick_foot * 0.18f;
+      kf_foot_r->co[1] -= animator->trick_foot * 0.18f;
    }
    else if( animator->trick_type == k_trick_type_treflip ){
       kf_foot_l->co[0] += animator->trick_foot * 0.2f;
       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;
    }
 
    /* 
@@ -3085,6 +3091,7 @@ VG_STATIC void player__skate_pose( player_instance *player ){
       q_normalize( kf_wheels[i]->q );
    }
 
+#if 0
    {
       mdl_keyframe
          *kf_head    = &pose->keyframes[av->id_head-1],
@@ -3115,6 +3122,7 @@ VG_STATIC void player__skate_pose( player_instance *player ){
       q_mul( qrot, kf_head->q, kf_head->q );
       q_normalize( kf_head->q );
    }
+#endif
 }
 
 VG_STATIC void player__skate_post_animate( player_instance *player )