X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_common.c;h=29ae05068a284d85a2c5fd013571232ae6d6878a;hb=a9e3181f697ab37fc74f072cfcfdf44e2d659468;hp=017aa148a02fe1ca43cd3925d9812d8015111c90;hpb=06e5d59a9b7fdd96a2e46f49be85089b43df75ae;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_common.c b/player_common.c index 017aa14..29ae050 100644 --- a/player_common.c +++ b/player_common.c @@ -23,6 +23,7 @@ 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] ); } @@ -32,8 +33,8 @@ VG_STATIC void player_camera_portal_correction( player_instance *player ) { /* 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] ) @@ -41,6 +42,7 @@ VG_STATIC void player_camera_portal_correction( player_instance *player ) 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 { @@ -49,13 +51,6 @@ VG_STATIC void player_camera_portal_correction( player_instance *player ) 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 ); } @@ -99,9 +94,14 @@ VG_STATIC void player__cam_iterate( player_instance *player ) player->cam_velocity_constant, vg.frame_delta * 8.0f ); + enum camera_mode target_mode = player->camera_mode; + + if( player->subsystem == k_player_subsystem_dead ) + target_mode = k_cam_thirdperson; + player->camera_type_blend = vg_lerpf( player->camera_type_blend, - (player->camera_mode == k_cam_firstperson)? 1.0f: 0.0f, + (target_mode == k_cam_firstperson)? 1.0f: 0.0f, 5.0f * vg.frame_delta ); v3_lerp( player->fpv_viewpoint_smooth, player->fpv_viewpoint, @@ -132,7 +132,10 @@ VG_STATIC void player__cam_iterate( player_instance *player ) v3f velocity_angles; v3_lerp( player->cam_velocity_smooth, player->rb.v, 4.0f*vg.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 ); @@ -150,10 +153,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 ); + m3x3_mulv( player->invbasis, future, future ); v3f camera_follow_dir = { -sinf( player->angles[0] ) * cosf( player->angles[1] ), @@ -168,14 +174,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 ); @@ -185,13 +186,16 @@ VG_STATIC void player__cam_iterate( player_instance *player ) rb_extrapolate( &player->rb, pco, pq ); v3_lerp( player->tpv_lpf, pco, 20.0f*vg.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 */