Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RealBadAngel authored and paramat committed Nov 12, 2016
1 parent 8a1a9fd commit 68f5b87
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/game.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/hud.cpp
Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions src/hud.h
Expand Up @@ -139,8 +139,11 @@ class Hud {
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);

Expand Down Expand Up @@ -169,6 +172,8 @@ class Hud {

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;
};
Expand Down
20 changes: 20 additions & 0 deletions src/mesh.cpp
Expand Up @@ -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;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/mesh.h
Expand Up @@ -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.
Expand Down
Binary file modified textures/base/pack/halo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68f5b87

Please sign in to comment.