如何检查对象是否位于 OpenGL 中的剪切体积之外? [英] How to check if an object lies outside the clipping volume in OpenGL?

查看:25
本文介绍了如何检查对象是否位于 OpenGL 中的剪切体积之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的对 OpenGL 的模型视图转换感到困惑.我了解所有的转换过程,但是当涉及到投影矩阵时,我迷路了:(

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 :(

如果我有一个点 P (x, y, z),我如何检查这个点是否会被绘制在一个由平行剪切体积或透视剪切体积定义的剪切体积上?这个过程背后的数学背景是什么?

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?

推荐答案

将模型-视图-投影矩阵应用于对象,然后检查它是否位于由平面定义的剪辑坐标截头体之外:

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:

    -w < x < w
    -w < y < w
     0 < z < w

因此,如果您有一个点 p 是一个 vec3,还有一个模型-视图-投影矩阵 M,那么在 GLSL 中它会是这样的:

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:

    bool in_frustum(mat4 M, vec3 p) {
        vec4 Pclip = M * vec4(p, 1.);
        return abs(Pclip.x) < Pclip.w && 
               abs(Pclip.y) < Pclip.w && 
               0 < Pclip.z && 
               Pclip.z < Pclip.w;
    }

这篇关于如何检查对象是否位于 OpenGL 中的剪切体积之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆