aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2016-02-21 06:50:41 +0100
committerparamat <mat.gregory@virginmedia.com>2016-11-12 06:41:04 +0000
commit68f5b877c72cf91106ac343673f8a31b9712a470 (patch)
treed9706d8b21a613c40e7ecf6eb254f41d5ca980ba /src
parent8a1a9fdc24d29419422f0fb41095fd0388c4be9e (diff)
downloadminetest-68f5b877c72cf91106ac343673f8a31b9712a470.tar.gz
minetest-68f5b877c72cf91106ac343673f8a31b9712a470.tar.bz2
minetest-68f5b877c72cf91106ac343673f8a31b9712a470.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp2
-rw-r--r--src/hud.cpp6
-rw-r--r--src/hud.h9
-rw-r--r--src/mesh.cpp20
-rw-r--r--src/mesh.h4
5 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.