提取视锥面(Gribb& Hartmann方法) [英] Extracting View Frustum Planes (Gribb & Hartmann method)
问题描述
我一直在努力提取Gribb/Hartmann方法的方法视锥飞机已有一段时间,但收效甚微.我想建立一个摄影机视锥以消隐我的场景.
I have been grappling with the Gribb/Hartmann method of extracting the Frustum planes for some time now, with little success. I want to build a camera view-frustum to cull my scene.
我正在用右手坐标系处理主要列矩阵. (OpenGL风格-我使用的是C#和Playstation Mobile,但数学方法应该相同)
I am working with column-major matrices in a right-handed coordinate system. (OpenGL style - I'm using C# and Playstation Mobile, but the math should be the same)
我想让飞机进入世界空间,所以我从View-Projection Matrix(即projectionMatrix * viewMatrix)构建了我的视锥.矩阵视图是摄影机的World-Transform的倒数.
I want to get my planes in World-Space, so I build my frustum from the View-Projection Matrix (that's projectionMatrix * viewMatrix). The view Matrix is the inverse of the camera's World-Transform.
问题是;无论我进行什么调整,我似乎都无法获得正确的视锥.我认为我可能缺少明显的东西.
The problem is; regardless of what I tweak, I can't seem to get a correct frustum. I think that I may be missing something obvious.
如果我努力"当我的相机仍沿z轴向下看时,向左或向右移动时,飞机的法线发生变化,因此它们始终指向场景的原点-这使我认为它们不在世界空间中.>
If I "strafe" my camera left or right while still looking down the z-axis, the normals of my planes change so that they are always pointing at the origin of the scene - which makes me think that they are not in world-space...
推荐答案
可以使用Gribb/Hartmann方法提取投影矩阵中的平面,如下所示(主列):
The planes from a projection matrix can be extracted using the Gribb/Hartmann method as follows, (column major):
void extract_planes_from_projmat(
const float mat[4][4],
float left[4], float right[4], float top[4], float bottom[4],
float near[4], float far[4])
{
for (int i = 4; i--; ) left[i] = mat[i][3] + mat[i][0];
for (int i = 4; i--; ) right[i] = mat[i][3] - mat[i][0];
for (int i = 4; i--; ) bottom[i] = mat[i][3] + mat[i][1];
for (int i = 4; i--; ) top[i] = mat[i][3] - mat[i][1];
for (int i = 4; i--; ) near[i] = mat[i][3] + mat[i][2];
for (int i = 4; i--; ) far[i] = mat[i][3] - mat[i][2];
}
其中mat4
是投影矩阵和模型视图矩阵的乘积.
Where mat4
is the product of the projection matrix and the model-view matrix.
请参阅:
- https://fgiesen. wordpress.com/2012/08/31/frustum-planes-from-the-projection-matrix/
- http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
- https://fgiesen.wordpress.com/2012/08/31/frustum-planes-from-the-projection-matrix/
- http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
注意:如果矩阵分量未归一化,并且您需要一个 Hessian范式平面,那么您将需要归一化所得平面.
Note: if the matrix components aren't normalized and you require a Hessian Normal Form plane, then you will need to normalize the resulting planes.
这篇关于提取视锥面(Gribb& Hartmann方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!