0

基本上我想在 XNA (C#/.NET) 中使用 Rays and Planes 来检测我的模型之间的碰撞。但在我能做到这一点之前,我迫切需要知道它们是如何工作的。

每当我去某个地方寻找 Ray/Plane 示例时,除了挑选教程之外我什么也得不到——我不是在寻找挑选教程……

我一直在尝试做的是取一个平面,给它输入 3 个 Vector3,让它代表一个 3d 原始三角形,然后向它发射 Ray。射线只是空间中的一个点和一个方向。

我的问题是当我在飞机上发射射线时,它给了我一些我无法理解的结果。例如:

假设我有一个表示坐标为 {0,0,0}{1,0,0}{0,0,1} 的基元的平面

现在我在 {0.5,1,0.5} (大约在三角形平面的中心上方)放置一条射线并给它方向;{0,-1,0}

这给了我 1,这是预期的,因为平面在射线下方 1 个单位,并且射线指向下方。但是,当我在 {2,0,0} 处设置 Ray 点时,它仍然给我一个数字,这是没有意义的,因为 {2,0,0} 是一个不在三角形上的点。

这是我一直在使用的代码;

Plane plane = new Plane(Vector3.Zero, Vector3.Right, Vector3.Backward);
Vector3 rayPos = new Vector3(0.5f, 1f, 0.5f);
Vector3 direction = new Vector3(1f, 0f, 1f) - rayPos;
direction.Normalize();
Ray ray = new Ray(rayPos, direction);
Console.WriteLine(ray.Intersects(plane));

我觉得我遗漏了一些非常重要的东西,而且我认为这一切都是错误的。任何帮助将非常感激。

4

1 回答 1

0

although 2,0,0 isn't on the plane, the direction ((2,0,0) - rayPos) is a direction that will intersect the plane (if starting from the current rayPos) and returns a result of 1.87...

于 2013-04-23T20:06:24.397 回答