이 RayCasting 알고리즘을 대각선으로 변경하지 않도록 어떻게 변경할 수 있습니까?
-
17-09-2020 - |
문제
// Arg0 - Map, Arg1 - X, Arg2 - Y, Arg3 - Distance, Arg4 - MaxDistance
var xx,yy,dist, x1, y1, dir, maxdist, obj, res, map;
map = argument0
x1 = argument1
y1 = argument2
dir = argument3
maxdist = argument4
dist = 0
do {
dist+=1
xx = x1+round(lengthdir_x(dist,dir))
yy = y1+round(lengthdir_y(dist,dir))
} until(block_isSolid(map_get_block(map,xx,yy)) or dist>maxdist)
if !block_isSolid(map_get_block(map,xx,yy)) {
return false
} else {
res = ds_list_create()
ds_list_add(res,xx)
ds_list_add(res,yy)
return res
}
.
함수가 있습니다.lengthdir_x/y
는 generacodicicetagcode입니다.
C 태그를 거기에 넣는 것을 위해 소리 지르지 마십시오.언어는 매우 비슷합니다.
오른쪽, 절차 완료 : 이 현재의 알고리즘은 때로는 대각선으로 이동합니다 (둘 모두에서는 두 개의 로그인 중 하나가 모두 변화)하지만이 작업을 수행하지 않기를 바랍니다.
예 :
전류 : (X는 광선 캐스팅 인 경우)
xoooo oxooo ooxoo oooxo oooox.
원함 :
xxooo oxxoo ooxxo oooxx oooox.
의미가 있습니까?
도와주세요.
해결책
Delta는 float이며 가상 Secound "Ray"의 x 거리 (1.0F - 2.0F, 그냥 실험해야 함)
델타는지도의 단일 픽셀 크기보다 작아서는 안됩니다.
do {
dist+=1
xx = x1+round(lengthdir_x(dist,dir))
yy = y1+round(lengthdir_y(dist,dir))
} until(block_isSolid(map_get_block(map,xx,yy)) || block_isSolid(map_get_block(map,xx + delta,yy)) or dist>maxdist)
. 제휴하지 않습니다 StackOverflow