I have problems implementing a frustum culling. I don't know why, but it seems that also BoundingBoxes around the NearPlane height are catched too. Its not easy to explain so here a picture:
There you can see the Light-Frustum in the middle. My FrustumChecking for a Box draws me a red-box for "ContainmentType.Intersects", a green-box for "ContainmentType.Disjoint" and a blue-box for "ContainmentType.Contains".. So you can see there are some boxes outside the frustum which are red..
This is my code for building the Frustum with the Lights World and Proj Matrix:
Public Sub BuildViewFrustum(ByVal ViewMatrix As Matrix, ByVal ProjMatrix As Matrix) Dim viewProjection As Matrix = Matrix.Multiply(ViewMatrix, ProjMatrix) 'left plane Planes(2) = New Plane(-viewProjection.M14 - viewProjection.M11, -viewProjection.M24 - viewProjection.M21, -viewProjection.M34 - viewProjection.M31, -viewProjection.M44 - viewProjection.M41) 'right plane Planes(3) = New Plane(-viewProjection.M14 + viewProjection.M11, -viewProjection.M24 + viewProjection.M21, -viewProjection.M34 + viewProjection.M31, -viewProjection.M44 + viewProjection.M41) 'top plane Planes(4) = New Plane(-viewProjection.M14 + viewProjection.M12, -viewProjection.M24 + viewProjection.M22, -viewProjection.M34 + viewProjection.M32, -viewProjection.M44 + viewProjection.M42) 'bottom plane Planes(5) = New Plane(-viewProjection.M14 - viewProjection.M12, -viewProjection.M24 - viewProjection.M22, -viewProjection.M34 - viewProjection.M32, -viewProjection.M44 - viewProjection.M42) 'near plane Planes(0) = New Plane(-viewProjection.M13, -viewProjection.M23, -viewProjection.M33, -viewProjection.M43) 'far plane Planes(1) = New Plane(-viewProjection.M14 + viewProjection.M13, -viewProjection.M24 + viewProjection.M23, -viewProjection.M34 + viewProjection.M33, -viewProjection.M44 + viewProjection.M43) For Each p In Planes p.Normalize() Next 'Corners Dim Ray As Ray = ComputeIntersectionLine(Near, Left) Corners(0) = ComputeIntersection(Top, Ray) Corners(3) = ComputeIntersection(Bottom, Ray) Ray = ComputeIntersectionLine(Right, Near) Corners(1) = ComputeIntersection(Top, Ray) Corners(2) = ComputeIntersection(Bottom, Ray) Ray = ComputeIntersectionLine(Left, Far) Corners(4) = ComputeIntersection(Top, Ray) Corners(7) = ComputeIntersection(Bottom, Ray) Ray = ComputeIntersectionLine(Far, Right) Corners(5) = ComputeIntersection(Top, Ray) Corners(6) = ComputeIntersection(Bottom, Ray) End Sub
and this my Code for testing a box in the frustum
Public Function Contains(ByVal Box As BoundingBox, ByVal worldMatrix As Matrix) As ContainmentType BoundingBox.Minimum = Vector3.TransformCoordinate(BoundingBox.Minimum, worldMatrix) BoundingBox.Maximum = Vector3.TransformCoordinate(BoundingBox.Maximum, worldMatrix) Dim flag As Boolean = False For Each P In Planes Select Case BoundingBox.Intersects(Box, P) Case PlaneIntersectionType.Front Return ContainmentType.Disjoint Case PlaneIntersectionType.Intersecting flag = True Exit For End Select Next If not flag Then Return ContainmentType.Contains Return ContainmentType.Intersects End Function
What I'm doing wrong? I saw that there was an BoundingFrustum-Class in maybe older versions of SlimDX.. Why they are removed?