Esempio n. 1
0
        void GetProjParams(Camera c, out Vector3 wCamMinOnPlane, out Vector3 wCamMaxOnPlane)
        {
            if (c.orthographic)
            {
                var camPos = c.transform.position;
                var size   = (c.transform.up + c.transform.right * c.aspect) * c.orthographicSize;

                var   camMin = camPos - size;
                var   camMax = camPos + size;
                var   plane  = new Plane(transform.up, transform.position);
                float enter;
                var   r = new Ray(camMin, c.transform.forward);
                plane.Raycast(r, out enter);
                camMin = r.GetPoint(enter);
                r      = new Ray(camMax, c.transform.forward);
                plane.Raycast(r, out enter);
                camMax = r.GetPoint(enter);


                wCamMinOnPlane = new Vector3(
                    Mathf.Min(camMin.x, camMax.x),
                    Mathf.Min(camMin.y, camMax.y),
                    Mathf.Min(camMin.z, camMax.z));
                wCamMaxOnPlane = new Vector3(
                    Mathf.Max(camMin.x, camMax.x),
                    Mathf.Max(camMin.y, camMax.y),
                    Mathf.Max(camMin.z, camMax.z));
            }
            else
            {
                var   corners = c.ProjectFrustumOnXZPlane();
                float minX, maxX, minY, maxY, minZ, maxZ;
                MUtils.MinMax(out minX, out maxX, corners[0].x, corners[1].x, corners[2].x, corners[3].x);
                MUtils.MinMax(out minY, out maxY, corners[0].y, corners[1].y, corners[2].y, corners[3].y);
                MUtils.MinMax(out minZ, out maxZ, corners[0].z, corners[1].z, corners[2].z, corners[3].z);
                wCamMinOnPlane = new Vector3(minX, minY, minZ);
                wCamMaxOnPlane = new Vector3(maxX, maxY, maxZ);
            }
        }