所以我已经断断续续地工作了一个星期,谷歌搜索等等,我还没有找到如何做到这一点。
我有一张“射线”表和一张“线”表,我希望这些线充当镜子并在光线碰到一条线时反射光线。想象一下激光从镜子上反弹,那种反射。我已经让相交检测工作了,但我不知道如何正确计算反射角并将光线延伸到那个方向。
代码:
--the table rays is a table of tables, and each table inside is formatted as such:
--rays[x] = {100,200,150,600,200,400}, where (100,200) are ordered pairs, etc.
--The table lines simply contains values for x1,y1,x2,y2
for i,ray in ipairs(rays) do
for j,line in ipairs(lines) do
if line.x2 ~= nil and #ray>3 then
print(line.x2..' '..line.y2)
iX, iY = intersect.test(ray[#ray-3],ray[#ray-2],
ray[#ray-1],ray[#ray],line.x1,line.y1,line.x2,line.y2)
--The above code takes each ray and
--sees if it intersects with a line, with the intersect.test function
--Then if …Run Code Online (Sandbox Code Playgroud)