diff options
author | MarkuBu <markus.burrer@gmail.com> | 2017-04-01 16:50:53 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-04-01 16:50:53 +0200 |
commit | 26f4a5c2d1e3d825816188fcd63f6d1f6758ae60 (patch) | |
tree | f7a0c054309e7ba547cac27d919a8c04b667f594 /builtin | |
parent | ef56586ed32ca67bd0ae4bbd474f3eca2ce56ec5 (diff) | |
download | minetest-26f4a5c2d1e3d825816188fcd63f6d1f6758ae60.tar.gz minetest-26f4a5c2d1e3d825816188fcd63f6d1f6758ae60.tar.bz2 minetest-26f4a5c2d1e3d825816188fcd63f6d1f6758ae60.zip |
First commit for fine pointed (#5485)
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index f7111680c..1c7ff3958 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -691,3 +691,35 @@ end function core.strip_colors(str) return (str:gsub(ESCAPE_CHAR .. "%([bc]@[^)]+%)", "")) end + +-------------------------------------------------------------------------------- +-- Returns the exact coordinate of a pointed surface +-------------------------------------------------------------------------------- +function core.pointed_thing_to_face_pos(placer, pointed_thing) + local eye_offset_first = placer:get_eye_offset() + local node_pos = pointed_thing.under + local camera_pos = placer:get_pos() + local pos_off = vector.multiply( + vector.subtract(pointed_thing.above, node_pos), 0.5) + local look_dir = placer:get_look_dir() + local offset, nc + local oc = {} + + for c, v in pairs(pos_off) do + if v == 0 then + oc[#oc + 1] = c + else + offset = v + nc = c + end + end + local fine_pos = {[nc] = node_pos[nc] + offset} + camera_pos.y = camera_pos.y + 1.625 + eye_offset_first.y / 10 + local f = (node_pos[nc] + offset - camera_pos[nc]) / look_dir[nc] + + for i = 1, #oc do + fine_pos[oc[i]] = camera_pos[oc[i]] + look_dir[oc[i]] * f + end + return fine_pos +end + |