X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_animation.h;h=98aa25697e1e2c843c0566885a8dbff4c83e7ee7;hb=cbce8a9ec86c6f061c292eec1855eacafc6a3a4f;hp=b9e28de2b5ad10398acc75fc666fba18fb1efdcb;hpb=147ecb98ce2d6a2b24b0d86436913a46888dea84;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_animation.h b/player_animation.h index b9e28de..98aa256 100644 --- a/player_animation.h +++ b/player_animation.h @@ -161,7 +161,7 @@ VG_STATIC void player_animate(void) { float dirz = phys->reverse > 0.0f? 0.0f: 1.0f, dirx = phys->slip < 0.0f? 0.0f: 1.0f, - fly = phys->in_air? 1.0f: 0.0f; + fly = (phys->in_air|phys->grind)? 1.0f: 0.0f; player.fdirz = vg_lerpf( player.fdirz, dirz, 2.4f*vg.time_delta ); player.fdirx = vg_lerpf( player.fdirx, dirx, 0.6f*vg.time_delta ); @@ -318,6 +318,53 @@ VG_STATIC void player_animate_death_cam(void) player.angles[1] = -asinf( delta[1] ); } +VG_STATIC void player_animate_follow_cam( v3f target, float dist, float speed ) +{ + v3f delta; + + v3_sub( target, player.camera_pos, delta ); + v3_normalize( delta ); + + v3f follow_pos; + v3_muladds( target, delta, -dist, follow_pos ); + v3_lerp( player.camera_pos, follow_pos, + speed * vg.time_delta, player.camera_pos ); + + /* + * Make sure the camera stays above the ground + */ + v3f min_height = {0.0f,1.0f,0.0f}; + + v3f sample; + v3_add( player.camera_pos, min_height, sample ); + ray_hit hit; + hit.dist = min_height[1]*2.0f; + + if( ray_world( sample, (v3f){0.0f,-1.0f,0.0f}, &hit )) + v3_add( hit.pos, min_height, player.camera_pos ); + +#if 0 + if( world.water.enabled ) + { + player.camera_pos[1] = + vg_maxf( world.water.height + 2.0f, player.camera_pos[1] ); + } +#endif + + player.angles[0] = atan2f( delta[0], -delta[2] ); + player.angles[1] = -asinf( delta[1] ); +} + +VG_STATIC void player_animate_camera_thirdperson(void) +{ + static v3f lerp_cam = { 0.0f, 0.0f, 0.0f }; + v3f target; + + v3_muladds( player.phys.rb.co, player.phys.rb.up, 1.2f, target ); + + player_animate_follow_cam( target, 1.5f, 20.0f ); +} + VG_STATIC void player_animate_camera(void) { struct player_phys *phys = &player.phys;