コード例 #1
0
    public void UpdateBounds(bool visualize = true)
    {
        if (!gameObject.activeSelf)
        {
            return;
        }

        showBox = visualize;

        Vector3[] verts = MeshUtility.GetMesh(transform).vertices;

        //convert to world point, then screen space
        for (int i = 0; i < verts.Length; i++)
        {
            verts[i] = cam.WorldToScreenPoint(transform.TransformPoint(verts[i]));
            //make sure we dont go off screen
            if (verts[i].x <0 || verts[i].x> Screen.width || verts[i].y <0 || verts[i].y> Screen.height)
            {
                verts[i] = verts[0];
            }
        }

        //create new box
        currBox = new Rect {
            xMin = verts[0].x,
            xMax = verts[0].x,
            yMin = verts[0].y,
            yMax = verts[0].y
        };

        //find min and max screen space values
        for (int i = 0; i < verts.Length; i++)
        {
            currBox.xMin = currBox.xMin < verts[i].x ? currBox.xMin : verts[i].x;
            currBox.xMax = currBox.xMax > verts[i].x ? currBox.xMax : verts[i].x;
            currBox.yMin = currBox.yMin < verts[i].y ? currBox.yMin : verts[i].y;
            currBox.yMax = currBox.yMax > verts[i].y ? currBox.yMax : verts[i].y;
        }

        photoRect = currBox;

        currBox.yMin = Screen.height - currBox.yMin;
        currBox.yMax = Screen.height - currBox.yMax;
    }
コード例 #2
0
    // funzione che fa un update dei bounds dell'oggetto, aprendo alla possibilità di mostrarli o meno in una bounding box i cui limiti sono min e max di x e y, a seconda del parametro booleano che le viene passato. I bounds, inizialmente statici, vengono convertiti sulla base della posizione della telecamera, assicurandosi che non finiscano fuori dal campo visivo di quest'ultima.
    public void UpdateBounds(bool visualize = true)
    {
        if (!gameObject.activeSelf)
        {
            return;
        }

        showBox = visualize;

        Vector3[] verts = MeshUtility.GetMesh(transform).vertices;

        for (int i = 0; i < verts.Length; i++)
        {
            verts[i] = cam.WorldToScreenPoint(transform.TransformPoint(verts[i]));
            if (verts[i].x <0 || verts[i].x> Screen.width || verts[i].y <0 || verts[i].y> Screen.height)
            {
                verts[i] = verts[0];
            }
        }

        currBox = new Rect {
            xMin = verts[0].x,
            xMax = verts[0].x,
            yMin = verts[0].y,
            yMax = verts[0].y
        };

        for (int i = 0; i < verts.Length; i++)
        {
            currBox.xMin = currBox.xMin < verts[i].x ? currBox.xMin : verts[i].x;
            currBox.xMax = currBox.xMax > verts[i].x ? currBox.xMax : verts[i].x;
            currBox.yMin = currBox.yMin < verts[i].y ? currBox.yMin : verts[i].y;
            currBox.yMax = currBox.yMax > verts[i].y ? currBox.yMax : verts[i].y;
        }

        photoRect = currBox;

        currBox.yMin = Screen.height - currBox.yMin;
        currBox.yMax = Screen.height - currBox.yMax;
    }
コード例 #3
0
 void Start()
 {
     originalMesh = MeshUtility.GetMesh(transform);
 }