From 3caad3f3c9e319ca67d63231e8c64b2ace855fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Juh=C3=A1sz?= Date: Sat, 23 Jul 2016 21:11:20 +0200 Subject: 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). --- src/util/pointedthing.cpp | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'src/util/pointedthing.cpp') diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index f1f1d3f20..e5c5dcf4c 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -23,20 +23,47 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "../exceptions.h" #include +PointedThing::PointedThing(const v3s16 &under, const v3s16 &above, + const v3s16 &real_under, const v3f &point, const v3s16 &normal, + f32 distSq): + type(POINTEDTHING_NODE), + node_undersurface(under), + node_abovesurface(above), + node_real_undersurface(real_under), + intersection_point(point), + intersection_normal(normal), + distanceSq(distSq) +{} + +PointedThing::PointedThing(s16 id, const v3f &point, const v3s16 &normal, + f32 distSq) : + type(POINTEDTHING_OBJECT), + object_id(id), + intersection_point(point), + intersection_normal(normal), + distanceSq(distSq) +{} + std::string PointedThing::dump() const { std::ostringstream os(std::ios::binary); - if (type == POINTEDTHING_NOTHING) { - os<<"[nothing]"; - } else if (type == POINTEDTHING_NODE) { + switch (type) { + case POINTEDTHING_NOTHING: + os << "[nothing]"; + break; + case POINTEDTHING_NODE: + { const v3s16 &u = node_undersurface; const v3s16 &a = node_abovesurface; - os<<"[node under="<