GetFrustum() private static method

private static GetFrustum ( Camera camera, Vector3 near, Vector3 far, float &frustumAspect ) : bool
camera UnityEngine.Camera
near Vector3
far Vector3
frustumAspect float
return bool
Ejemplo n.º 1
0
        public void OnSceneGUI()
        {
            Camera camera = (Camera)base.target;

            if (CameraEditor.IsViewPortRectValidToRender(camera.rect))
            {
                SceneViewOverlay.Window(new GUIContent("Camera Preview"), new SceneViewOverlay.WindowFunction(this.OnOverlayGUI), -100, base.target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget);
                Color color  = Handles.color;
                Color color2 = CameraEditor.kGizmoCamera;
                color2.a     *= 2f;
                Handles.color = color2;
                Vector3[] array = new Vector3[4];
                float     num;
                if (CameraEditor.GetFrustum(camera, null, array, out num))
                {
                    Vector3 vector  = array[0];
                    Vector3 vector2 = array[1];
                    Vector3 vector3 = array[2];
                    Vector3 vector4 = array[3];
                    bool    changed = GUI.changed;
                    Vector3 vector5 = Vector3.Lerp(vector, vector3, 0.5f);
                    float   num2    = -1f;
                    Vector3 a       = CameraEditor.MidPointPositionSlider(vector2, vector3, camera.transform.up);
                    if (!GUI.changed)
                    {
                        a = CameraEditor.MidPointPositionSlider(vector, vector4, -camera.transform.up);
                    }
                    if (GUI.changed)
                    {
                        num2 = (a - vector5).magnitude;
                    }
                    GUI.changed = false;
                    a           = CameraEditor.MidPointPositionSlider(vector4, vector3, camera.transform.right);
                    if (!GUI.changed)
                    {
                        a = CameraEditor.MidPointPositionSlider(vector, vector2, -camera.transform.right);
                    }
                    if (GUI.changed)
                    {
                        num2 = (a - vector5).magnitude / num;
                    }
                    if (num2 >= 0f)
                    {
                        Undo.RecordObject(camera, "Adjust Camera");
                        if (camera.orthographic)
                        {
                            camera.orthographicSize = num2;
                        }
                        else
                        {
                            Vector3 a2 = vector5 + camera.transform.up * num2;
                            camera.fieldOfView = Vector3.Angle(camera.transform.forward, a2 - camera.transform.position) * 2f;
                        }
                        changed = true;
                    }
                    GUI.changed   = changed;
                    Handles.color = color;
                }
            }
        }
Ejemplo n.º 2
0
        internal static void RenderGizmo(Camera camera)
        {
            Vector3[] array  = new Vector3[4];
            Vector3[] array2 = new Vector3[4];
            float     num;

            if (CameraEditor.GetFrustum(camera, array, array2, out num))
            {
                Color color = Handles.color;
                Handles.color = CameraEditor.kGizmoCamera;
                for (int i = 0; i < 4; i++)
                {
                    Handles.DrawLine(array[i], array[(i + 1) % 4]);
                    Handles.DrawLine(array2[i], array2[(i + 1) % 4]);
                    Handles.DrawLine(array[i], array2[i]);
                }
                Handles.color = color;
            }
        }
Ejemplo n.º 3
0
        internal static void RenderGizmo(Camera camera)
        {
            Vector3[] near = new Vector3[4];
            Vector3[] far  = new Vector3[4];
            float     frustumAspect;

            if (!CameraEditor.GetFrustum(camera, near, far, out frustumAspect))
            {
                return;
            }
            Color color = Handles.color;

            Handles.color = CameraEditor.kGizmoCamera;
            for (int index = 0; index < 4; ++index)
            {
                Handles.DrawLine(near[index], near[(index + 1) % 4]);
                Handles.DrawLine(far[index], far[(index + 1) % 4]);
                Handles.DrawLine(near[index], far[index]);
            }
            Handles.color = color;
        }
Ejemplo n.º 4
0
        public void OnSceneGUI()
        {
            Camera target = (Camera)this.target;

            if (!CameraEditor.IsViewPortRectValidToRender(target.rect))
            {
                return;
            }
            SceneViewOverlay.Window(new GUIContent("Camera Preview"), new SceneViewOverlay.WindowFunction(this.OnOverlayGUI), -100, this.target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget);
            Color color        = Handles.color;
            Color kGizmoCamera = CameraEditor.kGizmoCamera;

            kGizmoCamera.a *= 2f;
            Handles.color   = kGizmoCamera;
            Vector3[] far = new Vector3[4];
            float     frustumAspect;

            if (!CameraEditor.GetFrustum(target, (Vector3[])null, far, out frustumAspect))
            {
                return;
            }
            Vector3 vector3_1 = far[0];
            Vector3 vector3_2 = far[1];
            Vector3 vector3_3 = far[2];
            Vector3 vector3_4 = far[3];
            bool    flag      = GUI.changed;
            Vector3 vector3_5 = Vector3.Lerp(vector3_1, vector3_3, 0.5f);
            float   num       = -1f;
            Vector3 vector3_6 = CameraEditor.MidPointPositionSlider(vector3_2, vector3_3, target.transform.up);

            if (!GUI.changed)
            {
                vector3_6 = CameraEditor.MidPointPositionSlider(vector3_1, vector3_4, -target.transform.up);
            }
            if (GUI.changed)
            {
                num = (vector3_6 - vector3_5).magnitude;
            }
            GUI.changed = false;
            Vector3 vector3_7 = CameraEditor.MidPointPositionSlider(vector3_4, vector3_3, target.transform.right);

            if (!GUI.changed)
            {
                vector3_7 = CameraEditor.MidPointPositionSlider(vector3_1, vector3_2, -target.transform.right);
            }
            if (GUI.changed)
            {
                num = (vector3_7 - vector3_5).magnitude / frustumAspect;
            }
            if ((double)num >= 0.0)
            {
                Undo.RecordObject((UnityEngine.Object)target, "Adjust Camera");
                if (target.orthographic)
                {
                    target.orthographicSize = num;
                }
                else
                {
                    Vector3 vector3_8 = vector3_5 + target.transform.up * num;
                    target.fieldOfView = Vector3.Angle(target.transform.forward, vector3_8 - target.transform.position) * 2f;
                }
                flag = true;
            }
            GUI.changed   = flag;
            Handles.color = color;
        }