我正在制造射线施法者。射线物体有Vect2 origin
和Vect2 direction
。 origin
是相机的向量。方向由此代码计算2维射线与正方形相交
var a = (cam_dir - fov) + (((fov * 2)/width) * x);
// x is the current x position of the screen. width is screen width
var b = a * Math.PI/180; // radians
ray.direction = new Vect2(Math.sin(b), Math.cos(b));
raycaster世界是一个数组。每个项目是0或一个正数。我循环这些值,这是我需要帮助的地方。
给出如上计算的射线和宽度为1的盒子,如何找到从射线到射线与盒子相交点的距离?
如果你想让我的代码看看这个pastebin。有一个评论我需要帮助。 https://pastebin.com/vPfGzzdM
此外,您不需要添加Vect2.add或减或点或交叉等等我知道如何做他们,我做了很多次,所以不要定义他们:)谢谢uuuu