mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-15 19:42:10 +00:00
Allow rotating entity selectionboxes (#12379)
This commit is contained in:
parent
b829231992
commit
077627181e
18 changed files with 271 additions and 58 deletions
|
@ -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,
|
||||
¤t_intersection, ¤t_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, ¤t_intersection, ¤t_normal, ¤t_raw_normal);
|
||||
} else {
|
||||
collision = boxLineCollision(selection_box, rel_pos, line_vector,
|
||||
¤t_intersection, ¤t_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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue