Frustum Culling Problem

Razor89

Member
Joined
Dec 15, 2004
Messages
12
Could anybody give me a hand on why this doesnt work? Thanks!
(Code is in VB.NET)

Code:
        Public Sub ExtractFrustumPlanes(Optional ByVal Normalize As Boolean = True)

            Dim comboMatrix As Matrix = Matrix.Multiply(ccCore.Device.Transform.View, ccCore.Device.Transform.Projection)

            Left clipping plane
            ccFrustum(0).A = comboMatrix.M14 + comboMatrix.M11
            ccFrustum(0).B = -(comboMatrix.M24 + comboMatrix.M21)
            ccFrustum(0).C = -(comboMatrix.M34 + comboMatrix.M31)
            ccFrustum(0).D = -(comboMatrix.M44 + comboMatrix.M41)

            Right clipping plane
            ccFrustum(1).A = -(comboMatrix.M14 - comboMatrix.M11)
            ccFrustum(1).B = -(comboMatrix.M24 - comboMatrix.M21)
            ccFrustum(1).C = -(comboMatrix.M34 - comboMatrix.M31)
            ccFrustum(1).D = -(comboMatrix.M44 - comboMatrix.M41)

            Top clipping plane
            ccFrustum(2).A = -(comboMatrix.M14 - comboMatrix.M12)
            ccFrustum(2).B = -(comboMatrix.M24 - comboMatrix.M22)
            ccFrustum(2).C = -(comboMatrix.M34 - comboMatrix.M32)
            ccFrustum(2).D = -(comboMatrix.M44 - comboMatrix.M42)

            Bottom clipping plane
            ccFrustum(3).A = -(comboMatrix.M14 + comboMatrix.M12)
            ccFrustum(3).B = -(comboMatrix.M24 + comboMatrix.M22)
            ccFrustum(3).C = -(comboMatrix.M34 + comboMatrix.M32)
            ccFrustum(3).D = -(comboMatrix.M44 + comboMatrix.M42)

            Near clipping plane
            ccFrustum(4).A = -(comboMatrix.M14 + comboMatrix.M13)
            ccFrustum(4).B = -(comboMatrix.M24 + comboMatrix.M23)
            ccFrustum(4).C = -(comboMatrix.M34 + comboMatrix.M33)
            ccFrustum(4).D = -(comboMatrix.M44 + comboMatrix.M43)

            Far clipping plane
            ccFrustum(5).A = -(comboMatrix.M14 - comboMatrix.M13)
            ccFrustum(5).B = -(comboMatrix.M24 - comboMatrix.M23)
            ccFrustum(5).C = -(comboMatrix.M34 - comboMatrix.M33)
            ccFrustum(5).D = -(comboMatrix.M44 - comboMatrix.M43)

            If Normalize Then
                For I As Integer = 0 To 5
                    ccFrustum(I).Normalize()
                    NormalizePlane(ccFrustum(I))
                Next
            End If

        End Sub

Code:
        Public Function FrustumTestSphere(ByVal vCenter As m3dVector3D, ByVal Radius As Single) As Boolean

            Dim Distance As Single
            Dim tCenter As Vector3

            tCenter = vCenter.ToVector3
            tCenter.TransformCoordinate(ccCore.Device.Transform.World)

            For I As Integer = 0 To 5
                Distance = Plane.DotNormal(ccFrustum(I), tCenter)
                Debug.WriteLine(Distance)
                If Distance < -Radius Then
                    Return False
                End If
            Next

            Return True

        End Function
 
Back
Top