Esempio n. 1
0
        static Bounds GetScreenSpaceGroupBoundingBox(
            CinemachineTargetGroup group, ref Vector3 pos, Quaternion orientation)
        {
            Matrix4x4 observer = Matrix4x4.TRS(pos, orientation, Vector3.one);
            Vector2   minAngles, maxAngles, zRange;

            group.GetViewSpaceAngularBounds(observer, out minAngles, out maxAngles, out zRange);

            Quaternion q                 = Quaternion.identity.ApplyCameraRotation((minAngles + maxAngles) / 2, Vector3.up);
            Vector3    localPosAdustment = q * new Vector3(0, 0, (zRange.y + zRange.x) / 2);

            localPosAdustment.z = 0;
            pos      = observer.MultiplyPoint3x4(localPosAdustment);
            observer = Matrix4x4.TRS(pos, orientation, Vector3.one);
            group.GetViewSpaceAngularBounds(observer, out minAngles, out maxAngles, out zRange);

            float   zSize  = zRange.y - zRange.x;
            float   z      = zRange.x + (zSize / 2);
            Vector2 angles = new Vector2(89.5f, 89.5f);

            if (zRange.x > 0)
            {
                angles = Vector3.Max(maxAngles, UnityVectorExtensions.Abs(minAngles)) * Mathf.Deg2Rad;
                angles = Vector2.Min(angles, new Vector2(89.5f, 89.5f));
            }
            return(new Bounds(new Vector3(0, 0, z),
                              new Vector3(Mathf.Tan(angles.y) * z * 2, Mathf.Tan(angles.x) * z * 2, zSize)));
        }
Esempio n. 2
0
        /// <param name="observer">Point of view</param>
        /// <param name="newFwd">New forward direction to use when interpreting the return value</param>
        /// <returns>Bounding box in a slightly rotated version of observer, as specified by newFwd</returns>
        static Bounds GetScreenSpaceGroupBoundingBox(
            CinemachineTargetGroup group, Matrix4x4 observer, out Vector3 newFwd)
        {
            Vector2 minAngles, maxAngles, zRange;

            group.GetViewSpaceAngularBounds(observer, out minAngles, out maxAngles, out zRange);
            Vector2 shift = (minAngles + maxAngles) / 2;

            newFwd = Quaternion.identity.ApplyCameraRotation(shift, Vector3.up) * Vector3.forward;
            newFwd = observer.MultiplyVector(newFwd);

            float   d      = (zRange.y + zRange.x);
            Vector2 angles = (maxAngles - shift) * Mathf.Deg2Rad;

            angles = Vector2.Min(angles, new Vector2(89.5f, 89.5f));
            return(new Bounds(
                       new Vector3(0, 0, d / 2),
                       new Vector3(Mathf.Tan(angles.y) * d, Mathf.Tan(angles.x) * d, zRange.y - zRange.x)));
        }