盒子背面剔除
假设我有一个由其位置和方向定义的相机,以及一个由其中心和范围定义的盒子(从盒子中心到面中心的三个正交向量)。当其外表面面向相机时,面部可见;而当其内表面面向相机时,面部不可见。
显然,根据盒子的位置和方向,盒子可能有 1-3 个面可见。有没有一些聪明的方法来确定哪些面孔是可见的?一个明显的解决方案是计算每张脸的脸法线与脸相机向量的 6 个点积。有更好的办法吗?
注意:将使用透视投影,但我认为这并不重要,“面向相机”的属性似乎与投影无关。
Assume I have a camera defined by its position and direction, and a box defined by its center and extents (three orthogonal vectors from the box center to face centers). Face is visible when its outer surface is facing the camera and invisible when its inner surface is facing it.
It seems obvious that depending on box position and orientation there may be 1-3 faces of the box visible. Is there some clever way how to determine which faces are visible? An obvious solution would be to compute 6 dot-products of the face normal against the face-camera vector for each face. Is there a better way?
Note: perspective projection will be used, but I do not think it matters, the property of "facing camera" seems independent to a projecting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您描述的方法是执行此操作的正常方法。这是一个非常快的计算,因此您不必太担心速度。这与他们用来减少射线-三角形相交算法的计算次数的方法相同。如果该面的正面不可见,则该方法不会继续对该面进行计算。有关该算法的 C++ 实现,请参阅本文。这是计算的前半部分。 http://jgt.akpeters.com/papers/MollerTrumbore97/code.html
I believe the method you described is the normal way to do this. It's a very fast calculation so you shouldn't be worried too much about speed. This is the same method they use to reduce the number of calculations for ray-triangle intersection algorithms. If the front of the face isn't visible, the method doesn't continue calculations for that face. See this paper for a c++ implementation of this algorithm. It's in the first half of the calculations. http://jgt.akpeters.com/papers/MollerTrumbore97/code.html
唯一的聪明之处在于,如果立方体的一个面是可见的,那么相反的面肯定是不可见的。至少在常规透视投影中是这样。
请注意,相反的情况可能并非如此:如果一个面不可见,则另一面也可能不可见。这是因为投影类型确实很重要。想象一下立方体非常靠近相机,相机直视一张脸。然后稍微旋转立方体,当使用平行投影时,另一个面会立即变得可见,而在透视投影中不会发生这种情况。
The only cleverness is that if a face of the cube is visible, the opposing face definitely isn't. At least in a regular perspective projection.
Note that the opposite might not be true: if a face is invisible, the opposing face might be invisible too. This is because the type of projection does matter. Imagine the cube being really up close to the camera, which is looking straight at one face. Then rotate the cube slightly, and while with a parallel projection, another face would immediately become visible, in a perspective projection this doesn't happen.