aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-10-30 16:53:14 +0100
committerGitHub <noreply@github.com>2022-10-30 16:53:14 +0100
commit077627181ee2eac3c0dacc3d8dc49825837e474c (patch)
treea8a6298198738f2edb30bd7e733a7a0d2005affa /src/client
parentb8292319924994352d56d6111faa73fe315d149a (diff)
downloadminetest-077627181ee2eac3c0dacc3d8dc49825837e474c.tar.xz
Allow rotating entity selectionboxes (#12379)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/clientenvironment.cpp25
-rw-r--r--src/client/game.cpp14
-rw-r--r--src/client/hud.cpp31
-rw-r--r--src/client/hud.h5
4 files changed, 47 insertions, 28 deletions
diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp
index 0b6f1a325..1ce443bcc 100644
--- a/src/client/clientenvironment.cpp
+++ b/src/client/clientenvironment.cpp
@@ -505,15 +505,24 @@ void ClientEnvironment::getSelectedActiveObjects(
if (!obj->getSelectionBox(&selection_box))
continue;
- const v3f &pos = obj->getPosition();
- aabb3f offsetted_box(selection_box.MinEdge + pos,
- selection_box.MaxEdge + pos);
-
v3f current_intersection;
- v3s16 current_normal;
- if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector,
- &current_intersection, &current_normal)) {
- objects.emplace_back((s16) obj->getId(), current_intersection, current_normal,
+ v3f current_normal, current_raw_normal;
+ const v3f rel_pos = shootline_on_map.start - obj->getPosition();
+ bool collision;
+ GenericCAO* gcao = dynamic_cast<GenericCAO*>(obj);
+ if (gcao != nullptr && gcao->getProperties().rotate_selectionbox) {
+ gcao->getSceneNode()->updateAbsolutePosition();
+ const v3f deg = obj->getSceneNode()->getAbsoluteTransformation().getRotationDegrees();
+ collision = boxLineCollision(selection_box, deg,
+ rel_pos, line_vector, &current_intersection, &current_normal, &current_raw_normal);
+ } else {
+ collision = boxLineCollision(selection_box, rel_pos, line_vector,
+ &current_intersection, &current_normal);
+ current_raw_normal = current_normal;
+ }
+ if (collision) {
+ current_intersection += obj->getPosition();
+ objects.emplace_back(obj->getId(), current_intersection, current_normal, current_raw_normal,
(current_intersection - shootline_on_map.start).getLengthSQ());
}
}
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 91c93ef7f..cdcfde759 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -3297,7 +3297,7 @@ PointedThing Game::updatePointedThing(
{
std::vector<aabb3f> *selectionboxes = hud->getSelectionBoxes();
selectionboxes->clear();
- hud->setSelectedFaceNormal(v3f(0.0, 0.0, 0.0));
+ hud->setSelectedFaceNormal(v3f());
static thread_local const bool show_entity_selectionbox = g_settings->getBool(
"show_entity_selectionbox");
@@ -3321,7 +3321,13 @@ PointedThing Game::updatePointedThing(
v3f pos = runData.selected_object->getPosition();
selectionboxes->push_back(aabb3f(selection_box));
hud->setSelectionPos(pos, camera_offset);
+ GenericCAO* gcao = dynamic_cast<GenericCAO*>(runData.selected_object);
+ if (gcao != nullptr && gcao->getProperties().rotate_selectionbox)
+ hud->setSelectionRotation(gcao->getSceneNode()->getAbsoluteTransformation().getRotationDegrees());
+ else
+ hud->setSelectionRotation(v3f());
}
+ hud->setSelectedFaceNormal(result.raw_intersection_normal);
} else if (result.type == POINTEDTHING_NODE) {
// Update selection boxes
MapNode n = map.getNode(result.node_undersurface);
@@ -3339,10 +3345,8 @@ PointedThing Game::updatePointedThing(
}
hud->setSelectionPos(intToFloat(result.node_undersurface, BS),
camera_offset);
- hud->setSelectedFaceNormal(v3f(
- result.intersection_normal.X,
- result.intersection_normal.Y,
- result.intersection_normal.Z));
+ hud->setSelectionRotation(v3f());
+ hud->setSelectedFaceNormal(result.intersection_normal);
}
// Update selection mesh light level and vertex colors
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index e8ccdbb2b..58f5ec5f1 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -826,28 +826,31 @@ void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
void Hud::drawSelectionMesh()
{
+ if (m_mode == HIGHLIGHT_NONE || (m_mode == HIGHLIGHT_HALO && !m_selection_mesh))
+ return;
+ const video::SMaterial oldmaterial = driver->getMaterial2D();
+ driver->setMaterial(m_selection_material);
+ const core::matrix4 oldtransform = driver->getTransform(video::ETS_WORLD);
+
+ core::matrix4 translate;
+ translate.setTranslation(m_selection_pos_with_offset);
+ core::matrix4 rotation;
+ rotation.setRotationDegrees(m_selection_rotation);
+ driver->setTransform(video::ETS_WORLD, translate * rotation);
+
if (m_mode == HIGHLIGHT_BOX) {
// Draw 3D selection boxes
- video::SMaterial oldmaterial = driver->getMaterial2D();
- driver->setMaterial(m_selection_material);
for (auto & selection_box : m_selection_boxes) {
- aabb3f box = aabb3f(
- selection_box.MinEdge + m_selection_pos_with_offset,
- selection_box.MaxEdge + m_selection_pos_with_offset);
-
u32 r = (selectionbox_argb.getRed() *
m_selection_mesh_color.getRed() / 255);
u32 g = (selectionbox_argb.getGreen() *
m_selection_mesh_color.getGreen() / 255);
u32 b = (selectionbox_argb.getBlue() *
m_selection_mesh_color.getBlue() / 255);
- driver->draw3DBox(box, video::SColor(255, r, g, b));
+ driver->draw3DBox(selection_box, video::SColor(255, r, g, b));
}
- driver->setMaterial(oldmaterial);
} else if (m_mode == HIGHLIGHT_HALO && m_selection_mesh) {
// Draw selection mesh
- 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),
@@ -855,16 +858,14 @@ void Hud::drawSelectionMesh()
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();
for (u32 i = 0; i < mc; i++) {
- scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
+ scene::IMeshBuffer *buf = m_selection_mesh->getMeshBuffer(i);
driver->drawMeshBuffer(buf);
}
- mesh->drop();
- driver->setMaterial(oldmaterial);
}
+ driver->setMaterial(oldmaterial);
+ driver->setTransform(video::ETS_WORLD, oldtransform);
}
enum Hud::BlockBoundsMode Hud::toggleBlockBounds()
diff --git a/src/client/hud.h b/src/client/hud.h
index fd79183a0..b6ff84243 100644
--- a/src/client/hud.h
+++ b/src/client/hud.h
@@ -75,6 +75,10 @@ public:
v3f getSelectionPos() const { return m_selection_pos; }
+ void setSelectionRotation(v3f rotation) { m_selection_rotation = rotation; }
+
+ v3f getSelectionRotation() const { return m_selection_rotation; }
+
void setSelectionMeshColor(const video::SColor &color)
{
m_selection_mesh_color = color;
@@ -126,6 +130,7 @@ private:
std::vector<aabb3f> m_halo_boxes;
v3f m_selection_pos;
v3f m_selection_pos_with_offset;
+ v3f m_selection_rotation;
scene::IMesh *m_selection_mesh = nullptr;
video::SColor m_selection_mesh_color;