From: TeTpaAka Date: Sat, 29 Jul 2017 17:24:10 +0000 (+0200) Subject: Move the nametag back to the top of the player (#6179) X-Git-Tag: 5.0.0~988 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d504831ee2adf59421e82202e350f82701bd3cd0;p=oweals%2Fminetest.git Move the nametag back to the top of the player (#6179) read the actual height of the collisionbox --- diff --git a/src/camera.cpp b/src/camera.cpp index 027e0ffc8..efd8a3389 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -617,7 +617,7 @@ void Camera::drawNametags() // shadow can remain. continue; } - v3f pos = nametag->parent_node->getAbsolutePosition() + v3f(0.0, 1.1 * BS, 0.0); + v3f pos = nametag->parent_node->getAbsolutePosition() + nametag->nametag_pos * BS; f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f }; trans.multiplyWith1x4Matrix(transformed_pos); if (transformed_pos[3] > 0) { @@ -641,9 +641,10 @@ void Camera::drawNametags() } Nametag *Camera::addNametag(scene::ISceneNode *parent_node, - std::string nametag_text, video::SColor nametag_color) + const std::string &nametag_text, video::SColor nametag_color, + const v3f &pos) { - Nametag *nametag = new Nametag(parent_node, nametag_text, nametag_color); + Nametag *nametag = new Nametag(parent_node, nametag_text, nametag_color, pos); m_nametags.push_back(nametag); return nametag; } diff --git a/src/camera.h b/src/camera.h index 620e316de..052284cac 100644 --- a/src/camera.h +++ b/src/camera.h @@ -39,15 +39,18 @@ class WieldMeshSceneNode; struct Nametag { Nametag(scene::ISceneNode *a_parent_node, const std::string &a_nametag_text, - const video::SColor &a_nametag_color): + const video::SColor &a_nametag_color, + const v3f a_nametag_pos): parent_node(a_parent_node), nametag_text(a_nametag_text), - nametag_color(a_nametag_color) + nametag_color(a_nametag_color), + nametag_pos(a_nametag_pos) { } scene::ISceneNode *parent_node; std::string nametag_text; video::SColor nametag_color; + v3f nametag_pos; }; enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT}; @@ -157,7 +160,8 @@ public: } Nametag *addNametag(scene::ISceneNode *parent_node, - std::string nametag_text, video::SColor nametag_color); + const std::string &nametag_text, video::SColor nametag_color, + const v3f &pos); void removeNametag(Nametag *nametag); diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 2cc675573..993087353 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -895,8 +895,11 @@ void GenericCAO::addToScene(ITextureSource *tsrc) scene::ISceneNode *node = getSceneNode(); if (node && m_prop.nametag != "" && !m_is_local_player) { // Add nametag + v3f pos; + pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f; m_nametag = m_client->getCamera()->addNametag(node, - m_prop.nametag, m_prop.nametag_color); + m_prop.nametag, m_prop.nametag_color, + pos); } updateNodePos(); @@ -1700,6 +1703,9 @@ void GenericCAO::processMessage(const std::string &data) m_prop.nametag_color = readARGB8(is); if (m_nametag != NULL) { m_nametag->nametag_color = m_prop.nametag_color; + v3f pos; + pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f; + m_nametag->nametag_pos = pos; } } else if (cmd == GENERIC_CMD_SPAWN_INFANT) { u16 child_id = readU16(is);