Frustrum Bounding Volume

Started by
14 comments, last by Hibbs 18 years, 9 months ago
Can anyone help me with calculating a Frustrum Bounding Volume, or obtaining the four corner vertex's. Im using directx. Thanks
Advertisement
Aren't there 8 corner vertices?

But anyway assuming you do mean 8 and not 4 it's done as follows (well, I'm an OpenGL man but here's how I think it works in D3D): take your 3 matrices (world, view and projection), multiply them together in order (i.e. work out the overall transformation matrix), and then invert it. Then transform 8 vertices through that which are all the combinations of (-1/+1,-1/+1,-1/+1). This will give you the 8 points in world space. Which is which depends on whether you're using a left- or right-handed coordinate system (I seem to remember most D3D apps use left-handed in defiance of hundreds of years of science and maths, but I could well be wrong), and the matrix inversion will be different to OpenGL because the matrices are stored differently. If you want the viewer position, transform the vector (-1, 0, 0, 0) through that matrix.
You usually describe the frustum volume with six clipping planes. Here is details about extracting the planes in opengl and directx:

Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

Finding the clipping planes didnt help me much becuase i want to check the frustrum volume against my octree & the clipping planes tell me if a point isnt in the frustrum where-as I want to check to see if the frustrum is inside a quad.

I coded up to find the eight points of the frustrum and created a virtual camera(world view projection) so that I could render it all on the screen. It draws a frustrum shaped pyramid on the screen :) - but changing the world matrix moves it in the opposite direction - obviously becuase of the invert - removing the invert and i dont get a pyramid frustrum. Inverting the world matrix before the multiplication works. Is this a correct behaviour?

Added: Somthing is deffinatley wrong, changing the farPlane increases the size of the frustrum but also moves its posiition. Am I multiplying the matrix's in the correct order?

Heres my code:

Matrix p = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1, 1.0f, 2.0f);
Matrix v = Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, 2), new Vector3(0, 1, 0));
Matrix m = Matrix.Translation(-3, -1, -3);
Matrix M = m * v * p;
M.Invert();

fv[0] = new Vector3(-1, -1, -1);
fv[1] = new Vector3(1, -1, -1);
fv[2] = new Vector3(1, 1, -1);
fv[3] = new Vector3(-1, 1, -1);
fv[4] = new Vector3(-1, -1, 1);
fv[5] = new Vector3(1, -1, 1);
fv[6] = new Vector3(1, 1, 1);
fv[7] = new Vector3(-1, 1, 1);

for (int i = 0; i < 8; i++)
{
fv.TransformCoordinate(M);
}

Thanks
Hm.. I'm not sure exactly why you would want to check if a frustum is in a quad or not. Normally if you want to perform frustum culling with an octree you check if the quad is inside, intersect or outside the frustum. If the quad is outside you can assume that all sub-quads are too, if inside you could assume that all sub-quads are inside, if intersecting you should perform intersection tests on the sub-quads.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

Quote:Original post by Opwiz
Hm.. I'm not sure exactly why you would want to check if a frustum is in a quad or not. Normally if you want to perform frustum culling with an octree you check if the quad is inside, intersect or outside the frustum. If the quad is outside you can assume that all sub-quads are too, if inside you could assume that all sub-quads are inside, if intersecting you should perform intersection tests on the sub-quads.


Why do you see a distinction between the two checks?
Don't be afraid to be yourself. Nobody else ever will be.
Hm, there is a difference between checking if frustum is inside a quad versus checking if quad is inside (or intersecting) the frustum.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

Quote:Original post by Opwiz
Hm, there is a difference between checking if frustum is inside a quad versus checking if quad is inside (or intersecting) the frustum.


frustum inside quad == quad outside frustum

I dont see the difference.
Don't be afraid to be yourself. Nobody else ever will be.
Hm, frustum inside quad means quad intersect frustum.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

Check out Mark Morley's frustum culling tutorial. I found it to be very clear and extremely helpful, but then his site just went down. I managed to save a copy from the google cache. Does anyone know what happened to him?

This topic is closed to new replies.

Advertisement