Beispiel #1
0
    public void DrawTree(Vector3 offset, int iteration)
    {
        Color color = this is BeachLineArc ? Color.green : Color.cyan;
        // Draw square
        float square_size = 0.5f;

        Debug.DrawRay(new Vector3(-square_size, -square_size, 0) + offset, 2 * Vector3.right * square_size, color);
        Debug.DrawRay(new Vector3(-square_size, square_size, 0) + offset, 2 * Vector3.right * square_size, color);
        Debug.DrawRay(new Vector3(-square_size, square_size, 0) + offset, 2 * Vector3.down * square_size, color);
        Debug.DrawRay(new Vector3(square_size, square_size, 0) + offset, 2 * Vector3.down * square_size, color);

        float   child_x_offset     = 4f / Mathf.Pow(2, iteration);
        Vector3 left_child_offset  = new Vector3(offset.x + child_x_offset, offset.y - 1.5f, 0);
        Vector3 right_child_offset = new Vector3(offset.x - child_x_offset, offset.y - 1.5f, 0);

        if (LeftChild != null)
        {
            Debug.DrawLine(
                offset + (new Vector3(0, -square_size, 0)),
                left_child_offset + (new Vector3(0, square_size, 0)),
                Color.white);
            LeftChild.DrawTree(left_child_offset, iteration + 1);
        }
        if (RightChild != null)
        {
            Debug.DrawLine(
                offset + (new Vector3(0, -square_size, 0)),
                right_child_offset + (new Vector3(0, square_size, 0)),
                Color.white);
            RightChild.DrawTree(right_child_offset, iteration + 1);
        }
    }