X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_common.c;h=5236ee5b9227c0358d0966f31e394236baa2725c;hb=refs%2Fheads%2Frigidbody;hp=203f52bc28e4500acfbe38a38f8442c8da909169;hpb=333430b27b5f9f73cbe9ad7921a4735aaff444f1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_common.c b/player_common.c index 203f52b..5236ee5 100644 --- a/player_common.c +++ b/player_common.c @@ -7,26 +7,9 @@ #include "menu.h" #include "vg/vg_perlin.h" -static void player_vector_angles( v3f angles, v3f v, float C, float k ){ - float yaw = atan2f( v[0], -v[2] ), - pitch = atan2f - ( - -v[1], - sqrtf - ( - v[0]*v[0] + v[2]*v[2] - ) - ) * C + k; - - angles[0] = yaw; - angles[1] = pitch; - angles[2] = 0.0f; -} - static float player_get_heading_yaw(void){ v3f xz; q_mulv( localplayer.rb.q, (v3f){ 0.0f,0.0f,1.0f }, xz ); - m3x3_mulv( localplayer.invbasis, xz, xz ); return atan2f( xz[0], xz[2] ); } @@ -39,27 +22,46 @@ static void player_camera_portal_correction(void){ f32 pol = v3_dot( localplayer.cam.pos, plane ) - plane[3]; - /* check camera polarity */ - if( (pol < 0.0f) || (pol > 5.0f) ) { + 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( &skaterift.replay, 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; - localplayer.viewable_world = world_current_instance(); - } - else{ - /* de-transform camera and player back */ - m4x3f inverse; - m4x3_invert_affine( localplayer.gate_waiting->transport, inverse ); - m4x3_mulv( inverse, localplayer.cam.pos, localplayer.cam.pos ); - - struct skeleton *sk = &localplayer.playeravatar->sk; - skeleton_apply_transform( sk, inverse, localplayer.final_mtx ); } } } static void player__cam_iterate(void){ - struct player_avatar *av = localplayer.playeravatar; struct player_cam_controller *cc = &localplayer.cam_control; if( localplayer.subsystem == k_player_subsystem_walk ){ @@ -67,6 +69,12 @@ static void player__cam_iterate(void){ 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 ); @@ -81,6 +89,16 @@ static void player__cam_iterate(void){ /* 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, @@ -127,7 +145,7 @@ static void player__cam_iterate(void){ /* position */ v3f fpv_pos, fpv_offset; - m4x3_mulv( localplayer.final_mtx[ av->id_head-1 ], + 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 ); @@ -137,11 +155,9 @@ static void player__cam_iterate(void){ v3_lerp( cc->cam_velocity_smooth, localplayer.rb.v, 4.0f*vg.time_frame_delta, cc->cam_velocity_smooth ); - v3f velocity_local; - m3x3_mulv( localplayer.invbasis, cc->cam_velocity_smooth, velocity_local ); - player_vector_angles( velocity_angles, velocity_local, - localplayer.cam_velocity_coefficient_smooth, - localplayer.cam_velocity_constant_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, @@ -163,7 +179,6 @@ static void player__cam_iterate(void){ v3f future; v3_muls( localplayer.rb.v, 0.4f*vg.time_frame_delta, future ); - m3x3_mulv( localplayer.invbasis, future, future ); v3f camera_follow_dir = { -sinf( localplayer.angles[0] ) * cosf( localplayer.angles[1] ), @@ -178,7 +193,7 @@ static void player__cam_iterate(void){ follow_angles[0] = atan2f( -v0[0], v0[2] ); follow_angles[1] = 0.3f + velocity_angles[1] * 0.2f; - float ya = atan2f( -velocity_local[1], 30.0f ); + float ya = atan2f( -cc->cam_velocity_smooth[1], 30.0f ); follow_angles[1] = 0.3f + ya; camera_lerp_angles( localplayer.angles, follow_angles, @@ -188,28 +203,25 @@ static void player__cam_iterate(void){ 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 */ - m3x3_mulv( localplayer.basis, camera_follow_dir, camera_follow_dir ); - v3_muls( camera_follow_dir, 1.8f, tpv_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 ); -#if 0 - 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 ); - } -#endif /* * Blend cameras @@ -242,7 +254,7 @@ static void player__cam_iterate(void){ ent_camera *cam = NULL; f32 min_dist = k_cinema; - world_instance *world = localplayer.viewable_world; + world_instance *world = world_current_instance(); for( u32 i=0; ient_camera); i++ ){ ent_camera *c = mdl_arritm(&world->ent_camera,i); @@ -260,9 +272,10 @@ static void player__cam_iterate(void){ v3f v0; if( k_cinema_fixed ) mdl_transform_vector( &cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 ); - else v3_sub( localplayer.rb.co, cam->transform.co, v0 ); - m3x3_mulv( localplayer.invbasis, v0, v0 ); - player_vector_angles( localplayer.cam.angles, v0, 1.0f, 0.0f ); + else + v3_sub( localplayer.rb.co, cam->transform.co, v0 ); + + v3_angles( v0, localplayer.cam.angles ); } }