1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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).
This commit is contained in:
Dániel Juhász 2016-07-23 21:11:20 +02:00 committed by paramat
parent a80ecbee1e
commit 3caad3f3c9
25 changed files with 671 additions and 313 deletions

View file

@ -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,
&current_intersection, &current_normal)) {
objects.push_back(PointedThing(
(s16) objectIds[i], current_intersection, current_normal,
(current_intersection - shootline_on_map.start).getLengthSQ()));
}
}
}
/*
************ Private methods *************
*/