X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_common.c;h=6ab378d6039d8317ea3cbdc774a7c9bb168f4155;hb=HEAD;hp=e1961b91a984cf0f9cc096d3895d6cc17f0b141b;hpb=14851c4c820eb07a0db0ec0366a70bdd6518c331;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_common.c b/player_common.c deleted file mode 100644 index e1961b9..0000000 --- a/player_common.c +++ /dev/null @@ -1,278 +0,0 @@ -#include "ent_skateshop.h" -#include "player.h" -#include "input.h" -#include "menu.h" -#include "vg/vg_perlin.h" - -float player_get_heading_yaw(void) -{ - v3f xz; - q_mulv( localplayer.rb.q, (v3f){ 0.0f,0.0f,1.0f }, xz ); - return atan2f( xz[0], xz[2] ); -} - -static void player_camera_portal_correction(void) -{ - if( localplayer.gate_waiting ){ - /* construct plane equation for reciever gate */ - v4f plane; - q_mulv( localplayer.gate_waiting->q[1], (v3f){0.0f,0.0f,1.0f}, plane ); - plane[3] = v3_dot( plane, localplayer.gate_waiting->co[1] ); - - f32 pol = v3_dot( localplayer.cam.pos, plane ) - plane[3]; - - int cleared = (pol < 0.0f) || (pol > 5.0f); - - if( cleared ){ - vg_success( "Plane cleared\n" ); - } - - m4x3f inverse; - m4x3_invert_affine( localplayer.gate_waiting->transport, inverse ); - - /* de-transform camera and player back */ - v3f v0; - m4x3_mulv( inverse, localplayer.cam.pos, localplayer.cam.pos ); - v3_angles_vector( localplayer.cam.angles, v0 ); - m3x3_mulv( inverse, v0, v0 ); - v3_angles( v0, localplayer.cam.angles ); - - skeleton_apply_transform( &localplayer.skeleton, inverse, - localplayer.final_mtx ); - - /* record and re-put things again */ - if( cleared ) - { - skaterift_record_frame( &player_replay.local, 1 ); - localplayer.deferred_frame_record = 1; - - skeleton_apply_transform( &localplayer.skeleton, - localplayer.gate_waiting->transport, - localplayer.final_mtx ); - - m4x3_mulv( localplayer.gate_waiting->transport, - localplayer.cam.pos, localplayer.cam.pos ); - v3_angles_vector( localplayer.cam.angles, v0 ); - m3x3_mulv( localplayer.gate_waiting->transport, v0, v0 ); - v3_angles( v0, localplayer.cam.angles ); - player_apply_transport_to_cam( localplayer.gate_waiting->transport ); - localplayer.gate_waiting = NULL; - } - } -} - -void player__cam_iterate(void) -{ - struct player_cam_controller *cc = &localplayer.cam_control; - - if( localplayer.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 if( localplayer.subsystem == k_player_subsystem_glide ){ - 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.0f,0.0f}, cc->tpv_offset ); - v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->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 ); - - f32 h = vg_lerpf( 0.4f, 1.4f, k_cam_height ); - v3_copy( (v3f){0.0f,h,0.0f}, cc->tpv_offset ); - v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->tpv_offset ); - } - - localplayer.cam_velocity_constant = 0.25f; - localplayer.cam_velocity_coefficient = 0.7f; - - /* lerping */ - - if( localplayer.cam_dist_smooth == 0.0f ){ - localplayer.cam_dist_smooth = localplayer.cam_dist; - } - else { - localplayer.cam_dist_smooth = vg_lerpf( - localplayer.cam_dist_smooth, - localplayer.cam_dist, - vg.time_frame_delta * 8.0f ); - } - - localplayer.cam_velocity_influence_smooth = vg_lerpf( - localplayer.cam_velocity_influence_smooth, - localplayer.cam_velocity_influence, - vg.time_frame_delta * 8.0f ); - - localplayer.cam_velocity_coefficient_smooth = vg_lerpf( - localplayer.cam_velocity_coefficient_smooth, - localplayer.cam_velocity_coefficient, - vg.time_frame_delta * 8.0f ); - - localplayer.cam_velocity_constant_smooth = vg_lerpf( - localplayer.cam_velocity_constant_smooth, - localplayer.cam_velocity_constant, - vg.time_frame_delta * 8.0f ); - - enum camera_mode target_mode = cc->camera_mode; - - if( localplayer.subsystem == k_player_subsystem_dead ) - target_mode = k_cam_thirdperson; - - 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( cc->fpv_viewpoint_smooth, cc->fpv_viewpoint, - vg.time_frame_delta * 8.0f, cc->fpv_viewpoint_smooth ); - - v3_lerp( cc->fpv_offset_smooth, cc->fpv_offset, - vg.time_frame_delta * 8.0f, cc->fpv_offset_smooth ); - - v3_lerp( cc->tpv_offset_smooth, cc->tpv_offset, - vg.time_frame_delta * 8.0f, cc->tpv_offset_smooth ); - - /* fov -- simple blend */ - float fov_skate = vg_lerpf( 97.0f, 135.0f, k_fov ), - fov_walk = vg_lerpf( 90.0f, 110.0f, k_fov ); - - localplayer.cam.fov = vg_lerpf( fov_walk, fov_skate, cc->camera_type_blend ); - - /* - * first person camera - */ - - /* position */ - v3f fpv_pos, fpv_offset; - m4x3_mulv( localplayer.final_mtx[ localplayer.id_head-1 ], - cc->fpv_viewpoint_smooth, fpv_pos ); - m3x3_mulv( localplayer.rb.to_world, cc->fpv_offset_smooth, fpv_offset ); - v3_add( fpv_offset, fpv_pos, fpv_pos ); - - /* angles */ - v3f velocity_angles; - v3_lerp( cc->cam_velocity_smooth, localplayer.rb.v, 4.0f*vg.time_frame_delta, - cc->cam_velocity_smooth ); - - v3_angles( cc->cam_velocity_smooth, velocity_angles ); - velocity_angles[1] *= localplayer.cam_velocity_coefficient_smooth; - velocity_angles[1] += localplayer.cam_velocity_constant_smooth; - - float inf_fpv = localplayer.cam_velocity_influence_smooth * - cc->camera_type_blend, - inf_tpv = localplayer.cam_velocity_influence_smooth * - (1.0f-cc->camera_type_blend); - - vg_camera_lerp_angles( localplayer.angles, velocity_angles, - inf_fpv, - localplayer.angles ); - - /* - * Third person camera - */ - - /* no idea what this technique is called, it acts like clamped position based - * 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( localplayer.rb.v, 0.4f*vg.time_frame_delta, future ); - - v3f camera_follow_dir = - { -sinf( localplayer.angles[0] ) * cosf( localplayer.angles[1] ), - sinf( localplayer.angles[1] ), - cosf( localplayer.angles[0] ) * cosf( localplayer.angles[1] ) }; - - v3f v0; - v3_sub( camera_follow_dir, future, v0 ); - - v3f follow_angles; - v3_copy( localplayer.angles, follow_angles ); - follow_angles[0] = atan2f( -v0[0], v0[2] ); - follow_angles[1] = 0.3f + velocity_angles[1] * 0.2f; - - float ya = atan2f( -cc->cam_velocity_smooth[1], 30.0f ); - - follow_angles[1] = 0.3f + ya; - vg_camera_lerp_angles( localplayer.angles, follow_angles, - inf_tpv, - localplayer.angles ); - - v3f pco; - v4f pq; - rb_extrapolate( &localplayer.rb, pco, pq ); - v3_muladds( pco, localplayer.holdout_pose.root_co, - localplayer.holdout_time, pco ); - 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; - - /* TODO: whats up with CC and not CC but both sets of variables are doing - * the same ideas just saved in different places? - */ - /* origin */ - q_mulv( pq, cc->tpv_offset_smooth, tpv_origin ); - v3_add( tpv_origin, cc->tpv_lpf, tpv_origin ); - - /* offset */ - v3_muls( camera_follow_dir, localplayer.cam_dist_smooth, tpv_offset ); - v3_muladds( tpv_offset, cc->cam_velocity_smooth, -0.025f, tpv_offset ); - - v3_add( tpv_origin, tpv_offset, tpv_pos ); - - /* - * Blend cameras - */ - v3_lerp( tpv_pos, fpv_pos, cc->camera_type_blend, localplayer.cam.pos ); - v3_copy( localplayer.angles, localplayer.cam.angles ); - - /* Camera shake */ - f32 speed = v3_length(localplayer.rb.v), - strength = k_cam_shake_strength * speed; - localplayer.cam_trackshake += - speed*k_cam_shake_trackspeed*vg.time_frame_delta; - - v2f rnd = {vg_perlin_fract_1d( localplayer.cam_trackshake, 1.0f, 4, 20 ), - vg_perlin_fract_1d( localplayer.cam_trackshake, 1.0f, 4, 63 ) }; - v2_muladds( localplayer.cam.angles, rnd, strength, localplayer.cam.angles ); - - v3f Fd, Fs, F; - v3_muls( localplayer.cam_land_punch_v, -k_cam_damp, Fd ); - v3_muls( localplayer.cam_land_punch, -k_cam_spring, Fs ); - v3_muladds( localplayer.cam_land_punch, localplayer.cam_land_punch_v, - vg.time_frame_delta, localplayer.cam_land_punch ); - v3_add( Fd, Fs, F ); - v3_muladds( localplayer.cam_land_punch_v, F, vg.time_frame_delta, - localplayer.cam_land_punch_v ); - v3_add( localplayer.cam_land_punch, localplayer.cam.pos, - localplayer.cam.pos ); - - /* portal transitions */ - player_camera_portal_correction(); -} - -void player_look( v3f angles, float speed ) -{ - if( vg_ui.wants_mouse ) return; - - angles[2] = 0.0f; - - 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 * speed, angles ); - - v2f jlook; - joystick_state( k_srjoystick_look, jlook ); - - angles[0] += jlook[0] * vg.time_frame_delta * 4.0f * speed; - float input_y = jlook[1] * vg.time_frame_delta * 4.0f; - if( k_invert_y ) input_y *= -1.0f; - - angles[1] += input_y * speed; - angles[1] = vg_clampf( angles[1], -VG_PIf*0.5f, VG_PIf*0.5f ); -}