Skip to content

Commit

Permalink
First commit for fine pointed (#5485)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkuBu authored and nerzhul committed Apr 1, 2017
1 parent ef56586 commit 26f4a5c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions builtin/common/misc_helpers.lua
Expand Up @@ -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

4 changes: 3 additions & 1 deletion doc/client_lua_api.md
Expand Up @@ -752,6 +752,8 @@ Call these functions only at load time!
extra arguments and return the result
* `fgettext(string, ...)` : returns string
* same as fgettext_ne(), but calls minetest.formspec_escape before returning result
* `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
* returns the exact position on the surface of a pointed node

### UI
* `minetest.ui.minimap`
Expand Down Expand Up @@ -827,7 +829,7 @@ The following functions provide escape sequences:
* Removes background colors added by `get_background_escape_sequence`.
* `color.strip_colors(str)`
* Removes all color escape sequences.

`ColorString`
-------------
`#RGB` defines a color in hexadecimal format.
Expand Down
2 changes: 2 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -1939,6 +1939,8 @@ Helper functions
* returns time with microsecond precision. May not return wall time.
* `table.copy(table)`: returns a table
* returns a deep copy of `table`
* `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
* returns the exact position on the surface of a pointed node

`minetest` namespace reference
------------------------------
Expand Down

0 comments on commit 26f4a5c

Please sign in to comment.