clean boardshop idea
[carveJwlIkooP6JGAAIwe30JlM.git] / player_common.c
index 432fbaec639b39ab6025b6523997213488def673..4991d231a31f00671635c154c246f9d0b1643e87 100644 (file)
@@ -4,6 +4,10 @@
 #include "player.h"
 #include "conf.h"
 
+VG_STATIC float
+   k_cam_spring            = 20.0f,
+   k_cam_damp              = 6.7f;
+
 VG_STATIC void player_vector_angles( v3f angles, v3f v, float C, float k )
 {
    float yaw = atan2f( v[0], -v[2] ),
@@ -18,6 +22,7 @@ VG_STATIC void player_vector_angles( v3f angles, v3f v, float C, float k )
 
    angles[0] = yaw;
    angles[1] = pitch;
+   angles[2] = 0.0f;
 }
 
 VG_STATIC float player_get_heading_yaw( player_instance *player )
@@ -84,17 +89,17 @@ VG_STATIC void player__cam_iterate( player_instance *player )
    player->cam_velocity_influence_smooth = vg_lerpf(
          player->cam_velocity_influence_smooth, 
          player->cam_velocity_influence,
-         vg.frame_delta * 8.0f );
+         vg.time_frame_delta * 8.0f );
 
    player->cam_velocity_coefficient_smooth = vg_lerpf(
          player->cam_velocity_coefficient_smooth,
          player->cam_velocity_coefficient,
-         vg.frame_delta * 8.0f );
+         vg.time_frame_delta * 8.0f );
 
    player->cam_velocity_constant_smooth = vg_lerpf(
          player->cam_velocity_constant_smooth,
          player->cam_velocity_constant,
-         vg.frame_delta * 8.0f );
+         vg.time_frame_delta * 8.0f );
 
    enum camera_mode target_mode = player->camera_mode;
 
@@ -104,16 +109,16 @@ VG_STATIC void player__cam_iterate( player_instance *player )
    player->camera_type_blend = 
       vg_lerpf( player->camera_type_blend, 
                 (target_mode == k_cam_firstperson)? 1.0f: 0.0f,
-                5.0f * vg.frame_delta );
+                5.0f * vg.time_frame_delta );
 
    v3_lerp( player->fpv_viewpoint_smooth, player->fpv_viewpoint,
-         vg.frame_delta * 8.0f, player->fpv_viewpoint_smooth );
+         vg.time_frame_delta * 8.0f, player->fpv_viewpoint_smooth );
 
    v3_lerp( player->fpv_offset_smooth, player->fpv_offset,
-         vg.frame_delta * 8.0f, player->fpv_offset_smooth );
+         vg.time_frame_delta * 8.0f, player->fpv_offset_smooth );
 
    v3_lerp( player->tpv_offset_smooth, player->tpv_offset,
-         vg.frame_delta * 8.0f, player->tpv_offset_smooth );
+         vg.time_frame_delta * 8.0f, player->tpv_offset_smooth );
 
    /* fov -- simple blend */
    float fov_skate = vg_lerpf( 97.0f, 135.0f, cl_fov ),
@@ -134,7 +139,7 @@ VG_STATIC void player__cam_iterate( player_instance *player )
 
    /* angles */
    v3f velocity_angles;
-   v3_lerp( player->cam_velocity_smooth, player->rb.v, 4.0f*vg.frame_delta, 
+   v3_lerp( player->cam_velocity_smooth, player->rb.v, 4.0f*vg.time_frame_delta, 
             player->cam_velocity_smooth );
 
    v3f velocity_local;
@@ -162,7 +167,7 @@ VG_STATIC void player__cam_iterate( player_instance *player )
     * it is done in the local basis then transformed back */
 
    v3f future;
-   v3_muls( player->rb.v, 0.4f*vg.frame_delta, future );
+   v3_muls( player->rb.v, 0.4f*vg.time_frame_delta, future );
    m3x3_mulv( player->invbasis, future, future );
 
    v3f camera_follow_dir = 
@@ -188,7 +193,7 @@ VG_STATIC void player__cam_iterate( player_instance *player )
    v3f pco;
    v4f pq;
    rb_extrapolate( &player->rb, pco, pq );
-   v3_lerp( player->tpv_lpf, pco, 20.0f*vg.frame_delta, player->tpv_lpf );
+   v3_lerp( player->tpv_lpf, pco, 20.0f*vg.time_frame_delta, player->tpv_lpf );
 
    /* now move into world */
 
@@ -208,8 +213,8 @@ VG_STATIC void player__cam_iterate( player_instance *player )
 
    float Fd = -player->cam_land_punch_v * k_cam_damp,
          Fs = -player->cam_land_punch   * k_cam_spring;
-   player->cam_land_punch   += player->cam_land_punch_v * vg.frame_delta;
-   player->cam_land_punch_v += ( Fd + Fs ) * vg.frame_delta;
+   player->cam_land_punch   += player->cam_land_punch_v * vg.time_frame_delta;
+   player->cam_land_punch_v += ( Fd + Fs ) * vg.time_frame_delta;
    player->cam.angles[1] += player->cam_land_punch;
 
    /* override camera */
@@ -221,6 +226,8 @@ VG_STATIC void player__cam_iterate( player_instance *player )
                  player->cam_override_strength );
    v3_lerp( player->cam.pos, player->cam_override_pos, 
             player->cam_override_strength, player->cam.pos );
+   player->cam.fov = vg_lerpf( player->cam.fov, player->cam_override_fov, 
+                               player->cam_override_strength );
 
    /* portal transitions */
    player_camera_portal_correction( player );