Exemplo n.º 1
0
    void RecursiveBuildTree(Node node)
    {
        if (node.objs.Count <= 1)
        {
            return;
        }

        Plane splitPlane = PickSplittingPlane(node.objs);

        List <T> nodeObjs  = new List <T>();
        List <T> frontObjs = new List <T>();
        List <T> backObjs  = new List <T>();

        foreach (var obj in node.objs)
        {
            if (SpatialUtils.PlaneCoincide(splitPlane, obj.plane))
            {
                nodeObjs.Add(obj);
            }
            else
            {
                obj.Split(splitPlane, ref frontObjs, ref backObjs);
            }
        }

        node.plane = splitPlane;
        node.objs  = nodeObjs;

        if (frontObjs.Count > 0)
        {
            node.left      = new Node();
            node.left.objs = frontObjs;
            RecursiveBuildTree(node.left);
        }

        if (backObjs.Count > 0)
        {
            node.right      = new Node();
            node.right.objs = backObjs;
            RecursiveBuildTree(node.right);
        }
    }
Exemplo n.º 2
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);
        }
    }