From 68f5b877c72cf91106ac343673f8a31b9712a470 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sun, 21 Feb 2016 06:50:41 +0100 Subject: [PATCH] Halo: Highlight selected face This is a slightly modified and cleaned up version of #3774 by RealBadAngel. By sofar: Remove color change (just make it lighter) and some minor cleanups. --- src/game.cpp | 2 ++ src/hud.cpp | 6 ++++++ src/hud.h | 9 +++++++-- src/mesh.cpp | 20 ++++++++++++++++++++ src/mesh.h | 4 ++++ textures/base/pack/halo.png | Bin 144 -> 144 bytes 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 33795abc5..e0ffa1be5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -362,6 +362,7 @@ PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_positio min_distance = (selected_object->getPosition() - camera_position).getLength(); + hud->setSelectedFaceNormal(v3f(0.0, 0.0, 0.0)); result.type = POINTEDTHING_OBJECT; result.object_id = selected_object->getId(); } @@ -473,6 +474,7 @@ PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_positio if (!facebox.intersectsWithLine(shootline)) continue; result.node_abovesurface = pointed_pos + facedir; + hud->setSelectedFaceNormal(v3f(facedir.X, facedir.Y, facedir.Z)); face_min_distance = distance; } } diff --git a/src/hud.cpp b/src/hud.cpp index 19feaef7b..43d957380 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -544,6 +544,12 @@ void Hud::drawSelectionMesh() video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); setMeshColor(m_selection_mesh, m_selection_mesh_color); + video::SColor face_color(0, + MYMIN(255, m_selection_mesh_color.getRed() * 1.5), + MYMIN(255, m_selection_mesh_color.getGreen() * 1.5), + MYMIN(255, m_selection_mesh_color.getBlue() * 1.5)); + setMeshColorByNormal(m_selection_mesh, m_selected_face_normal, + face_color); scene::IMesh* mesh = cloneMesh(m_selection_mesh); translateMesh(mesh, m_selection_pos_with_offset); u32 mc = m_selection_mesh->getMeshBufferCount(); diff --git a/src/hud.h b/src/hud.h index 7f0fbe7b3..a4d7990e9 100644 --- a/src/hud.h +++ b/src/hud.h @@ -139,8 +139,11 @@ public: v3f getSelectionPos() const { return m_selection_pos; } - void setSelectionMeshColor(const video::SColor &c) - { m_selection_mesh_color = c; } + void setSelectionMeshColor(const video::SColor &color) + { m_selection_mesh_color = color; } + + void setSelectedFaceNormal(const v3f &face_normal) + { m_selected_face_normal = face_normal; } void drawLuaElements(const v3s16 &camera_offset); @@ -169,6 +172,8 @@ private: scene::IMesh* m_selection_mesh; video::SColor m_selection_mesh_color; + v3f m_selected_face_normal; + video::SMaterial m_selection_material; bool m_use_selection_mesh; }; diff --git a/src/mesh.cpp b/src/mesh.cpp index b5bf8660a..b68862d22 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -226,7 +226,27 @@ void setMeshColorByNormalXYZ(scene::IMesh *mesh, vertex->Color = colorY; else vertex->Color = colorZ; + } + } +} + +void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal, + const video::SColor &color) +{ + if (!mesh) + return; + u16 mc = mesh->getMeshBufferCount(); + for (u16 j = 0; j < mc; j++) { + scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); + const u32 stride = getVertexPitchFromType(buf->getVertexType()); + u32 vertex_count = buf->getVertexCount(); + u8 *vertices = (u8 *)buf->getVertices(); + for (u32 i = 0; i < vertex_count; i++) { + video::S3DVertex *vertex = (video::S3DVertex *)(vertices + i * stride); + if (normal == vertex->Normal) { + vertex->Color = color; + } } } } diff --git a/src/mesh.h b/src/mesh.h index 8e1893773..10df97015 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -64,6 +64,10 @@ void setMeshColorByNormalXYZ(scene::IMesh *mesh, const video::SColor &colorX, const video::SColor &colorY, const video::SColor &colorZ); + +void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal, + const video::SColor &color); + /* Rotate the mesh by 6d facedir value. Method only for meshnodes, not suitable for entities. diff --git a/textures/base/pack/halo.png b/textures/base/pack/halo.png index eaea782da6480cd7996367a1a10785db6f5933cb..ed3ff9d8c856f3fb8758f75f665b4e04a42d6605 100644 GIT binary patch delta 68 zcmbQhIDv6Ou&pR7gTgPPA(>OMG4b{D-D6nY~73u Y50#ke59Y7U2P$OnboFyt=akR{03(?fPXGV_ delta 68 zcmbQhIDv6Ouq`{2m1tSH2|EJ=gRG~EV~EA+