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.
This commit is contained in:
RealBadAngel 2016-02-21 06:50:41 +01:00 committed by paramat
parent 8a1a9fdc24
commit 68f5b877c7
6 changed files with 39 additions and 2 deletions

@ -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;
}
}

@ -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();

@ -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;
};

@ -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;
}
}
}
}

@ -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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 144 B