Player eye height: Make this a settable player object property
authorparamat <paramat@users.noreply.github.com>
Fri, 3 Nov 2017 19:10:53 +0000 (19:10 +0000)
committerparamat <mat.gregory@virginmedia.com>
Mon, 6 Nov 2017 12:54:00 +0000 (12:54 +0000)
src/content_cao.cpp
src/content_sao.cpp
src/localplayer.cpp
src/localplayer.h
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp

index 8bc9ad88e2aecff2be55fc9dc1b35b82c8a176cb..861dc83e74cfaae16e7fcb05587f161c2cb561c6 100644 (file)
@@ -1260,6 +1260,7 @@ void GenericCAO::processMessage(const std::string &data)
                        collision_box.MaxEdge *= BS;
                        player->setCollisionbox(collision_box);
                        player->setCanZoom(m_prop.can_zoom);
+                       player->setEyeHeight(m_prop.eye_height);
                }
 
                if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
index 819c63ac3340f465fef87561a0bed5bc054e53f0..31ee21e583542128e7c15ff266dd5b40d44dfcf7 100644 (file)
@@ -809,6 +809,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p
        m_prop.colors.clear();
        m_prop.colors.emplace_back(255, 255, 255, 255);
        m_prop.spritediv = v2s16(1,1);
+       m_prop.eye_height = 1.625f;
        // end of default appearance
        m_prop.is_visible = true;
        m_prop.makes_footstep_sound = true;
@@ -834,7 +835,7 @@ void PlayerSAO::finalize(RemotePlayer *player, const std::set<std::string> &priv
 
 v3f PlayerSAO::getEyeOffset() const
 {
-       return v3f(0, BS * 1.625f, 0);
+       return v3f(0, BS * m_prop.eye_height, 0);
 }
 
 std::string PlayerSAO::getDescription()
index eb99d0062be80b044dd19aaf0d00c4ed0ce97f56..e501fac1bbc2a93fc74e82c27c5e2ff776caf584 100644 (file)
@@ -718,7 +718,8 @@ v3s16 LocalPlayer::getLightPosition() const
 
 v3f LocalPlayer::getEyeOffset() const
 {
-       float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
+       float eye_height = camera_barely_in_ceiling ?
+               m_eye_height - 0.125f : m_eye_height;
        return v3f(0, BS * eye_height, 0);
 }
 
index a3c97db5d516887da809fc97cfdefaca6c8031f9..8e4378dfa157f5ffc3e49e2f95806e4b95e45282 100644 (file)
@@ -138,6 +138,7 @@ public:
        v3f getPosition() const { return m_position; }
        v3f getEyePosition() const { return m_position + getEyeOffset(); }
        v3f getEyeOffset() const;
+       void setEyeHeight(float eye_height) { m_eye_height = eye_height; }
 
        void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
 
@@ -181,6 +182,7 @@ private:
        aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
                        BS * 1.75f, BS * 0.30f);
        bool m_can_zoom = true;
+       float m_eye_height = 1.625f;
 
        GenericCAO *m_cao = nullptr;
        Client *m_client;
index ae030501944570eaeddbaa7c0613c59c3f15c10e..ffb1ecb439e16f0fe4e136b63a724f7c30caa9b9 100644 (file)
@@ -67,6 +67,7 @@ std::string ObjectProperties::dump()
        os << ", pointable=" << pointable;
        os << ", can_zoom=" << can_zoom;
        os << ", static_save=" << static_save;
+       os << ", eye_height=" << eye_height;
        return os.str();
 }
 
@@ -99,7 +100,7 @@ void ObjectProperties::serialize(std::ostream &os) const
                writeARGB8(os, color);
        }
        writeU8(os, collideWithObjects);
-       writeF1000(os,stepheight);
+       writeF1000(os, stepheight);
        writeU8(os, automatic_face_movement_dir);
        writeF1000(os, automatic_face_movement_dir_offset);
        writeU8(os, backface_culling);
@@ -111,6 +112,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        writeU8(os, can_zoom);
        writeS8(os, glow);
        writeU16(os, breath_max);
+       writeF1000(os, eye_height);
 
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
@@ -162,5 +164,6 @@ void ObjectProperties::deSerialize(std::istream &is)
        try {
                glow = readS8(is);
                breath_max = readU16(is);
+               eye_height = readF1000(is);
        } catch (SerializationError &e) {}
 }
index fcf03383c0754dc49b560aa42142b67d9dc87e6e..8ccce589fc3634545526446cb0847e36764af747 100644 (file)
@@ -59,6 +59,7 @@ struct ObjectProperties
        //! For dropped items, this contains item information.
        std::string wield_item;
        bool static_save = true;
+       float eye_height = 1.625f;
 
        ObjectProperties();
        std::string dump();
index 1bbfac25ffe4a95df3be60498bdea269ee3c9e9f..73661a7b63cb9dc9547aefb18eede6117504589f 100644 (file)
@@ -266,6 +266,7 @@ void read_object_properties(lua_State *L, int index,
        if (getfloatfield(L, -1, "stepheight", prop->stepheight))
                prop->stepheight *= BS;
        getboolfield(L, -1, "can_zoom", prop->can_zoom);
+       getfloatfield(L, -1, "eye_height", prop->eye_height);
 
        getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
        lua_getfield(L, -1, "automatic_face_movement_dir");
@@ -359,7 +360,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
        lua_setfield(L, -2, "stepheight");
        lua_pushboolean(L, prop->can_zoom);
        lua_setfield(L, -2, "can_zoom");
-
+       lua_pushnumber(L, prop->eye_height);
+       lua_setfield(L, -2, "eye_height");
        lua_pushnumber(L, prop->automatic_rotate);
        lua_setfield(L, -2, "automatic_rotate");
        if (prop->automatic_face_movement_dir)