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/voxelalgorithms.cpp | |
parent | a80ecbee1e838491343af760539a37fac4232048 (diff) | |
download | hax-minetest-server-3caad3f3c9e319ca67d63231e8c64b2ace855fff.tar.gz hax-minetest-server-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/voxelalgorithms.cpp')
-rw-r--r-- | src/voxelalgorithms.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index cea339557..74c165dd3 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -1407,6 +1407,8 @@ VoxelLineIterator::VoxelLineIterator(const v3f &start_position, const v3f &line_ m_line_vector(line_vector) { m_current_node_pos = floatToInt(m_start_position, 1); + m_start_node_pos = m_current_node_pos; + m_last_index = getIndex(floatToInt(start_position + line_vector, 1)); if (m_line_vector.X > 0) { m_next_intersection_multi.X = (floorf(m_start_position.X - 0.5) + 1.5 @@ -1440,14 +1442,11 @@ VoxelLineIterator::VoxelLineIterator(const v3f &start_position, const v3f &line_ m_intersection_multi_inc.Z = -1 / m_line_vector.Z; m_step_directions.Z = -1; } - - m_has_next = (m_next_intersection_multi.X <= 1) - || (m_next_intersection_multi.Y <= 1) - || (m_next_intersection_multi.Z <= 1); } void VoxelLineIterator::next() { + m_current_index++; if ((m_next_intersection_multi.X < m_next_intersection_multi.Y) && (m_next_intersection_multi.X < m_next_intersection_multi.Z)) { m_next_intersection_multi.X += m_intersection_multi_inc.X; @@ -1459,10 +1458,13 @@ void VoxelLineIterator::next() m_next_intersection_multi.Z += m_intersection_multi_inc.Z; m_current_node_pos.Z += m_step_directions.Z; } +} - m_has_next = (m_next_intersection_multi.X <= 1) - || (m_next_intersection_multi.Y <= 1) - || (m_next_intersection_multi.Z <= 1); +s16 VoxelLineIterator::getIndex(v3s16 voxel){ + return + abs(voxel.X - m_start_node_pos.X) + + abs(voxel.Y - m_start_node_pos.Y) + + abs(voxel.Z - m_start_node_pos.Z); } } // namespace voxalgo |