From 377015a9a070ea62f0e25e7c530d090d734def1a Mon Sep 17 00:00:00 2001 From: Joel Leclerc Date: Wed, 2 May 2012 15:50:54 -0600 Subject: [PATCH] No more blocky FOV when going in and out of sprinting --- src/camera.cpp | 48 +++++++++++++++++++++++++++++++++++----------- src/camera.h | 3 +++ src/game.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/player.cpp | 1 + src/player.h | 2 ++ 5 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index e698373..36df534 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -74,6 +74,9 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, m_view_bobbing_state(0), m_view_bobbing_speed(0), + m_sprinting_fov_state(0), + m_sprinting_fov_states(5), + m_digging_anim(0), m_digging_button(-1) { @@ -239,22 +242,45 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0)); m_playernode->updateAbsolutePosition(); - //Get camera tilt timer (hurt animation) + // Get camera tilt timer (hurt animation) float cameratilt = fabs(fabs(-(player->hurt_tilt_timer_max/2)+player->hurt_tilt_timer)-player->hurt_tilt_timer_max/2)/5; v3f campos(player->getEyeOffset()); v3f camrot(player->getPitch(), 0, 0); + //f32 incr = 0.3/m_sprinting_fov_states; + /*if(m_sprinting_fov_state <= 0) + { + m_sprinting_fov_state = incr; + } + else if(m_sprinting_fov_state < 0.3) + { + m_sprinting_fov_state += incr; + }*/ + if(player->is_sprinting) + { + if(player->sprinting_timer != -10) + { + m_sprinting_fov_state = 0.3-player->sprinting_timer; + } + } + else + { + if(player->sprinting_timer != -20) + { + m_sprinting_fov_state = 0.3-player->sprinting_timer; + } + } m_headnode->updateAbsolutePosition(); - if (cameratilt > 0) + if(cameratilt > 0) { campos += v3f(0, cameratilt * -13, 0); camrot += v3f(0, 0, cameratilt * 13 * BS); } - if(player->is_sprinting) - { - campos += v3f(0, 0, 0.3 * BS); - } + /*if(player->is_sprinting) + {*/ + campos += v3f(0, 0, m_sprinting_fov_state * BS); + //} // Set head node transformation m_headnode->setPosition(campos); @@ -333,11 +359,11 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect))); // WTF is this? It can't be right m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y)); - if(player->is_sprinting) - { - m_fov_x += 0.3; - m_fov_y += 0.3; - } + /*if(player->is_sprinting) + {*/ + m_fov_x += m_sprinting_fov_state; + m_fov_y += m_sprinting_fov_state; + //} m_cameranode->setAspectRatio(m_aspect); m_cameranode->setFOV(m_fov_y); diff --git a/src/camera.h b/src/camera.h index 0180d99..41a5af6 100644 --- a/src/camera.h +++ b/src/camera.h @@ -167,6 +167,9 @@ private: // Speed of view bobbing animation f32 m_view_bobbing_speed; + f32 m_sprinting_fov_state; + f32 m_sprinting_fov_states; + // Digging animation frame (0 <= m_digging_anim < 1) f32 m_digging_anim; // If -1, no digging animation diff --git a/src/game.cpp b/src/game.cpp index f2b78b0..5a3ab18 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2993,6 +2993,58 @@ void the_game( } } + /* + Sprinting camera timer + */ + // Number is calculated by: 0.3/NUM. + // I chose 0.5, so 0.3/0.5 = 0.5 + f32 num = 0.6; + f32 num1 = 1; + if(player->is_sprinting) + { + if(player->sprinting_timer == -20) + { + player->sprinting_timer = 0.3; + } + if(player->sprinting_timer != -10) + { + if(player->sprinting_timer > 0.0) + { + player->sprinting_timer -= dtime*num; + if(player->sprinting_timer < 0.0) + { + player->sprinting_timer = -10; + } + } + else + { + player->sprinting_timer = 0.3; + } + } + } + else + { + if(player->sprinting_timer == -10) + { + player->sprinting_timer = 0; + } + if(player->sprinting_timer != -20) + { + if(player->sprinting_timer < 0.3) + { + player->sprinting_timer += dtime*num1; + if(player->sprinting_timer > 0.3) + { + player->sprinting_timer = -20; + } + } + else + { + player->sprinting_timer = 0; + } + } + } + /* Time that has to pass between key_forward presses to enable sprinting */ diff --git a/src/player.cpp b/src/player.cpp index d08c9c4..9088275 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -46,6 +46,7 @@ Player::Player(IGameDef *gamedef): hp(PLAYER_MAX_HP), hurt_tilt_timer(0), hurt_tilt_timer_max(0), + sprinting_timer(0.0), enable_sprinting_timer(0), enable_flying_timer(0), hunger(PLAYER_MAX_HUNGER), diff --git a/src/player.h b/src/player.h index c12cd99..32051e7 100644 --- a/src/player.h +++ b/src/player.h @@ -165,6 +165,8 @@ public: float hurt_tilt_timer_max; + float sprinting_timer; + float enable_sprinting_timer; float enable_flying_timer;