No more blocky FOV when going in and out of sprinting
parent
c8c094bf49
commit
377015a9a0
|
@ -74,6 +74,9 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
|
||||||
m_view_bobbing_state(0),
|
m_view_bobbing_state(0),
|
||||||
m_view_bobbing_speed(0),
|
m_view_bobbing_speed(0),
|
||||||
|
|
||||||
|
m_sprinting_fov_state(0),
|
||||||
|
m_sprinting_fov_states(5),
|
||||||
|
|
||||||
m_digging_anim(0),
|
m_digging_anim(0),
|
||||||
m_digging_button(-1)
|
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->setRotation(v3f(0, -1 * player->getYaw(), 0));
|
||||||
m_playernode->updateAbsolutePosition();
|
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;
|
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 campos(player->getEyeOffset());
|
||||||
v3f camrot(player->getPitch(), 0, 0);
|
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();
|
m_headnode->updateAbsolutePosition();
|
||||||
if (cameratilt > 0)
|
if(cameratilt > 0)
|
||||||
{
|
{
|
||||||
campos += v3f(0, cameratilt * -13, 0);
|
campos += v3f(0, cameratilt * -13, 0);
|
||||||
camrot += v3f(0, 0, cameratilt * 13 * BS);
|
camrot += v3f(0, 0, cameratilt * 13 * BS);
|
||||||
}
|
}
|
||||||
if(player->is_sprinting)
|
/*if(player->is_sprinting)
|
||||||
{
|
{*/
|
||||||
campos += v3f(0, 0, 0.3 * BS);
|
campos += v3f(0, 0, m_sprinting_fov_state * BS);
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Set head node transformation
|
// Set head node transformation
|
||||||
m_headnode->setPosition(campos);
|
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)));
|
m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
|
||||||
// WTF is this? It can't be right
|
// WTF is this? It can't be right
|
||||||
m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y));
|
m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y));
|
||||||
if(player->is_sprinting)
|
/*if(player->is_sprinting)
|
||||||
{
|
{*/
|
||||||
m_fov_x += 0.3;
|
m_fov_x += m_sprinting_fov_state;
|
||||||
m_fov_y += 0.3;
|
m_fov_y += m_sprinting_fov_state;
|
||||||
}
|
//}
|
||||||
m_cameranode->setAspectRatio(m_aspect);
|
m_cameranode->setAspectRatio(m_aspect);
|
||||||
m_cameranode->setFOV(m_fov_y);
|
m_cameranode->setFOV(m_fov_y);
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,9 @@ private:
|
||||||
// Speed of view bobbing animation
|
// Speed of view bobbing animation
|
||||||
f32 m_view_bobbing_speed;
|
f32 m_view_bobbing_speed;
|
||||||
|
|
||||||
|
f32 m_sprinting_fov_state;
|
||||||
|
f32 m_sprinting_fov_states;
|
||||||
|
|
||||||
// Digging animation frame (0 <= m_digging_anim < 1)
|
// Digging animation frame (0 <= m_digging_anim < 1)
|
||||||
f32 m_digging_anim;
|
f32 m_digging_anim;
|
||||||
// If -1, no digging animation
|
// If -1, no digging animation
|
||||||
|
|
52
src/game.cpp
52
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
|
Time that has to pass between key_forward presses to enable sprinting
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -46,6 +46,7 @@ Player::Player(IGameDef *gamedef):
|
||||||
hp(PLAYER_MAX_HP),
|
hp(PLAYER_MAX_HP),
|
||||||
hurt_tilt_timer(0),
|
hurt_tilt_timer(0),
|
||||||
hurt_tilt_timer_max(0),
|
hurt_tilt_timer_max(0),
|
||||||
|
sprinting_timer(0.0),
|
||||||
enable_sprinting_timer(0),
|
enable_sprinting_timer(0),
|
||||||
enable_flying_timer(0),
|
enable_flying_timer(0),
|
||||||
hunger(PLAYER_MAX_HUNGER),
|
hunger(PLAYER_MAX_HUNGER),
|
||||||
|
|
|
@ -165,6 +165,8 @@ public:
|
||||||
|
|
||||||
float hurt_tilt_timer_max;
|
float hurt_tilt_timer_max;
|
||||||
|
|
||||||
|
float sprinting_timer;
|
||||||
|
|
||||||
float enable_sprinting_timer;
|
float enable_sprinting_timer;
|
||||||
|
|
||||||
float enable_flying_timer;
|
float enable_flying_timer;
|
||||||
|
|
Loading…
Reference in New Issue