Beispiel #1
0
    void RecursiveTraverseTree(Node node, Vector3 point, Action <T> action)
    {
        bool side = SpatialUtils.SideToPlane(node.plane, point);
        Node a = node.right, b = node.left;

        if (!side)
        {
            a = node.left; b = node.right;
        }

        if (a != null)
        {
            RecursiveTraverseTree(a, point, action);
        }

        if (action != null)
        {
            foreach (var obj in node.objs)
            {
                action(obj);
            }
        }

        if (b != null)
        {
            RecursiveTraverseTree(b, point, action);
        }
    }
Beispiel #2
0
    bool RecursiveIntersectPoint(Node node, Vector3 point)
    {
        bool side = SpatialUtils.SideToPlane(node.plane, point);

        if (side)
        {
            if (node.left != null)
            {
                return(RecursiveIntersectPoint(node.left, point));
            }
            return(false);
        }
        else
        {
            if (node.right != null)
            {
                return(RecursiveIntersectPoint(node.right, point));
            }
            return(true);
        }
    }
Beispiel #3
0
    public void Split <T>(Plane plane, ref List <T> front, ref List <T> back) where T : BSPtreeObject
    {
        bool s0 = SpatialUtils.SideToPlane(plane, vertices[0]);
        bool s1 = SpatialUtils.SideToPlane(plane, vertices[1]);
        bool s2 = SpatialUtils.SideToPlane(plane, vertices[2]);

        if (s0 && s1 && s2)
        {
            front.Add(this as T);
        }
        else if (!(s0 || s1 || s2))
        {
            back.Add(this as T);
        }
        else if (s0 && !(s1 || s2))
        {
            SplitObject(plane, 0, 1, 2, ref front, ref back);
        }
        else if (s1 && !(s2 || s0))
        {
            SplitObject(plane, 1, 2, 0, ref front, ref back);
        }
        else if (s2 && !(s0 || s1))
        {
            SplitObject(plane, 2, 0, 1, ref front, ref back);
        }
        else if (s0 && s1 && !s2)
        {
            SplitObject(plane, 2, 0, 1, ref back, ref front);
        }
        else if (s2 && s0 && !s1)
        {
            SplitObject(plane, 1, 2, 0, ref back, ref front);
        }
        else if (s1 && s2 && !s0)
        {
            SplitObject(plane, 0, 1, 2, ref back, ref front);
        }
    }
Beispiel #4
0
    public UbietyResult UbietyToPlane(Plane plane)
    {
        if (SpatialUtils.PlaneCoincide(plane, this.plane))
        {
            return(UbietyResult.Coincident);
        }

        bool s0 = SpatialUtils.SideToPlane(plane, vertices[0]);
        bool s1 = SpatialUtils.SideToPlane(plane, vertices[1]);
        bool s2 = SpatialUtils.SideToPlane(plane, vertices[2]);

        if (s0 && s1 && s2)
        {
            return(UbietyResult.Front);
        }
        else if (!(s0 || s1 || s2))
        {
            return(UbietyResult.Back);
        }
        else
        {
            return(UbietyResult.Cross);
        }
    }