X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_common.c;h=21d52aa76871c6f978d10f3bda4334ae614e5671;hb=8c376ed2e4021a18b0a6c6e800109d67ad09d198;hp=3ce7c9cdc7d6143aaf52c77a8f6dc49e81ba0abf;hpb=c4c762ce6f3bbdcb770bbc42e349aebbc3390d9d;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_common.c b/player_common.c index 3ce7c9c..21d52aa 100644 --- a/player_common.c +++ b/player_common.c @@ -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,66 +22,63 @@ 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 ) { v3f xz; q_mulv( player->rb.q, (v3f){ 0.0f,0.0f,1.0f }, xz ); + m3x3_mulv( player->invbasis, xz, xz ); return atan2f( xz[0], xz[2] ); } VG_STATIC void player_camera_portal_correction( player_instance *player ) { - if( player->gate_waiting ) - { + if( player->gate_waiting ){ /* construct plane equation for reciever gate */ v4f plane; - v3_copy( player->gate_waiting->recv_to_world[2], plane ); - plane[3] = v3_dot( plane, player->gate_waiting->recv_to_world[3] ); + q_mulv( player->gate_waiting->q[1], (v3f){0.0f,0.0f,1.0f}, plane ); + plane[3] = v3_dot( plane, player->gate_waiting->co[1] ); /* check camera polarity */ - if( v3_dot( player->cam.pos, plane ) < plane[3] ) - { + if( v3_dot( player->cam.pos, plane ) < plane[3] ) { vg_success( "Plane cleared\n" ); player_apply_transport_to_cam( player->gate_waiting->transport ); player->gate_waiting = NULL; + player->viewable_world = get_active_world(); } - else - { + else{ /* de-transform camera and player back */ m4x3f inverse; m4x3_invert_affine( player->gate_waiting->transport, inverse ); m4x3_mulv( inverse, player->cam.pos, player->cam.pos ); - /* TODO: Find robust method for this */ - v3f fwd_dir = { cosf(player->cam.angles[0]), - 0.0f, - sinf(player->cam.angles[0])}; - m3x3_mulv( inverse, fwd_dir, fwd_dir ); - player->cam.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] ); - struct skeleton *sk = &player->playeravatar->sk; skeleton_apply_transform( sk, inverse ); } } } +static v3f TEMP_TPV_EXTRA; + VG_STATIC void player__cam_iterate( player_instance *player ) { struct player_avatar *av = player->playeravatar; - if( player->subsystem == k_player_subsystem_walk ) - { + if( player->subsystem == k_player_subsystem_walk ){ v3_copy( (v3f){-0.1f,1.8f,0.0f}, player->fpv_viewpoint ); v3_copy( (v3f){0.0f,0.0f,0.0f}, player->fpv_offset ); v3_copy( (v3f){0.0f,1.4f,0.0f}, player->tpv_offset ); } - else - { - v3_copy( (v3f){0.0f,1.8f,0.0f}, player->fpv_viewpoint ); + else{ + v3_copy( (v3f){-0.15f,1.75f,0.0f}, player->fpv_viewpoint ); +#if 0 v3_copy( (v3f){-0.35f,0.0f,0.0f}, player->fpv_offset ); +#endif + v3_copy( (v3f){0.0f,0.0f,0.0f}, player->fpv_offset ); v3_copy( (v3f){0.0f,1.4f,0.0f}, player->tpv_offset ); + v3_add( TEMP_TPV_EXTRA, player->tpv_offset, player->tpv_offset ); } player->cam_velocity_constant = 0.25f; @@ -87,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; @@ -107,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, 118.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 @@ -135,9 +139,12 @@ 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 ); - player_vector_angles( velocity_angles, player->cam_velocity_smooth, + + v3f velocity_local; + m3x3_mulv( player->invbasis, player->cam_velocity_smooth, velocity_local ); + player_vector_angles( velocity_angles, velocity_local, player->cam_velocity_coefficient_smooth, player->cam_velocity_constant_smooth ); @@ -155,10 +162,13 @@ VG_STATIC void player__cam_iterate( player_instance *player ) */ /* no idea what this technique is called, it acts like clamped position based - * on some derivative of where the final camera would end up .... */ + * on some derivative of where the final camera would end up .... + * + * 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 = { -sinf( player->angles[0] ) * cosf( player->angles[1] ), @@ -173,14 +183,9 @@ VG_STATIC void player__cam_iterate( player_instance *player ) follow_angles[0] = atan2f( -v0[0], v0[2] ); follow_angles[1] = 0.3f + velocity_angles[1] * 0.2f; - float ya = atan2f - ( - -player->cam_velocity_smooth[1], - 30.0f - ); + float ya = atan2f( -velocity_local[1], 30.0f ); follow_angles[1] = 0.3f + ya; - camera_lerp_angles( player->angles, follow_angles, inf_tpv, player->angles ); @@ -188,29 +193,40 @@ 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 */ + m3x3_mulv( player->basis, camera_follow_dir, camera_follow_dir ); v3f tpv_pos, tpv_offset; + v3_muladds( player->tpv_lpf, camera_follow_dir, 1.8f, tpv_pos ); q_mulv( pq, player->tpv_offset_smooth, tpv_offset ); v3_add( tpv_offset, tpv_pos, tpv_pos ); v3_muladds( tpv_pos, player->cam_velocity_smooth, -0.025f, tpv_pos ); - /* * Blend cameras */ - v3_lerp( tpv_pos, fpv_pos, player->camera_type_blend, player->cam.pos ); v3_copy( player->angles, player->cam.angles ); - 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 */ + player->cam.angles[0] = + vg_alerpf( player->cam.angles[0], player->cam_override_angles[0], + player->cam_override_strength ); + player->cam.angles[1] = + vg_lerpf ( player->cam.angles[1], player->cam_override_angles[1], + player->cam_override_strength ); + v3_lerp( player->cam.pos, player->cam_override_pos, + player->cam_override_strength, player->cam.pos ); + /* portal transitions */ player_camera_portal_correction( player ); } @@ -218,10 +234,14 @@ 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 ); - if( vg_input.controller_should_use_trackpad_look ) - { + 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; static v2f vel; static v2f vel_smooth; @@ -229,13 +249,14 @@ VG_STATIC void player_look( player_instance *player, v3f angles ) v2f input = { player->input_js2h->axis.value, player->input_js2v->axis.value }; - if( (v2_length2(last_input) > 0.001f) && (v2_length2(input) > 0.001f) ) - { + 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 ); } - else - { + else{ v2_zero( vel ); } @@ -244,10 +265,14 @@ VG_STATIC void player_look( player_instance *player, v3f angles ) v2_muladds( angles, vel_smooth, vg.time_delta, angles ); v2_copy( input, last_input ); } - else - { + 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 );