Improve glass
[oweals/minetest.git] / src / content_cao.h
index c8554e737cb0cc370823e37eee370eed7545091b..3a3fbbcda071a4c259bf48bcc1149085950ab67e 100644 (file)
@@ -38,6 +38,7 @@ struct SmoothTranslator
        f32 anim_counter;
        f32 anim_time;
        f32 anim_time_counter;
+       bool aim_is_end;
 
        SmoothTranslator():
                vect_old(0,0,0),
@@ -45,7 +46,8 @@ struct SmoothTranslator
                vect_aim(0,0,0),
                anim_counter(0),
                anim_time(0),
-               anim_time_counter(0)
+               anim_time_counter(0),
+               aim_is_end(true)
        {}
 
        void init(v3f vect)
@@ -56,6 +58,7 @@ struct SmoothTranslator
                anim_counter = 0;
                anim_time = 0;
                anim_time_counter = 0;
+               aim_is_end = true;
        }
 
        void sharpen()
@@ -63,14 +66,19 @@ struct SmoothTranslator
                init(vect_show);
        }
 
-       void update(v3f vect_new)
+       void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
        {
+               aim_is_end = is_end_position;
                vect_old = vect_show;
                vect_aim = vect_new;
-               if(anim_time < 0.001 || anim_time > 1.0)
-                       anim_time = anim_time_counter;
-               else
-                       anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               if(update_interval > 0){
+                       anim_time = update_interval;
+               } else {
+                       if(anim_time < 0.001 || anim_time > 1.0)
+                               anim_time = anim_time_counter;
+                       else
+                               anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               }
                anim_time_counter = 0;
                anim_counter = 0;
        }
@@ -85,8 +93,11 @@ struct SmoothTranslator
                        moveratio = anim_time_counter / anim_time;
                // Move a bit less than should, to avoid oscillation
                moveratio = moveratio * 0.5;
-               if(moveratio > 1.5)
-                       moveratio = 1.5;
+               float move_end = 1.5;
+               if(aim_is_end)
+                       move_end = 1.0;
+               if(moveratio > move_end)
+                       moveratio = move_end;
                vect_show = vect_old + vect_move * moveratio;
        }
 
@@ -104,7 +115,7 @@ struct SmoothTranslator
 class TestCAO : public ClientActiveObject
 {
 public:
-       TestCAO();
+       TestCAO(IGameDef *gamedef);
        virtual ~TestCAO();
        
        u8 getType() const
@@ -112,9 +123,9 @@ public:
                return ACTIVEOBJECT_TYPE_TEST;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -136,7 +147,7 @@ private:
 class ItemCAO : public ClientActiveObject
 {
 public:
-       ItemCAO();
+       ItemCAO(IGameDef *gamedef);
        virtual ~ItemCAO();
        
        u8 getType() const
@@ -144,9 +155,9 @@ public:
                return ACTIVEOBJECT_TYPE_ITEM;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -177,7 +188,7 @@ private:
 class RatCAO : public ClientActiveObject
 {
 public:
-       RatCAO();
+       RatCAO(IGameDef *gamedef);
        virtual ~RatCAO();
        
        u8 getType() const
@@ -185,9 +196,9 @@ public:
                return ACTIVEOBJECT_TYPE_RAT;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -220,7 +231,7 @@ private:
 class Oerkki1CAO : public ClientActiveObject
 {
 public:
-       Oerkki1CAO();
+       Oerkki1CAO(IGameDef *gamedef);
        virtual ~Oerkki1CAO();
        
        u8 getType() const
@@ -228,9 +239,9 @@ public:
                return ACTIVEOBJECT_TYPE_OERKKI1;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -269,7 +280,7 @@ private:
 class FireflyCAO : public ClientActiveObject
 {
 public:
-       FireflyCAO();
+       FireflyCAO(IGameDef *gamedef);
        virtual ~FireflyCAO();
        
        u8 getType() const
@@ -277,9 +288,9 @@ public:
                return ACTIVEOBJECT_TYPE_FIREFLY;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -311,7 +322,7 @@ private:
 class MobV2CAO : public ClientActiveObject
 {
 public:
-       MobV2CAO();
+       MobV2CAO(IGameDef *gamedef);
        virtual ~MobV2CAO();
        
        u8 getType() const
@@ -319,9 +330,9 @@ public:
                return ACTIVEOBJECT_TYPE_MOBV2;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -380,10 +391,12 @@ private:
        LuaEntityCAO
 */
 
+struct LuaEntityProperties;
+
 class LuaEntityCAO : public ClientActiveObject
 {
 public:
-       LuaEntityCAO();
+       LuaEntityCAO(IGameDef *gamedef);
        virtual ~LuaEntityCAO();
        
        u8 getType() const
@@ -391,9 +404,9 @@ public:
                return ACTIVEOBJECT_TYPE_LUAENTITY;
        }
        
-       static ClientActiveObject* create();
+       static ClientActiveObject* create(IGameDef *gamedef);
 
-       void addToScene(scene::ISceneManager *smgr);
+       void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
        void removeFromScene();
        void updateLight(u8 light_at_pos);
        v3s16 getLightPosition();
@@ -408,12 +421,16 @@ public:
        core::aabbox3d<f32>* getSelectionBox()
                {return &m_selection_box;}
        v3f getPosition()
-               {return m_position;}
+               {return pos_translator.vect_show;}
 
 private:
        core::aabbox3d<f32> m_selection_box;
-       scene::IMeshSceneNode *m_node;
+       scene::IMeshSceneNode *m_meshnode;
+       scene::MyBillboardSceneNode *m_spritenode;
        v3f m_position;
+       float m_yaw;
+       struct LuaEntityProperties *m_prop;
+       SmoothTranslator pos_translator;
 };