clean boardshop idea
[carveJwlIkooP6JGAAIwe30JlM.git] / player_common.c
index 259a7987fc6bd5adda266765ce0834fe58f8c6a0..4991d231a31f00671635c154c246f9d0b1643e87 100644 (file)
@@ -2,6 +2,11 @@
 #define PLAYER_COMMON_C
 
 #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 )
 {
@@ -17,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 )
@@ -83,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;
 
@@ -103,20 +109,22 @@ 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 */
-   /* FIXME: cl_fov */
-   player->cam.fov = vg_lerpf( 97.0f, 128.0f, player->camera_type_blend );
+   float fov_skate = vg_lerpf( 97.0f, 135.0f, cl_fov ),
+         fov_walk  = vg_lerpf( 90.0f, 110.0f, cl_fov );
+
+   player->cam.fov = vg_lerpf( fov_walk, fov_skate, player->camera_type_blend );
 
    /* 
     * first person camera
@@ -131,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;
@@ -159,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 = 
@@ -185,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 */
 
@@ -205,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 */
@@ -218,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 );
@@ -226,7 +236,12 @@ VG_STATIC void player__cam_iterate( player_instance *player )
 VG_STATIC void player_look( player_instance *player, v3f angles )
 {
    angles[2] = 0.0f;
-   v2_muladds( angles, vg.mouse_delta, 0.0025f, angles );
+
+   v2f mouse_input;
+   v2_copy( vg.mouse_delta, mouse_input );
+   if( cl_invert_y )
+      mouse_input[1] *= -1.0f;
+   v2_muladds( angles, mouse_input, 0.0025f, angles );
 
    if( vg_input.controller_should_use_trackpad_look ){
       static v2f last_input;
@@ -236,6 +251,9 @@ VG_STATIC void player_look( player_instance *player, v3f angles )
       v2f input = { player->input_js2h->axis.value,
                     player->input_js2v->axis.value };
 
+      if( cl_invert_y )
+         input[1] *= -1.0f;
+
       if( (v2_length2(last_input) > 0.001f) && (v2_length2(input) > 0.001f) ){
          v2_sub( input, last_input, vel );
          v2_muls( vel, 1.0f/vg.time_delta, vel );
@@ -251,7 +269,12 @@ VG_STATIC void player_look( player_instance *player, v3f angles )
    }
    else{
       angles[0] += player->input_js2h->axis.value * vg.time_delta * 4.0f;
-      angles[1] += player->input_js2v->axis.value * vg.time_delta * 4.0f;
+
+      float input_y = player->input_js2v->axis.value * vg.time_delta * 4.0f;
+      if( cl_invert_y )
+         input_y *= -1.0f;
+
+      angles[1] += input_y;
    }
 
    angles[1] = vg_clampf( angles[1], -VG_PIf*0.5f, VG_PIf*0.5f );