Improve GUIMessageMenu (move and resize elements based on size of text)
[oweals/minetest.git] / src / camera.cpp
index 531661679f27fee2c8e9d611799537c4a86d19ad..290776bf3d2da197a60ee5398b0c40d29872558c 100644 (file)
@@ -30,8 +30,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "itemdef.h" // For wield visualization
 #include "noise.h" // easeCurve
+#include "gamedef.h"
+#include "sound.h"
+#include "event.h"
 
-Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
+Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
+               IGameDef *gamedef):
        m_smgr(smgr),
        m_playernode(NULL),
        m_headnode(NULL),
@@ -42,6 +46,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
        m_wieldlight(0),
 
        m_draw_control(draw_control),
+       m_gamedef(gamedef),
 
        m_camera_position(0,0,0),
        m_camera_direction(0,0,0),
@@ -168,19 +173,39 @@ void Camera::step(f32 dtime)
                }
                else
                {
+                       float was = m_view_bobbing_anim;
                        m_view_bobbing_anim = my_modf(m_view_bobbing_anim + offset);
+                       bool step = (was == 0 ||
+                                       (was < 0.5f && m_view_bobbing_anim >= 0.5f) ||
+                                       (was > 0.5f && m_view_bobbing_anim <= 0.5f));
+                       if(step){
+                               MtEvent *e = new SimpleTriggerEvent("ViewBobbingStep");
+                               m_gamedef->event()->put(e);
+                       }
                }
        }
 
        if (m_digging_button != -1)
        {
                f32 offset = dtime * 3.5;
+               float m_digging_anim_was = m_digging_anim;
                m_digging_anim += offset;
                if (m_digging_anim >= 1)
                {
                        m_digging_anim = 0;
                        m_digging_button = -1;
                }
+               float lim = 0.15;
+               if(m_digging_anim_was < lim && m_digging_anim >= lim)
+               {
+                       if(m_digging_button == 0){
+                               MtEvent *e = new SimpleTriggerEvent("CameraPunchLeft");
+                               m_gamedef->event()->put(e);
+                       } else if(m_digging_button == 1){
+                               MtEvent *e = new SimpleTriggerEvent("CameraPunchRight");
+                               m_gamedef->event()->put(e);
+                       }
+               }
        }
 }
 
@@ -265,6 +290,9 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
        // FOV and aspect ratio
        m_aspect = (f32)screensize.X / (f32) screensize.Y;
        m_fov_y = fov_degrees * PI / 180.0;
+       // Increase vertical FOV on lower aspect ratios (<16:10)
+       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));
        m_cameranode->setAspectRatio(m_aspect);
        m_cameranode->setFOV(m_fov_y);
@@ -279,15 +307,15 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
                if(m_digging_anim > 0.5)
                        frac = 2.0 * (m_digging_anim - 0.5);
                // This value starts from 1 and settles to 0
-               f32 ratiothing = pow((1.0 - tool_reload_ratio), 0.5);
-               //f32 ratiothing2 = pow(ratiothing, 0.5);
+               f32 ratiothing = pow((1.0f - tool_reload_ratio), 0.5f);
+               //f32 ratiothing2 = pow(ratiothing, 0.5f);
                f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0;
-               wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7);
+               wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f);
                //wield_position.Z += frac * 5.0 * ratiothing2;
-               wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1);
-               wield_rotation.Y += frac * 70.0 * pow(ratiothing2, 1.4);
-               //wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4);
-               //wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0);
+               wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1f);
+               wield_rotation.Y += frac * 70.0 * pow(ratiothing2, 1.4f);
+               //wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4f);
+               //wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f);
        }
        if (m_digging_button != -1)
        {
@@ -323,7 +351,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
        if ((hypot(speed.X, speed.Z) > BS) &&
                (player->touching_ground) &&
                (g_settings->getBool("view_bobbing") == true) &&
-               (g_settings->getBool("free_move") == false))
+               (g_settings->getBool("free_move") == false ||
+                               !m_gamedef->checkLocalPrivilege("fly")))
        {
                // Start animation
                m_view_bobbing_state = 1;
@@ -375,8 +404,12 @@ void Camera::updateViewingRange(f32 frametime_in)
                m_draw_control.wanted_range = viewing_range_max;
 
        // Just so big a value that everything rendered is visible
-       // Some more allowance than viewing_range_max * BS because of active objects etc.
-       m_cameranode->setFarValue(viewing_range_max * BS * 10);
+       // Some more allowance than viewing_range_max * BS because of clouds,
+       // active objects, etc.
+       if(viewing_range_max < 200*BS)
+               m_cameranode->setFarValue(200 * BS * 10);
+       else
+               m_cameranode->setFarValue(viewing_range_max * BS * 10);
 
        f32 wanted_fps = g_settings->getFloat("wanted_fps");
        wanted_fps = MYMAX(wanted_fps, 1.0);
@@ -477,9 +510,9 @@ void Camera::setDigging(s32 button)
                m_digging_button = button;
 }
 
-void Camera::wield(const ItemStack &item, IGameDef *gamedef)
+void Camera::wield(const ItemStack &item)
 {
-       IItemDefManager *idef = gamedef->idef();
+       IItemDefManager *idef = m_gamedef->idef();
        scene::IMesh *wield_mesh = item.getDefinition(idef).wield_mesh;
        if(wield_mesh)
        {