diff options
author | Dániel Juhász <juhdanad@gmail.com> | 2016-07-23 21:11:20 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-07-07 22:28:23 +0100 |
commit | 3caad3f3c9e319ca67d63231e8c64b2ace855fff (patch) | |
tree | f3cb283b7aa28958e2deec7c70dad3a85e1236d4 /src/serverenvironment.cpp | |
parent | a80ecbee1e838491343af760539a37fac4232048 (diff) | |
download | minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.tar.gz minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.tar.bz2 minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.zip |
Expose getPointedThing to Lua
This commit introduces Raycast, a Lua user object, which can be
used to perform a raycast on the map. The ray is continuable, so one can
also get hidden nodes (for example to see trough glass).
Diffstat (limited to 'src/serverenvironment.cpp')
-rw-r--r-- | src/serverenvironment.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index e8bdd2a28..11c71e28e 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -30,7 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "remoteplayer.h" #include "scripting_server.h" #include "server.h" -#include "voxelalgorithms.h" #include "util/serialize.h" #include "util/basic_macros.h" #include "util/pointedthing.h" @@ -1662,6 +1661,38 @@ ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() return message; } +void ServerEnvironment::getSelectedActiveObjects( + const core::line3d<f32> &shootline_on_map, + std::vector<PointedThing> &objects) +{ + std::vector<u16> objectIds; + getObjectsInsideRadius(objectIds, shootline_on_map.start, + shootline_on_map.getLength() + 10.0f); + const v3f line_vector = shootline_on_map.getVector(); + + for (u32 i = 0; i < objectIds.size(); i++) { + ServerActiveObject* obj = getActiveObject(objectIds[i]); + + aabb3f selection_box; + if (!obj->getSelectionBox(&selection_box)) + continue; + + v3f pos = obj->getBasePosition(); + + 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.push_back(PointedThing( + (s16) objectIds[i], current_intersection, current_normal, + (current_intersection - shootline_on_map.start).getLengthSQ())); + } + } +} + /* ************ Private methods ************* */ |