使用矩阵变换进行场景遍历期间的射线盒相交

发布于 2024-08-27 11:33:36 字数 952 浏览 9 评论 0原文

我可以通过以下几种方法来测试光线盒相交:

  1. 使用 ComputeIntersectionBox(...) 方法,该方法将光线和盒子作为参数,并计算光线和盒子的最近交点。该方法的工作原理是用盒子的每个面形成一个平面,并找到与每个平面的交点。一旦找到交点,就会通过检查交点是否位于角点之间来检查该点是否在盒子的表面上。 当我在两个不同的盒子上运行该算法后查看光线时,我获得了正确的交点。

  2. 在具有两个球体、一个十二面体(三角形网格)和两个盒子的场景上使用 ComputeIntersectionScene(...) 方法,而不使用矩阵变换。 ComputeIntersectionScene(...) 递归遍历场景图的所有节点并计算与给定射线的最近交点。该测试特别不应用父节点可能具有的任何转换,这些转换也需要应用于其子节点。通过这次测试,我也获得了正确的交叉点。

  3. 使用 ComputeIntersectionScene(...) 方法进行矩阵变换。此测试的工作方式与上面的测试类似,只是在找到光线与场景中的节点之间的交点之前,使用节点变换矩阵的逆矩阵将光线转换为节点的坐标系,并且在计算交点之后,该交点将被转换为节点的坐标系。通过将变换矩阵应用于交点,将变换回世界坐标。

当按照 2 中所述对同一场景文件使用第三种方法进行测试时,使用 4 条光线进行测试(因此,一条光线与一个球体相交,一条光线与另一个球体相交,一条光线与一个盒子相交,一条光线与另一个盒子相交),仅两个球体相交,而两个盒子没有相交。当我调试查看 ComputeIntersectionBox(...) 方法时,它实际上告诉我光线与盒子上的每个平面相交,但每个交点并不位于盒子上。

这似乎是奇怪的行为,因为当使用不带变换的测试 2 时,我获得了正确的盒子交集(因此,我相信我的光线盒交集是正确的),并且当使用带有变换的测试 3 时,我获得了正确的球体交集(因此,我相信我的变换光线应该没问题)。

有什么建议我可能会出错吗?

先感谢您。

There are a few ways that I'm testing my ray-box intersections:

  1. Using the ComputeIntersectionBox(...) method, that takes a ray and a box as arguments and computes the closest intersection of the ray and the box. This method works by forming a plane with each of the faces of the box and finding an intersection with each of the planes. Once an intersection is found, a check is made whether or not the point is on the surface of the box by checking that the intersection point is between the corner points.
    When I look at rays after running this algorithm on two different boxes, I obtain the correct intersections.

  2. Using ComputeIntersectionScene(...) method without using the matrix transformations on a scene that has two spheres, a dodecahedron (a triangular mesh), and two boxes. ComputeIntersectionScene(...) recursively traverses all of the nodes of the scene graph and computes the closest intersection with the given ray. This test in particular does not apply any transformations that parent nodes may have that also need to be applied to their children. With this test, I also obtain the correct intersections.

  3. Using ComputeIntersectionScene(...) method WITH the matrix transformations. This test works like the one above except that before finding an intersection between the ray and a node in the scene, the ray is transformed into the node's coordinate frame using the inverse of the node's transformation matrix and after the intersection has been computed, this intersection is transformed back into the world coordinates by applying the transformation matrix to the intersection point.

When testing with the third method on the same scene file as described in 2, testing with 4 rays (thus one ray intersects the one sphere, one ray the the other sphere, one ray one box, and one ray the other box), only the two spheres get intersected and the two boxes do not get intersections. When I debug looking into my ComputeIntersectionBox(...) method, it actually tells me that the ray intersects every plane on the box but each intersection point does not lie on the box.

This seems to be strange behavior, since when using test 2 without transformations, I obtain the correct box intersections (thus, I believe my ray-box intersection to be correct) and when using test 3 WITH transformations, I obtain the correct sphere intersections (thus, I believe my transformed ray should be OK).

Any suggestions where I could be going wrong?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-09-03 11:33:36

所以这个错误实际上是一个实现错误:当我转换光线时,我正在转换指向光线的指针,这也转换了其中的所有指针(因为该函数是递归的)。我应该做的是制作光线的单独副本并对副本(而不是原始副本)执行转换。

So the mistake was actually an implementation bug: when I was transforming the ray, I was transforming the pointer to the ray, which transformed all of the pointers within it as well (since the function is recursive). What I should have done is make a separate copy of my ray and perform the transformation on the copy, not the original.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文