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

Line_of_sight: Improve using VoxelLineIterator

This commit rewrites line_of_sight with VoxelLineIterator.
Stepsize is no longer needed, the results will be always accurate.
This commit is contained in:
Dániel Juhász 2016-12-01 20:15:37 +01:00 committed by paramat
parent ca64f564cd
commit 2153965cf9
5 changed files with 27 additions and 35 deletions

View file

@ -966,24 +966,19 @@ int ModApiEnvMod::l_clear_objects(lua_State *L)
return 0;
}
// line_of_sight(pos1, pos2, stepsize) -> true/false, pos
// line_of_sight(pos1, pos2) -> true/false, pos
int ModApiEnvMod::l_line_of_sight(lua_State *L)
{
float stepsize = 1.0;
GET_ENV_PTR;
// read position 1 from lua
v3f pos1 = checkFloatPos(L, 1);
// read position 2 from lua
v3f pos2 = checkFloatPos(L, 2);
//read step size from lua
if (lua_isnumber(L, 3)) {
stepsize = lua_tonumber(L, 3);
}
v3s16 p;
bool success = env->line_of_sight(pos1, pos2, stepsize, &p);
bool success = env->line_of_sight(pos1, pos2, &p);
lua_pushboolean(L, success);
if (!success) {
push_v3s16(L, p);

View file

@ -156,7 +156,7 @@ private:
// spawn_tree(pos, treedef)
static int l_spawn_tree(lua_State *L);
// line_of_sight(pos1, pos2, stepsize) -> true/false
// line_of_sight(pos1, pos2) -> true/false
static int l_line_of_sight(lua_State *L);
// raycast(pos1, pos2, objects, liquids) -> Raycast