Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- eps = 1e-9
- --...
- function cast(cam, r)
- possibles = {}
- for i, v in pairs(possibles) do
- possibles[i] = nil
- end
- for i, v in pairs(map) do
- vectorX, vectorY = math.cos(r * math.pi/180), math.sin(r * math.pi/180)
- wallDistanceX, wallDistanceY = v[3] - v[1], v[4] - v[2]
- wallParallelX, wallParallelY = -wallDistanceY, wallDistanceX
- rayX, rayY = v[1] - cam.x, v[2] - cam.y --Make -
- Distance = (
- (rayX * wallParallelX) + (rayY * wallParallelY))/(
- (vectorX * wallParallelX) + (vectorY * wallParallelY)
- )
- if (
- --[[
- (math.min(v[1],v[3]) <= math.floor((cam.x + (Distance * vectorX))) and math.max(v[1],v[3]) >= math.floor((cam.x + (Distance * vectorX)))) and
- (math.min(v[2],v[4]) <= math.floor((cam.y + (Distance * vectorY))) and math.max(v[2],v[4]) >= math.floor((cam.y + (Distance * vectorY))))
- --]]
- (math.min(v[1],v[3]) <= (cam.x + (Distance * vectorX)) and math.max(v[1],v[3]) >= (cam.x + (Distance * vectorX))) and
- (math.min(v[2],v[4]) <= (cam.y + (Distance * vectorY)) and math.max(v[2],v[4]) >= (cam.y + (Distance * vectorY)))
- --[[
- (math.min(v[1],v[3]) + eps <= (cam.x + (Distance * vectorX)) and math.max(v[1],v[3]) + eps >= (cam.x + (Distance * vectorX))) and
- (math.min(v[2],v[4]) + eps <= (cam.y + (Distance * vectorY)) and math.max(v[2],v[4]) + eps >= (cam.y + (Distance * vectorY)))
- --]]
- ) then --and Distance >= 0 and Distance < 1000 then
- print(Distance)
- table.insert(possibles, Distance)
- else
- table.insert(possibles, 0)
- end
- end
- --print(math.abs(math.min(unpack(possibles))))
- --return math.min(unpack(possibles))
- return math.abs(math.min(unpack(possibles)))
- --print(Distance)
- --return math.abs(Distance)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement