X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_common.c;h=2ebec6c07c34c857abd3321044048c0710110ff6;hb=9eb3de757a997becb8406417a4bf613f4cb04900;hp=29ae05068a284d85a2c5fd013571232ae6d6878a;hpb=192990d6d24e53749ca046fef808a63cf162ab8a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_common.c b/player_common.c index 29ae050..2ebec6c 100644 --- a/player_common.c +++ b/player_common.c @@ -1,7 +1,11 @@ #ifndef PLAYER_COMMON_C #define PLAYER_COMMON_C +#include "ent_skateshop.h" #include "player.h" +#include "input.h" +#include "menu.h" +#include "vg/vg_perlin.h" VG_STATIC void player_vector_angles( v3f angles, v3f v, float C, float k ) { @@ -17,6 +21,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 ) @@ -29,23 +34,20 @@ VG_STATIC float player_get_heading_yaw( player_instance *player ) 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; 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(); + player->viewable_world = world_current_instance(); } - else - { + else{ /* de-transform camera and player back */ m4x3f inverse; m4x3_invert_affine( player->gate_waiting->transport, inverse ); @@ -57,21 +59,20 @@ VG_STATIC void player_camera_portal_correction( player_instance *player ) } } -VG_STATIC void player__cam_iterate( player_instance *player ) -{ +VG_STATIC void player__cam_iterate( player_instance *player ){ struct player_avatar *av = player->playeravatar; + struct player_cam_controller *cc = &player->cam_control; - 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 ); + if( player->subsystem == k_player_subsystem_walk ){ + v3_copy( (v3f){-0.1f,1.8f,0.0f}, cc->fpv_viewpoint ); + v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); + v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset ); } - else - { - v3_copy( (v3f){0.0f,1.8f,0.0f}, player->fpv_viewpoint ); - v3_copy( (v3f){-0.35f,0.0f,0.0f}, player->fpv_offset ); - v3_copy( (v3f){0.0f,1.4f,0.0f}, player->tpv_offset ); + else{ + v3_copy( (v3f){-0.15f,1.75f,0.0f}, cc->fpv_viewpoint ); + v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); + v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset ); + v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->tpv_offset ); } player->cam_velocity_constant = 0.25f; @@ -82,40 +83,42 @@ 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; + enum camera_mode target_mode = cc->camera_mode; if( player->subsystem == k_player_subsystem_dead ) target_mode = k_cam_thirdperson; - player->camera_type_blend = - vg_lerpf( player->camera_type_blend, - (target_mode == k_cam_firstperson)? 1.0f: 0.0f, - 5.0f * vg.frame_delta ); + cc->camera_type_blend = + vg_lerpf( cc->camera_type_blend, + (target_mode == k_cam_firstperson)? 1.0f: 0.0f, + 5.0f * vg.time_frame_delta ); - v3_lerp( player->fpv_viewpoint_smooth, player->fpv_viewpoint, - vg.frame_delta * 8.0f, player->fpv_viewpoint_smooth ); + v3_lerp( cc->fpv_viewpoint_smooth, cc->fpv_viewpoint, + vg.time_frame_delta * 8.0f, cc->fpv_viewpoint_smooth ); - v3_lerp( player->fpv_offset_smooth, player->fpv_offset, - vg.frame_delta * 8.0f, player->fpv_offset_smooth ); + v3_lerp( cc->fpv_offset_smooth, cc->fpv_offset, + vg.time_frame_delta * 8.0f, cc->fpv_offset_smooth ); - v3_lerp( player->tpv_offset_smooth, player->tpv_offset, - vg.frame_delta * 8.0f, player->tpv_offset_smooth ); + v3_lerp( cc->tpv_offset_smooth, cc->tpv_offset, + vg.time_frame_delta * 8.0f, cc->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, k_fov ), + fov_walk = vg_lerpf( 90.0f, 110.0f, k_fov ); + + player->cam.fov = vg_lerpf( fov_walk, fov_skate, cc->camera_type_blend ); /* * first person camera @@ -124,25 +127,24 @@ VG_STATIC void player__cam_iterate( player_instance *player ) /* position */ v3f fpv_pos, fpv_offset; m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ], - player->fpv_viewpoint_smooth, fpv_pos ); - m3x3_mulv( player->rb.to_world, player->fpv_offset_smooth, fpv_offset ); + cc->fpv_viewpoint_smooth, fpv_pos ); + m3x3_mulv( player->rb.to_world, cc->fpv_offset_smooth, fpv_offset ); v3_add( fpv_offset, fpv_pos, fpv_pos ); /* angles */ v3f velocity_angles; - v3_lerp( player->cam_velocity_smooth, player->rb.v, 4.0f*vg.frame_delta, - player->cam_velocity_smooth ); + v3_lerp( cc->cam_velocity_smooth, player->rb.v, 4.0f*vg.time_frame_delta, + cc->cam_velocity_smooth ); v3f velocity_local; - m3x3_mulv( player->invbasis, player->cam_velocity_smooth, velocity_local ); + m3x3_mulv( player->invbasis, cc->cam_velocity_smooth, velocity_local ); player_vector_angles( velocity_angles, velocity_local, player->cam_velocity_coefficient_smooth, player->cam_velocity_constant_smooth ); - float inf_fpv = player->cam_velocity_influence_smooth * - player->camera_type_blend, + float inf_fpv = player->cam_velocity_influence_smooth * cc->camera_type_blend, inf_tpv = player->cam_velocity_influence_smooth * - (1.0f-player->camera_type_blend); + (1.0f-cc->camera_type_blend); camera_lerp_angles( player->angles, velocity_angles, inf_fpv, @@ -158,7 +160,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 = @@ -184,31 +186,92 @@ 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( cc->tpv_lpf, pco, 20.0f*vg.time_frame_delta, cc->tpv_lpf ); /* now move into world */ + v3f tpv_pos, tpv_offset, tpv_origin; - m3x3_mulv( player->basis, camera_follow_dir, camera_follow_dir ); - v3f tpv_pos, tpv_offset; + /* origin */ + q_mulv( pq, cc->tpv_offset_smooth, tpv_origin ); + v3_add( tpv_origin, cc->tpv_lpf, tpv_origin ); - 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 ); + /* offset */ + m3x3_mulv( player->basis, camera_follow_dir, camera_follow_dir ); + v3_muls( camera_follow_dir, 1.8f, tpv_offset ); + v3_muladds( tpv_offset, cc->cam_velocity_smooth, -0.025f, tpv_offset ); + + v3_add( tpv_origin, tpv_offset, tpv_pos ); + f32 t; v3f n; + if( spherecast_world( world_current_instance(), tpv_origin, tpv_pos, + 0.2f, &t, n ) != -1 ){ + v3_lerp( tpv_origin, tpv_pos, t, tpv_pos ); + } /* * Blend cameras */ - - v3_lerp( tpv_pos, fpv_pos, player->camera_type_blend, player->cam.pos ); + v3_lerp( tpv_pos, fpv_pos, cc->camera_type_blend, player->cam.pos ); v3_copy( player->angles, player->cam.angles ); + /* Camera shake */ + f32 speed = v3_length(player->rb.v), + strength = k_cam_shake_strength * speed; + player->cam_trackshake += speed*k_cam_shake_trackspeed*vg.time_frame_delta; + + v2f rnd = {perlin1d( player->cam_trackshake, 1.0f, 4, 20 ), + perlin1d( player->cam_trackshake, 1.0f, 4, 63 ) }; + v2_muladds( player->cam.angles, rnd, strength, player->cam.angles ); + + v3f Fd, Fs, F; + v3_muls( player->cam_land_punch_v, -k_cam_damp, Fd ); + v3_muls( player->cam_land_punch, -k_cam_spring, Fs ); + v3_muladds( player->cam_land_punch, player->cam_land_punch_v, + vg.time_frame_delta, player->cam_land_punch ); + v3_add( Fd, Fs, F ); + v3_muladds( player->cam_land_punch_v, F, vg.time_frame_delta, + player->cam_land_punch_v ); + v3_add( player->cam_land_punch, player->cam.pos, player->cam.pos ); + + /* 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 ); + player->cam.fov = vg_lerpf( player->cam.fov, player->cam_override_fov, + player->cam_override_strength ); + + + if( k_cinema >= 0.0001f ){ + ent_camera *cam = NULL; + f32 min_dist = k_cinema; + + world_instance *world = player->viewable_world; + for( u32 i=0; ient_camera); i++ ){ + ent_camera *c = mdl_arritm(&world->ent_camera,i); + + f32 dist = v3_dist( c->transform.co, player->rb.co ); + + if( dist < min_dist ){ + min_dist = dist; + cam = c; + } + } - 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.angles[1] += player->cam_land_punch; + if( cam ){ + player->cam.fov = cam->fov; + v3_copy( cam->transform.co, player->cam.pos ); + v3f v0; + if( k_cinema_fixed ) + mdl_transform_vector( &cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 ); + else v3_sub( player->rb.co, cam->transform.co, v0 ); + m3x3_mulv( player->invbasis, v0, v0 ); + player_vector_angles( player->cam.angles, v0, 1.0f, 0.0f ); + } + } /* portal transitions */ player_camera_portal_correction( player ); @@ -216,39 +279,25 @@ 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_ui.wants_mouse ) return; - if( vg_input.controller_should_use_trackpad_look ) - { - static v2f last_input; - static v2f vel; - static v2f vel_smooth; + float sensitivity = skaterift.time_rate; - v2f input = { player->input_js2h->axis.value, - player->input_js2v->axis.value }; + angles[2] = 0.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 - { - v2_zero( vel ); - } + v2f mouse_input; + v2_copy( vg.mouse_delta, mouse_input ); + if( k_invert_y ) mouse_input[1] *= -1.0f; + v2_muladds( angles, mouse_input, 0.0025f * sensitivity, angles ); - v2_lerp( vel_smooth, vel, vg.time_delta*8.0f, vel_smooth ); - - v2_muladds( angles, vel_smooth, vg.time_delta, angles ); - v2_copy( input, last_input ); - } - 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; - } + v2f jlook; + joystick_state( k_srjoystick_look, jlook ); + + angles[0] += jlook[0] * vg.time_delta * 4.0f * sensitivity; + float input_y = jlook[1] * vg.time_delta * 4.0f; + if( k_invert_y ) input_y *= -1.0f; + angles[1] += input_y * sensitivity; angles[1] = vg_clampf( angles[1], -VG_PIf*0.5f, VG_PIf*0.5f ); }