Move the nametag back to the top of the player (#6179)

read the actual height of the collisionbox
master
TeTpaAka 2017-07-29 19:24:10 +02:00 committed by SmallJoker
parent 765fd9a0bc
commit d504831ee2
3 changed files with 18 additions and 7 deletions

View File

@ -617,7 +617,7 @@ void Camera::drawNametags()
// shadow can remain. // shadow can remain.
continue; 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 }; f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f };
trans.multiplyWith1x4Matrix(transformed_pos); trans.multiplyWith1x4Matrix(transformed_pos);
if (transformed_pos[3] > 0) { if (transformed_pos[3] > 0) {
@ -641,9 +641,10 @@ void Camera::drawNametags()
} }
Nametag *Camera::addNametag(scene::ISceneNode *parent_node, 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); m_nametags.push_back(nametag);
return nametag; return nametag;
} }

View File

@ -39,15 +39,18 @@ class WieldMeshSceneNode;
struct Nametag { struct Nametag {
Nametag(scene::ISceneNode *a_parent_node, Nametag(scene::ISceneNode *a_parent_node,
const std::string &a_nametag_text, 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), parent_node(a_parent_node),
nametag_text(a_nametag_text), nametag_text(a_nametag_text),
nametag_color(a_nametag_color) nametag_color(a_nametag_color),
nametag_pos(a_nametag_pos)
{ {
} }
scene::ISceneNode *parent_node; scene::ISceneNode *parent_node;
std::string nametag_text; std::string nametag_text;
video::SColor nametag_color; video::SColor nametag_color;
v3f nametag_pos;
}; };
enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT}; enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
@ -157,7 +160,8 @@ public:
} }
Nametag *addNametag(scene::ISceneNode *parent_node, 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); void removeNametag(Nametag *nametag);

View File

@ -895,8 +895,11 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
scene::ISceneNode *node = getSceneNode(); scene::ISceneNode *node = getSceneNode();
if (node && m_prop.nametag != "" && !m_is_local_player) { if (node && m_prop.nametag != "" && !m_is_local_player) {
// Add nametag // Add nametag
v3f pos;
pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
m_nametag = m_client->getCamera()->addNametag(node, m_nametag = m_client->getCamera()->addNametag(node,
m_prop.nametag, m_prop.nametag_color); m_prop.nametag, m_prop.nametag_color,
pos);
} }
updateNodePos(); updateNodePos();
@ -1700,6 +1703,9 @@ void GenericCAO::processMessage(const std::string &data)
m_prop.nametag_color = readARGB8(is); m_prop.nametag_color = readARGB8(is);
if (m_nametag != NULL) { if (m_nametag != NULL) {
m_nametag->nametag_color = m_prop.nametag_color; 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) { } else if (cmd == GENERIC_CMD_SPAWN_INFANT) {
u16 child_id = readU16(is); u16 child_id = readU16(is);