问题描述
我真的对OpenGL的modelview转换感到困惑.我了解所有转换过程,但是当涉及到投影矩阵时,我会迷失:(
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?
推荐答案
将model-view-projection矩阵应用于对象,然后检查其是否位于由平面定义的剪辑坐标视锥中:
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
因此,如果您有一个点vec3的点p
和一个模型视图投影矩阵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中的裁剪空间之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!