1
Vote

Frustum intersections might be buggy

description

OK, spent some time investigating this and I've gone as far as my 3D math abilities can take me.

Looking at the library... it seems that the Dot Product call to test if either the BoundingSphere or Point is in the plane, returns a distance of 0. Not sure what that means, but that's what it is giving me.

The code from the library is:

public FrustumIntersection IsPointInFrustum(Vector vector)
    {
        for (var planeIndex = 0; planeIndex < _planes.Length; planeIndex++)
        {
            var plane = _planes[planeIndex];
            var distance = plane.GetDistanceFromVector(vector);
            if (distance < 0)
            {
                return FrustumIntersection.Outside;
            }
        }
        return FrustumIntersection.Inside;

    }

    public FrustumIntersection IsSphereInFrustum(Vector vector, float radius)
    {
        float distance = 0;
        for (var planeIndex = 0; planeIndex < _planes.Length; planeIndex++)
        {
            var plane = _planes[planeIndex];
            distance = plane.GetDistanceFromVector(vector);

            if (distance < -radius)
            {
                return FrustumIntersection.Outside;
            }
            else if (distance < radius)
            {
                return FrustumIntersection.Intersect;
            }
        }
        return FrustumIntersection.Inside;
    }
Either one of these are falling out to return '.Inside' which may be true, but then this isn't what I'm trying to do.

Thinking the issue was related to view-updates, I put a DispatcherTimer on my FloatingWindow to update the view every 10ms and zoom out a little more, checking to see if the object was in view.
   void _wireframe_OnMeshLoadCompleted(DNC2Mesh dnc2mesh, EventArgs e)
    {
        gameWireframe.Scene.AddNode(dnc2mesh);
        gameWireframe.Camera.Target = dnc2mesh.Centerpoint; // dnc2mesh.Centroid(dnc2mesh.Vertices.ToArray());

        dnc2mesh.PrepareBoundingSphere();

        // zoom in on the center of my mesh so we can pan backwards
        float currentz = 0;
        SetCameraAndTarget(new Coordinate(0, 0, currentz), 0, 180);
        int direction = 1;

        // create a timer which I can then use to pan back
        DispatcherTimer zoomtimer = new DispatcherTimer();
        zoomtimer.Tick += new EventHandler(zoomtimer_Tick);
        zoomtimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
        zoomtimer.Start();

    }

    void zoomtimer_Tick(object sender, EventArgs e)
    {
        if ((gameWireframe.Camera.Frustum.IsSphereInFrustum(_wireframe.BoundingSphere.Center, _wireframe.BoundingSphere.Radius) != FrustumIntersection.Outside)
            && (_zoomSlider.Value >= (float)_zoomSlider.Maximum / 2))
            _zoomSlider.Value += 1;
        else
            ((DispatcherTimer)sender).Stop();
    }
Any help you can shed here would be appreciated.

Oh, and I also realized that I needed to explicitly PrepareBoundingSphere to get the values populated, that's why I do that after adding the item.

Peter





comments