微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HC:intersectsRay如何工作

如何解决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 举报,一经查实,本站将立刻删除。