Пример #1
0
    public static Sphere CalculateBoundingSphere(DMC.Node node)
    {
        Sphere s = new Sphere();

        Vector3 minExt = node.Vertices[0];
        Vector3 maxExt = node.Vertices[0];

        for (int i = 1; i < 4; i++)
        {
            minExt = Min(minExt, node.Vertices[i]);
            maxExt = Max(maxExt, node.Vertices[i]);
        }

        s.Center = new Vector3(0.5f * (minExt.x + maxExt.x), 0.5f * (minExt.y + maxExt.y), 0.5f * (minExt.z + maxExt.z));

        float maxDist = 0f;

        foreach (Vector3 p in node.Vertices)
        {
            float dist = Vector3.Distance(p, s.Center);
            if (dist > maxDist)
            {
                maxDist = dist;
            }
        }
        s.Radius = maxDist / 2f;

        return(s);
    }
Пример #2
0
    public static void DrawNode(DMC.Node node, float scale = 1, int f = 0)
    {
        Gizmos.color = Color.cyan;
        //Vector3 offset = new Vector3(f * 1.4f, 0, 0);
        Vector3 offset = new Vector3(f * 0, 0, 0);

        if (node.IsLeaf)
        {
            for (int i = 0; i < 6; i++)
            {
                Vector3 pa = (node.Vertices[DMC.Lookups.EdgePairs[i, 0]] + offset) * scale;
                Vector3 pb = (node.Vertices[DMC.Lookups.EdgePairs[i, 1]] + offset) * scale;
                Gizmos.DrawLine(pa, pb);
            }
        }
        else
        {
            DrawNode(node.Children[0], f);
            DrawNode(node.Children[1], f);
        }
    }