如何检查对象是否位于 OpenGL 中的裁剪体积之外?
我对 OpenGL 的模型视图转换感到非常困惑。我理解所有的变换过程,但是当涉及到投影矩阵时,我迷失了:(
如果我有一个点 P (x, y, z),我如何检查该点是否会绘制在剪裁上由平行剪切体积或透视剪切体积定义的体积是什么?这个过程背后的数学背景是什么?
I'm really confused about OpenGL's modelview transformation. I understand all the transformation processes, but when it comes to projection matrix, I'm lost :(
If I have a point P (x, y, z), how can I check to see if this point will be drawn on a clipping volume defined by either by parallel clipping volume or perspective clipping volume? What's the mathematical background behind this process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将模型-视图-投影矩阵应用于对象,然后检查它是否位于由平面定义的剪辑坐标平截头体之外:
因此,如果您有一个点
p
,它是 vec3,并且模型-视图-投影矩阵,M
,那么在 GLSL 中它将如下所示:Apply the model-view-projection matrix to the object, then check if it lies outside the clip coordinate frustum, which is defined by the planes:
So if you have a point
p
which is a vec3, and a model-view-projection matrix,M
, then in GLSL it would look like this:对于任何依赖已接受答案的人来说,这是不正确的(至少在当前的实现中)。 OpenGL 在 z 平面中进行剪辑,与 x 和 y 相同,如 -w < z < w (https://www.khronos.org/opengl/wiki/Vertex_Post-Processing< /a>)。
z 的两个测试应该是: std::abs(Pclip.z) < Pclip.w
检查零将排除所有距离近场裁剪平面比远场裁剪平面更近的绘制点。
For anyone relying on the accepted answer, it is incorrect (at least in current implementations). OpenGL clips in the z plane the same as the x and y as -w < z < w (https://www.khronos.org/opengl/wiki/Vertex_Post-Processing).
The two tests for z should then be: std::abs(Pclip.z) < Pclip.w
Checking for zero will exclude all the drawn points that are closer to the near field clip plane than the far field clip plane.
要确定给定点在屏幕上是否可见,您可以根据视锥体对其进行测试。请参阅此视锥体剔除教程:
http://www.lighthouse3d.com/tutorials/view-视锥体剔除/
To determine if a given point will be visible on the screen, you test it against the viewing frustum. See this frustum culling tutorial:
http://www.lighthouse3d.com/tutorials/view-frustum-culling/