Page 1 of 1

does line-of-sight work

PostPosted: Mon Nov 04, 2013 23:12
by leetelate
i asked this before but got no answer, so i moved it here hoping for a better response - otherwise it means that nobody knows and that leaves me to have to fix my broken line-of-sight code and doing that makes me go grrrr

so, does Line Of Sight work?

where:
local p1={x=pos1.x,y=pos1.y,z=pos1.z}
local p2={x=pos2.x,y=pos2.y,z=pos2.z}
local los = minetest..line_of_sight(p1,p2,1)
so los will be true if there is a clear line of sight between p1 and p2, or false if there is not?
what about glass?
what about blocks adjacent only at the corners? like:
XX1XXX
XXX2XX
would that be false, or true?

(from the api)
minetest.line_of_sight(pos1,pos2,stepsize) ->true/false
^ checkif there is a direct line of sight between pos1 and pos2
^ pos1 First position
^ pos2 Second position
^ stepsize smaller gives more accurate results but requires more computing
time. Default is 1.

BAH! There is a tree between me and it, then I am standing on top of it, jumping up and down on it, and it always says "false"!

the cpp for it is pathfinder.cpp, but

local zpath = {}
zpath = minetest.find_path(p1,p2,10,1,1,"") --default algo
if zpath then ....

doesn't work either - says "14:41:04: ERROR[ServerThread]: invalid startposIndex: (10,10,10)Realpos: (156,32,123)"

p1 is 156,32,123 and p2 is 156.46600341797,32.5,123.71800994873 when i was standing on top of it

oh and the minetest is from 2 days ago, compiled with git clone blah blah blah

thank you...this is driving me nutso - i dun wanna fix my broke code waaaa

PostPosted: Tue Nov 05, 2013 08:51
by rubenwardy
Try a smaller step size, ie: 0.2
Stepsize 1 means it goes forward a block each time, so you may miss blocks.

I have never got either of these to work.

Line of sight means there is no blocks in its way, apart from air, so glass will stop LOS.

Try rounding or flooring the positions; get rid of the decimal places in the positions.

PostPosted: Tue Nov 05, 2013 17:56
by leetelate
thanks - i just tried 0.2, 0.1, 0.01, 2 lol - no joy - pathfinder.cpp reads like slopping through deep mud, with costs and manhatan distance - i think it no worky :- ( - guess this means i have to fix my los code AGAIN - pffffft - thanks anyway - meh, my code works ok, the problem is in the adjacent corner blocks, and i just need to force it to look non-diagonally along y - niceu with the step though, just pop along x,y,z in the right direction (basically the sign of 1-2) checking each spot as if you were there - better than my do...while code anyway

PostPosted: Tue Nov 05, 2013 18:05
by PilzAdam
line_of_sight() seems to work to me.
It works only for air node, though, so it doesnt "see" through glass.

PostPosted: Tue Nov 05, 2013 18:10
by leetelate
PilzAdam wrote:line_of_sight() seems to work to me.
It works only for air node, though, so it doesnt "see" through glass.


what is your call to do it (with specifics please) - did you math.floor player_pos before? - trying that now

PostPosted: Tue Nov 05, 2013 19:01
by leetelate
it's actually returning nil, not true or false - are we doing something wrong?

time to make a tester mod - brb

PostPosted: Tue Nov 05, 2013 19:01
by PilzAdam
leetelate wrote:
PilzAdam wrote:line_of_sight() seems to work to me.
It works only for air node, though, so it doesnt "see" through glass.


what is your call to do it (with specifics please) - did you math.floor player_pos before? - trying that now

I use it in the mobs mob in Pilztest: https://github.com/PilzAdam/pilztest/blob/master/mods/mobs/init.lua#L100 and https://github.com/PilzAdam/pilztest/blob/master/mods/mobs/init.lua#L157

PostPosted: Tue Nov 05, 2013 19:06
by leetelate
thanks, checking

here's the test mod - drop the blocks and check the print for results

PostPosted: Tue Nov 05, 2013 19:19
by leetelate
ahem, pp.y = pp.y + 1 and use it as "if minetest.line_of_sight(p3, p4, 0.1) then", not in a var

told ya it was something we didn't know

works fine now. thanks

rewrote the test mod, below

thanks again,
SOLVED