]> git.lizzy.rs Git - minetest.git/blobdiff - src/camera.cpp
Add shutdown hook interface to Lua API
[minetest.git] / src / camera.cpp
index 1ef594eeadacc5f762ae01374c850a94fea2dda3..43f26cd8f911c492e531a5c4aa3d82599df8078e 100644 (file)
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sound.h"
 #include "event.h"
 #include "util/numeric.h"
+#include "util/mathconstants.h"
 
 Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
                IGameDef *gamedef):
@@ -188,7 +189,7 @@ void Camera::step(f32 dtime)
 
        if (m_digging_button != -1)
        {
-               f32 offset = dtime * 3.5;
+               f32 offset = dtime * 4.5;
                float m_digging_anim_was = m_digging_anim;
                m_digging_anim += offset;
                if (m_digging_anim >= 1)
@@ -213,8 +214,22 @@ void Camera::step(f32 dtime)
 void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
                f32 tool_reload_ratio)
 {
+       // Get player position
+       // Smooth the movement when walking up stairs
+       v3f old_player_position = m_playernode->getPosition();
+       v3f player_position = player->getPosition();
+       //if(player->touching_ground && player_position.Y > old_player_position.Y)
+       if(player->touching_ground &&
+                       player_position.Y > old_player_position.Y)
+       {
+               f32 oldy = old_player_position.Y;
+               f32 newy = player_position.Y;
+               f32 t = exp(-23*frametime);
+               player_position.Y = oldy * t + newy * (1-t);
+       }
+
        // Set player node transformation
-       m_playernode->setPosition(player->getPosition());
+       m_playernode->setPosition(player_position);
        m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0));
        m_playernode->updateAbsolutePosition();
 
@@ -321,13 +336,13 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
        if (m_digging_button != -1)
        {
                f32 digfrac = m_digging_anim;
-               wield_position.X -= 30 * sin(pow(digfrac, 0.8f) * M_PI);
-               wield_position.Y += 15 * sin(digfrac * 2 * M_PI);
-               wield_position.Z += 5 * digfrac;
-
+               wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI);
+               wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI);
+               wield_position.Z += 25 * 0.5;
+       
                // Euler angles are PURE EVIL, so why not use quaternions?
                core::quaternion quat_begin(wield_rotation * core::DEGTORAD);
-               core::quaternion quat_end(v3f(90, -10, -130) * core::DEGTORAD);
+               core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD);
                core::quaternion quat_slerp;
                quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI));
                quat_slerp.toEuler(wield_rotation);