HC:intersectsRay如何工作

问题描述

我正在为LÖVE做轻松的表演。为了尽可能快地使用光源发出的光线到可以阻挡光线的物体。这些阻滞剂制成HC多边形形状。从理论上讲,我可以在光源周围放一些光线。如果射线与形状相交,则将相交点添加到表中,否则,将使用圆边。如果一切正常,我会得到一些

但是,我得到了这个

red lines is connected points of intersection

我禁用了碰撞检查并出现了一个圆圈,所以问题完全出在HC或我的用法不正确 这是代码本身

local PoI = {}
for _,source in ipairs(light_sources) do
    local x,y,radius = source:GetX(),source:GetY(),source:GeTradius()

    for i = 1,10 do --10 is amount of rays
        local a = i/10 * 2 * math.pi    
        local x1 = radius * math.cos(a) + x   --edge of a circle and direction for tracer
        local y1 = radius * math.sin(a) + y

        local no_intersection = true
        for _,blocker in ipairs(blocking_objects) do
            local check,intersection = blocker:intersectsRay(x,x1,y1)
            if check then
                local vx,vy = vector.add(x,vector.mul(intersection,y1))                    
                table.insert(PoI,vx)
                table.insert(PoI,vy)
                no_intersection = false
            end
        end

        if no_intersection then --nothing is found,use direction as a PoI
            table.insert(PoI,x1)
            table.insert(PoI,y1)
        end
    end
end

老实说,我不知道出什么问题了,所以如果有人可以帮助我,我将非常高兴。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)