summaryrefslogtreecommitdiff
path: root/src/camera.cpp
diff options
context:
space:
mode:
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>2013-04-07 15:41:33 -1000
committerkwolekr <kwolekr@minetest.net>2013-04-11 19:42:47 -0400
commit7cd5eb4c77de9fda4946de7e1c2384d0c2a0253e (patch)
tree67210091a050856c943443ea1b8e791d0fb271db /src/camera.cpp
parent17cfb1850d35148b9e2445dfdd160a164d02ebf9 (diff)
downloadminetest-7cd5eb4c77de9fda4946de7e1c2384d0c2a0253e.tar.gz
minetest-7cd5eb4c77de9fda4946de7e1c2384d0c2a0253e.tar.bz2
minetest-7cd5eb4c77de9fda4946de7e1c2384d0c2a0253e.zip
Swing the camera down when the player lands on the ground, based on the velocity the surface is hit with.
Diffstat (limited to 'src/camera.cpp')
-rw-r--r--src/camera.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index 735a8d1e9..211ecfd70 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -67,6 +67,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
m_view_bobbing_anim(0),
m_view_bobbing_state(0),
m_view_bobbing_speed(0),
+ m_view_bobbing_fall(0),
m_digging_anim(0),
m_digging_button(-1),
@@ -134,6 +135,13 @@ inline f32 my_modf(f32 x)
void Camera::step(f32 dtime)
{
+ if(m_view_bobbing_fall > 0)
+ {
+ m_view_bobbing_fall -= 3 * dtime;
+ if(m_view_bobbing_fall <= 0)
+ m_view_bobbing_fall = -1; // Mark the effect as finished
+ }
+
if (m_view_bobbing_state != 0)
{
//f32 offset = dtime * m_view_bobbing_speed * 0.035;
@@ -237,11 +245,28 @@ 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-0.75)-0.75);
+ // Fall bobbing animation
+ float fall_bobbing = 0;
+ if(player->camera_impact >= 1)
+ {
+ if(m_view_bobbing_fall == -1) // Effect took place and has finished
+ player->camera_impact = m_view_bobbing_fall = 0;
+ else if(m_view_bobbing_fall == 0) // Initialize effect
+ m_view_bobbing_fall = 1;
+
+ // Convert 0 -> 1 to 0 -> 1 -> 0
+ fall_bobbing = m_view_bobbing_fall < 0.5 ? m_view_bobbing_fall * 2 : -(m_view_bobbing_fall - 0.5) * 2 + 1;
+ // Smoothen and invert the above
+ fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1;
+ // Amplify according to the intensity of the impact
+ fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5;
+ }
+
// Set head node transformation
- m_headnode->setPosition(player->getEyeOffset()+v3f(0,cameratilt*-player->hurt_tilt_strength,0));
+ m_headnode->setPosition(player->getEyeOffset()+v3f(0,cameratilt*-player->hurt_tilt_strength+fall_bobbing,0));
m_headnode->setRotation(v3f(player->getPitch(), 0, cameratilt*player->hurt_tilt_strength));
m_headnode->updateAbsolutePosition();