Example #1
0
        /* ************************************************************************************************
        * Function Name: GetProcessors
        * Input: None
        * Output: None
        * Purpose: This function will generate a list of image processors installed on the telescope
        * craft.
        * ************************************************************************************************/
        private void GetProcessors()
        {
            Processors.Clear();

            foreach (Part p in FlightGlobals.ActiveVessel.Parts)
            {
                CactEyeProcessor cpu = p.GetComponent <CactEyeProcessor>();
                if (cpu != null)
                {
                    if (!Processors.Contains(cpu))
                    {
                        Processors.Add(cpu);
                    }
                }
            }

            Debug.Log("CactEye 2: Found " + Processors.Count().ToString() + " Processors.");

            if (Processors.Count <CactEyeProcessor>() > 0)
            {
                ActiveProcessor       = Processors.First <CactEyeProcessor>();
                CurrentProcessorIndex = 0;

                //if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                //{
                //    ActiveProcessor.Active = true;
                //}
            }
        }
Example #2
0
        private CactEyeProcessor GetPrevious(IEnumerable <CactEyeProcessor> list, CactEyeProcessor current)
        {
            try
            {
                //return list.SkipWhile(x => !x.Equals(current)).Skip(1).First();
                //lastAgentIDAarhus = agents[ index == -1 ? 0 : index % ( agents.Count - 1 ) ];
                if (CurrentProcessorIndex == 0)
                {
                    CurrentProcessorIndex = Processors.Count - 1;
                }
                else
                {
                    CurrentProcessorIndex--;
                }

                //return Processors[CurrentProcessorIndex == -1 ? 0 : CurrentProcessorIndex % (Processors.Count - 1)];
                Debug.Log("CactEye 2: CurrentProcessorIndex: " + CurrentProcessorIndex.ToString());
                return(Processors[CurrentProcessorIndex]);
            }
            catch (Exception e)
            {
                Debug.Log("CactEye 2: Exception #: Was not able to find the next processor, even though there is one.");
                Debug.Log(e.ToString());

                return(Processors.FirstOrDefault());
            }
        }
Example #3
0
        private CactEyeProcessor GetNext(IEnumerable <CactEyeProcessor> list, CactEyeProcessor current)
        {
            try
            {
                //return list.SkipWhile(x => !x.Equals(current)).Skip(1).First();
                //lastAgentIDAarhus = agents[ index == -1 ? 0 : index % ( agents.Count - 1 ) ];
                if ((CurrentProcessorIndex + 1) < Processors.Count)
                {
                    CurrentProcessorIndex++;
                }
                else
                {
                    CurrentProcessorIndex = 0;
                }

                //return Processors[CurrentProcessorIndex == -1 ? 0 : CurrentProcessorIndex % (Processors.Count - 1)];
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: CurrentProcessorIndex: " + CurrentProcessorIndex.ToString());
                }

                return(Processors[CurrentProcessorIndex]);
            }
            catch (Exception e)
            {
                Debug.Log("CactEye 2: Exception 6: Was not able to find the next processor, even though there is one.");
                Debug.Log(e.ToString());

                return(Processors[0]);
            }
        }
Example #4
0
        /*
         * Function name: UpdateTexture
         * Input: None
         * Output: A fully rendered texture of what's through the telescope.
         * Purpose: This function will produce a single frame texture of what image is being looked
         * at through the telescope.
         * Note: Need to modify behavior depending on what processor is currently active.
         */
        public Texture2D UpdateTexture(CactEyeProcessor CPU, RenderTexture RT, Texture2D Output)
        {
            RenderTexture CurrentRT = RenderTexture.active;

            RenderTexture.active = RT;

            //Update position of the cameras
            foreach (Camera Cam in CameraObject)
            {
                if (Cam != null)
                {
                    //The if statement fixes a bug with the camera position and timewarp.
                    if (Cam.name.Contains("0"))
                    {
                        //Cam.transform = CameraTransform;
                        Cam.transform.position = CameraTransform.position;
                    }
                    Cam.transform.up      = CameraTransform.up;
                    Cam.transform.forward = CameraTransform.forward;
                    if (!RotationLock)
                    {
                        Cam.transform.rotation = CameraTransform.rotation;
                    }
                    Cam.fieldOfView   = FieldOfView;
                    Cam.targetTexture = RT;
                }
                else
                {
                    Debug.Log("CactEye 2: " + Cam.name.ToString() + " was not found!");
                }
            }

            CameraObject[0].Render();
            CameraObject[1].Render();
            foreach (Renderer r in skyboxRenderers)
            {
                r.enabled = false;
            }
            foreach (ScaledSpaceFader s in scaledSpaceFaders)
            {
                s.r.enabled = true;
            }
            CameraObject[1].clearFlags   = CameraClearFlags.Depth;
            CameraObject[1].farClipPlane = 3e30f;
            CameraObject[1].Render();
            foreach (Renderer r in skyboxRenderers)
            {
                r.enabled = true;
            }
            CameraObject[2].Render();
            CameraObject[3].Render();

            Output.ReadPixels(new Rect(0, 0, Output.width, Output.height), 0, 0);
            Output = CPU.ApplyFilter("Standard", Output);
            Output.Apply();
            RenderTexture.active = CurrentRT;
            return(Output);
        }
Example #5
0
 /* ************************************************************************************************
 * Function Name: DestroyProcessors
 * Input: None
 * Output: None
 * Purpose: This function will destroy all onboard processors.
 * ************************************************************************************************/
 public void DestroyProcessors()
 {
     foreach (Part p in FlightGlobals.ActiveVessel.Parts)
     {
         CactEyeProcessor cpu = p.GetComponent <CactEyeProcessor>();
         if (cpu != null)
         {
             cpu.Die(); //Good-bye!
         }
     }
 }
Example #6
0
 public Texture2D UpdateTexture(CactEyeProcessor CPU)
 {
     if (CPU)
     {
         return(UpdateTexture(CPU, ScopeRenderTexture, ScopeTexture2D));
     }
     else
     {
         return(new Texture2D(CameraWidth, CameraHeight));
     }
 }
Example #7
0
        //Might take a look at using lazy initialization for enabling/disabling the menu object
        public void Toggle()
        {
            if (!IsGUIVisible)
            {
                //Moved to here from the constructor; this should get a new list of gyros
                //every time the player enables the menu to account for part changes due to
                //docking/undocking operations.
                try
                {
                    //Grab Reaction Wheels
                    GetReactionWheels();
                    GetProcessors();

                    //if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                    //{
                    //    ActiveProcessor.ActivateProcessor();
                    //}

                    ActiveProcessor.ActivateProcessor();
                }
                catch (Exception E)
                {
                    Debug.Log("CactEye 2: Exception 3: Was not able to get a list of Reaction Wheels or Processors.");
                    Debug.Log(E.ToString());
                }
            }

            else
            {
                if (ActiveProcessor != null)
                {
                    if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                    {
                        ActiveProcessor.DeactivateProcessor();
                    }
                    ActiveProcessor = null;
                }
            }
            IsGUIVisible = !IsGUIVisible;
        }
Example #8
0
        private void MainGUI(int WindowID)
        {
            timer     += Planetarium.GetUniversalTime() - storedTime;
            storedTime = Planetarium.GetUniversalTime();
            GUILayout.BeginHorizontal();
            //Top right hand corner button that exits the window.
            if (GUI.Button(new Rect(WindowPosition.width - 18, 2, 16, 16), ""))
            {
                Toggle();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            //What you see looking through the telescope.
            ScopeRect = GUILayoutUtility.GetRect(400f, 400f);
            Texture2D ScopeScreen = CameraModule.UpdateTexture(ActiveProcessor);

            GUI.DrawTexture(ScopeRect, ScopeScreen);


            //Draw the preview texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin, ScopeRect.yMax - 32f, 128f, 32f), PreviewTexture);
            //Draw the crosshair texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin + (0.5f * ScopeRect.width) - 64, ScopeRect.yMin + (0.5f * ScopeRect.height) - 64, 128, 128), CrosshairTexture);
            //Draw the notification label
            if (timer > 5f)
            {
                Notification = "";
            }
            GUI.Label(new Rect(ScopeRect.xMin + 16, ScopeRect.yMin + 16, 600, 32), new GUIContent(Notification));


            ControlRect = GUILayoutUtility.GetRect(300f, 20f);

            if (Processors.Count > 1)
            {
                //Previous button
                if (GUI.Button(new Rect(433f, 72f, 32, 32), Back9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor        = GetPrevious(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }
                if (GUI.Button(new Rect(635f, 72f, 32, 32), Forward9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor        = GetNext(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }
            }
            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
            GUI.Label(new Rect(475f, 40f, 150, 32), "Active Processor");
            GUI.Label(new Rect(475f, 72f, 150, 32), ActiveProcessor.GetProcessorType());
            if (!isSmallOptics)
            {
                if (GUI.Button(new Rect(475f, 124f, 150, 48), ToggleAperatureIcon))
                {
                    aperature.Toggle();
                }
            }

            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && ActiveProcessor.GetProcessorType().Contains("Wide Field"))
            {
                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleRight;
                GUI.Label(new Rect(425f, 188f, 150, 32), "Store Image:");
                if (GUI.Button(new Rect(585f, 188f, 32, 32), SaveScreenshotTexture))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    Notification = " Screenshot saved to " + WriteTextureToDrive(CameraModule.TakeScreenshot(ActiveProcessor));
                    timer        = 0f;
                }
            }
            else
            {
                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                GUI.Label(new Rect(475f, 188f, 150, 32), "Imaging not available.");
            }
            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleRight;
                GUI.Label(new Rect(425f, 252f, 150, 32), "Process Data:");
                if (GUI.Button(new Rect(585f, 252f, 32, 32), Atom6Icon))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    //ActiveProcessor.GenerateScienceReport(TakeScreenshot(ActiveProcessor.GetType()));
                    try
                    {
                        Notification = ActiveProcessor.DoScience(GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, 500f), scienceMultiplier, CameraModule.FieldOfView, CameraModule.TakeScreenshot(ActiveProcessor));
                    }
                    catch (Exception e)
                    {
                        Notification = "An error occured. Please post that you're having this error on the official CactEye 2 thread on the Kerbal Forums.";
                        Debug.Log("CactEye 2: Exception 4: An error occured producing a science report!");
                        Debug.Log(e.ToString());
                    }

                    timer = 0f;
                }
            }
            else
            {
                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                GUI.Label(new Rect(425f, 252f, 250, 32), "Data processing not available.");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            //Draw Processor controls in bottom center of display, with observation and screenshot buttons in center.
            DrawTargetPointer();

            if (ActiveProcessor)
            {
                //Close window down if we run out of power
                if (!ActiveProcessor.IsActive())
                {
                    //    Toggle();
                    //    ScreenMessages.PostScreenMessage("Image processor is out of power. Please restore power to telescope.", 6, ScreenMessageStyle.UPPER_CENTER);
                    ActiveProcessor = null;
                    Notification    = "Image Processor is out of power. Please restore power to telescope";
                    ScreenMessages.PostScreenMessage(Notification, 3f, ScreenMessageStyle.UPPER_CENTER);
                    timer = 0f;
                    Toggle();
                }

                //Zoom Feedback Label.
                string LabelZoom = "Zoom/Magnification: x";
                if (CameraModule.FieldOfView > 0.0064)
                {
                    LabelZoom += string.Format("{0:####0.0}", 64 / CameraModule.FieldOfView);
                }
                else
                {
                    LabelZoom += string.Format("{0:0.00E+0}", (64 / CameraModule.FieldOfView));
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label(LabelZoom);
                GUILayout.EndHorizontal();

                //Zoom Slider Controls.
                GUILayout.BeginHorizontal();
                FieldOfView = GUILayout.HorizontalSlider(FieldOfView, 0f, 1f);
                CameraModule.FieldOfView = 0.5f * Mathf.Pow(4f - FieldOfView * (4f - Mathf.Pow(ActiveProcessor.GetMinimumFOV(), (1f / 3f))), 3);
                GUILayout.EndHorizontal();

                //Log spam
                //Debug.Log("CactEye 2: MinimumFOV = " + ActiveProcessor.GetMinimumFOV().ToString());
            }

            else
            {
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Processor not installed; optics module cannot function without an image processor.");
                GUILayout.EndHorizontal();
            }

            //Gyro GUI. Active only if the craft has an active gyro
            if (GyroEnabled)
            {
                //Gyro Slider Label
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Gyro Sensitivity:  " + GyroSensitivity.ToString("P") + " + minimum gyroscopic torgue.", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                //Gyro Slider Controls.
                GUILayout.BeginHorizontal();
                GyroSensitivity = GUILayout.HorizontalSlider(GyroSensitivity, 0f, 1f, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                SetTorgue();
            }

            //Make the window draggable by the top bar only.
            GUI.DragWindow(new Rect(0, 0, WindowPosition.width, 16));
        }
Example #9
0
        /* ************************************************************************************************
         * Function Name: DrawProcessorControls
         * Input: None
         * Output: None
         * Purpose: This function will draw the four main processor control objects: the screenshot
         * button, the science button, and the next/previous processor buttons.
         * The screenshot button will only display and be available if the telescope has a valid
         * processor installed on the scope.
         * The science button will only appear if a target is selected, if there is a valid processor
         * installed, and if the game is not a sandbox game. It will generate a science report based
         * on the selected target.
         * The next/previous buttons will only appear if the scope has more than one processor installed,
         * and will allow the player to cycle through the different processors.
         * ************************************************************************************************/
        private void DrawProcessorControls()
        {
            //if (!ActiveProcessor.IsActive())
            //{
            //    //Craft is out of power.
            //    Notification = "Image processor is out of power; shutting down processor.";
            //    timer = 0f;
            //    Processors.Remove(ActiveProcessor);
            //}

            //Draw save icon
            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && ActiveProcessor.GetProcessorType().Contains("Wide Field"))
            {
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), SaveScreenshotTexture))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    Notification = " Screenshot saved to " + WriteTextureToDrive(CameraModule.TakeScreenshot(ActiveProcessor));
                    timer = 0f;
                }
            }

            //Draw gather science icon
            //Atom6 icon from Freepik
            //<div>Icons made by Freepik from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a>         is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0">CC BY 3.0</a></div>
            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Atom6Icon))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    //ActiveProcessor.GenerateScienceReport(TakeScreenshot(ActiveProcessor.GetType()));
                    try
                    {
                        Notification = ActiveProcessor.DoScience(GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, 500f), false, CameraModule.FieldOfView, CameraModule.TakeScreenshot(ActiveProcessor));
                    }
                    catch (Exception e)
                    {
                        Notification = "An error occured. Please post that you're having this error on the official CactEye 2 thread on the Kerbal Forums.";
                        Debug.Log("CactEye 2: Exception 4: An error occured producing a science report!");
                        Debug.Log(e.ToString());
                    }

                    timer = 0f;
                }
            }

            //Got an off-by-one error in the list somewhere
            //Previous/Next buttons
            if (Processors.Count<CactEyeProcessor>() > 1)
            {
                //Previous button
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Back9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor = GetPrevious(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }

                //Next Button
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Forward9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor = GetNext(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }
            }
        }
Example #10
0
        //Might take a look at using lazy initialization for enabling/disabling the menu object
        public void Toggle()
        {
            if (!IsGUIVisible)
            {
                //Moved to here from the constructor; this should get a new list of gyros
                //every time the player enables the menu to account for part changes due to
                //docking/undocking operations.
                try
                {
                    //Grab Reaction Wheels
                    GetReactionWheels();
                    GetProcessors();

                    //if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                    //{
                    //    ActiveProcessor.ActivateProcessor();
                    //}

                    ActiveProcessor.ActivateProcessor();
                }
                catch (Exception E)
                {
                    Debug.Log("CactEye 2: Exception 3: Was not able to get a list of Reaction Wheels or Processors.");
                    Debug.Log(E.ToString());
                }

                RenderingManager.AddToPostDrawQueue(3, new Callback(DrawGUI));
            }

            else
            {
                if (ActiveProcessor != null)
                {
                    if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                    {
                        ActiveProcessor.DeactivateProcessor();
                    }
                    ActiveProcessor = null;
                }

                RenderingManager.RemoveFromPostDrawQueue(3, new Callback(DrawGUI));
            }
            IsGUIVisible = !IsGUIVisible;
        }
Example #11
0
        private void MainGUI(int WindowID)
        {
            timer     += Planetarium.GetUniversalTime() - storedTime;
            storedTime = Planetarium.GetUniversalTime();

            //Top right hand corner button that exits the window.
            if (GUI.Button(new Rect(WindowPosition.width - 18, 2, 16, 16), ""))
            {
                Toggle();
            }

            //What you see looking through the telescope.
            ScopeRect = GUILayoutUtility.GetRect(Screen.width * 0.4f, Screen.width * 0.4f);
            Texture2D ScopeScreen = CameraModule.UpdateTexture(ActiveProcessor);

            GUI.DrawTexture(ScopeRect, ScopeScreen);

            //Draw the preview texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin, ScopeRect.yMax - 32f, 128f, 32f), PreviewTexture);
            //Draw the crosshair texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin + (0.5f * ScopeRect.width) - 64, ScopeRect.yMin + (0.5f * ScopeRect.height) - 64, 128, 128), CrosshairTexture);
            //Draw the notification label
            if (timer > 5f)
            {
                Notification = "";
            }
            GUI.Label(new Rect(ScopeRect.xMin + 16, ScopeRect.yMin + 16, 600, 32), new GUIContent(Notification));

            //Draw Processor controls in bottom center of display, with observation and screenshot buttons in center.
            DrawProcessorControls();
            DrawTargetPointer();

            if (ActiveProcessor)
            {
                //Close window down if we run out of power
                if (!ActiveProcessor.IsActive())
                {
                    //    Toggle();
                    //    ScreenMessages.PostScreenMessage("Image processor is out of power. Please restore power to telescope.", 6, ScreenMessageStyle.UPPER_CENTER);
                    ActiveProcessor = null;
                    Notification    = "Image Processor is out of power. Please restore power to telescope";
                    timer           = 0f;
                }

                //Zoom Feedback Label.
                string LabelZoom = "Zoom/Magnification: x";
                if (CameraModule.FieldOfView > 0.0064)
                {
                    LabelZoom += string.Format("{0:####0.0}", 64 / CameraModule.FieldOfView);
                }
                else
                {
                    LabelZoom += string.Format("{0:0.00E+0}", (64 / CameraModule.FieldOfView));
                }
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label(LabelZoom);

                //Active Processor and status Label
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                GUILayout.Label("Active Processor: " + ActiveProcessor.GetProcessorType());
                GUILayout.EndHorizontal();

                //Zoom Slider Controls.
                GUILayout.BeginHorizontal();
                FieldOfView = GUILayout.HorizontalSlider(FieldOfView, 0f, 1f);
                CameraModule.FieldOfView = 0.5f * Mathf.Pow(4f - FieldOfView * (4f - Mathf.Pow(ActiveProcessor.GetMinimumFOV(), (1f / 3f))), 3);
                GUILayout.EndHorizontal();

                //Log spam
                //Debug.Log("CactEye 2: MinimumFOV = " + ActiveProcessor.GetMinimumFOV().ToString());
            }

            else
            {
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Processor not installed; optics module cannot function without an image processor.");
                GUILayout.EndHorizontal();
            }

            //Gyro GUI. Active only if the craft has an active gyro
            if (GyroEnabled)
            {
                //Gyro Slider Label
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Gyro Sensitivity:  " + GyroSensitivity.ToString("P") + " + minimum gyroscopic torgue.", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                //Gyro Slider Controls.
                GUILayout.BeginHorizontal();
                GyroSensitivity = GUILayout.HorizontalSlider(GyroSensitivity, 0f, 1f, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                SetTorgue();
            }

            //Make the window draggable by the top bar only.
            GUI.DragWindow(new Rect(0, 0, WindowPosition.width, 16));
        }
Example #12
0
        /* ************************************************************************************************
        * Function Name: DrawProcessorControls
        * Input: None
        * Output: None
        * Purpose: This function will draw the four main processor control objects: the screenshot
        * button, the science button, and the next/previous processor buttons.
        * The screenshot button will only display and be available if the telescope has a valid
        * processor installed on the scope.
        * The science button will only appear if a target is selected, if there is a valid processor
        * installed, and if the game is not a sandbox game. It will generate a science report based
        * on the selected target.
        * The next/previous buttons will only appear if the scope has more than one processor installed,
        * and will allow the player to cycle through the different processors.
        * ************************************************************************************************/
        private void DrawProcessorControls()
        {
            //if (!ActiveProcessor.IsActive())
            //{
            //    //Craft is out of power.
            //    Notification = "Image processor is out of power; shutting down processor.";
            //    timer = 0f;
            //    Processors.Remove(ActiveProcessor);
            //}

            //Draw save icon
            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && ActiveProcessor.GetProcessorType().Contains("Wide Field"))
            {
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), SaveScreenshotTexture))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    Notification = " Screenshot saved to " + WriteTextureToDrive(CameraModule.TakeScreenshot(ActiveProcessor));
                    timer        = 0f;
                }
            }

            //Draw gather science icon
            //Atom6 icon from Freepik
            //<div>Icons made by Freepik from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a>         is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0">CC BY 3.0</a></div>
            if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Atom6Icon))
                {
                    //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                    //ActiveProcessor.GenerateScienceReport(TakeScreenshot(ActiveProcessor.GetType()));
                    try
                    {
                        Notification = ActiveProcessor.DoScience(GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, 500f), scienceMultiplier, CameraModule.FieldOfView, CameraModule.TakeScreenshot(ActiveProcessor));
                    }
                    catch (Exception e)
                    {
                        Notification = "An error occured. Please post that you're having this error on the official CactEye 2 thread on the Kerbal Forums.";
                        Debug.Log("CactEye 2: Exception 4: An error occured producing a science report!");
                        Debug.Log(e.ToString());
                    }

                    timer = 0f;
                }
            }

            //Got an off-by-one error in the list somewhere
            //Previous/Next buttons
            if (Processors.Count <CactEyeProcessor>() > 1)
            {
                //Previous button
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Back9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor        = GetPrevious(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }

                //Next Button
                if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Forward9Icon))
                {
                    ActiveProcessor.Active = false;
                    ActiveProcessor        = GetNext(Processors, ActiveProcessor);
                    ActiveProcessor.Active = true;
                }
            }
        }
Example #13
0
 public Texture2D UpdateTexture(CactEyeProcessor CPU)
 {
     if (CPU)
     {
         return UpdateTexture(CPU, ScopeRenderTexture, ScopeTexture2D);
     }
     else
     {
         return new Texture2D(CameraWidth, CameraHeight);
     }
 }
Example #14
0
 public Texture2D TakeScreenshot(CactEyeProcessor CPU)
 {
     //Just for right now
     return UpdateTexture(CPU, FullResolutionTexture, FullTexture2D);
 }
Example #15
0
        /*
         * Function name: UpdateTexture
         * Input: None
         * Output: A fully rendered texture of what's through the telescope.
         * Purpose: This function will produce a single frame texture of what image is being looked
         * at through the telescope.
         * Note: Need to modify behavior depending on what processor is currently active.
         */
        public Texture2D UpdateTexture(CactEyeProcessor CPU, RenderTexture RT, Texture2D Output)
        {
            RenderTexture CurrentRT = RenderTexture.active;
            RenderTexture.active = RT;

            //Update position of the cameras
            foreach (Camera Cam in CameraObject)
            {
                if (Cam != null)
                {
                    //The if statement fixes a bug with the camera position and timewarp.
                    if (Cam.name.Contains("0"))
                    {
                        //Cam.transform = CameraTransform;
                        Cam.transform.position = CameraTransform.position;
                    }
                    Cam.transform.up = CameraTransform.up;
                    Cam.transform.forward = CameraTransform.forward;
                    if (!RotationLock)
                    {
                        Cam.transform.rotation = CameraTransform.rotation;
                    }
                    Cam.fieldOfView = FieldOfView;
                    Cam.targetTexture = RT;
                }
                else
                {
                    Debug.Log("CactEye 2: " + Cam.name.ToString() + " was not found!");
                }
            }

            CameraObject[0].Render();
            CameraObject[1].Render();
            foreach (Renderer r in skyboxRenderers)
            {
                r.enabled = false;
            }
            foreach (ScaledSpaceFader s in scaledSpaceFaders)
            {
                s.r.enabled = true;
            }
            CameraObject[1].clearFlags = CameraClearFlags.Depth;
            CameraObject[1].farClipPlane = 3e30f;
            CameraObject[1].Render();
            foreach (Renderer r in skyboxRenderers)
            {
                r.enabled = true;
            }
            CameraObject[2].Render();
            CameraObject[3].Render();

            Output.ReadPixels(new Rect(0, 0, Output.width, Output.height), 0, 0);
            Output = CPU.ApplyFilter("Standard", Output);
            Output.Apply();
            RenderTexture.active = CurrentRT;
            return Output;
        }
Example #16
0
        private CactEyeProcessor GetPrevious(IEnumerable<CactEyeProcessor> list, CactEyeProcessor current)
        {
            try
            {
                //return list.SkipWhile(x => !x.Equals(current)).Skip(1).First();
                //lastAgentIDAarhus = agents[ index == -1 ? 0 : index % ( agents.Count - 1 ) ];
                if (CurrentProcessorIndex == 0)
                {
                    CurrentProcessorIndex = Processors.Count - 1;
                }
                else
                {
                    CurrentProcessorIndex--;
                }

                //return Processors[CurrentProcessorIndex == -1 ? 0 : CurrentProcessorIndex % (Processors.Count - 1)];
                Debug.Log("CactEye 2: CurrentProcessorIndex: " + CurrentProcessorIndex.ToString());
                return Processors[CurrentProcessorIndex];
            }
            catch (Exception e)
            {
                Debug.Log("CactEye 2: Exception #: Was not able to find the next processor, even though there is one.");
                Debug.Log(e.ToString());

                return Processors.FirstOrDefault();
            }
        }
Example #17
0
 public Texture2D TakeScreenshot(CactEyeProcessor CPU)
 {
     //Just for right now
     return(UpdateTexture(CPU, FullResolutionTexture, FullTexture2D));
 }
Example #18
0
        private void MainGUI(int WindowID)
        {
            timer += Planetarium.GetUniversalTime() - storedTime;
            storedTime = Planetarium.GetUniversalTime();

            //Top right hand corner button that exits the window.
            if (GUI.Button(new Rect(WindowPosition.width - 18, 2, 16, 16), ""))
            {
                Toggle();
            }

            //What you see looking through the telescope.
            ScopeRect = GUILayoutUtility.GetRect(Screen.width * 0.4f, Screen.width*0.4f);
            Texture2D ScopeScreen = CameraModule.UpdateTexture(ActiveProcessor);
            GUI.DrawTexture(ScopeRect, ScopeScreen);

            //Draw the preview texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin, ScopeRect.yMax - 32f, 128f, 32f), PreviewTexture);
            //Draw the crosshair texture
            GUI.DrawTexture(new Rect(ScopeRect.xMin + (0.5f * ScopeRect.width) - 64, ScopeRect.yMin + (0.5f * ScopeRect.height) - 64, 128, 128), CrosshairTexture);
            //Draw the notification label
            if (timer > 5f)
            {
                Notification = "";
            }
            GUI.Label(new Rect(ScopeRect.xMin + 16, ScopeRect.yMin + 16, 600, 32), new GUIContent(Notification));

            //Draw Processor controls in bottom center of display, with observation and screenshot buttons in center.
            DrawProcessorControls();
            DrawTargetPointer();

            if (ActiveProcessor)
            {
                //Close window down if we run out of power
                if (!ActiveProcessor.IsActive())
                {
                //    Toggle();
                //    ScreenMessages.PostScreenMessage("Image processor is out of power. Please restore power to telescope.", 6, ScreenMessageStyle.UPPER_CENTER);
                    ActiveProcessor = null;
                    Notification = "Image Processor is out of power. Please restore power to telescope";
                    timer = 0f;
                }

                //Zoom Feedback Label.
                string LabelZoom = "Zoom/Magnification: x";
                if (CameraModule.FieldOfView > 0.0064)
                {
                    LabelZoom += string.Format("{0:####0.0}", 64 / CameraModule.FieldOfView);
                }
                else
                {
                    LabelZoom += string.Format("{0:0.00E+0}", (64 / CameraModule.FieldOfView));
                }
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label(LabelZoom);

                //Active Processor and status Label
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                GUILayout.Label("Active Processor: " + ActiveProcessor.GetProcessorType());
                GUILayout.EndHorizontal();

                //Zoom Slider Controls.
                GUILayout.BeginHorizontal();
                FieldOfView = GUILayout.HorizontalSlider(FieldOfView, 0f, 1f);
                CameraModule.FieldOfView = 0.5f * Mathf.Pow(4f - FieldOfView * (4f - Mathf.Pow(ActiveProcessor.GetMinimumFOV(), (1f / 3f))), 3);
                GUILayout.EndHorizontal();

                //Log spam
                //Debug.Log("CactEye 2: MinimumFOV = " + ActiveProcessor.GetMinimumFOV().ToString());
            }

            else
            {
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Processor not installed; optics module cannot function without an image processor.");
                GUILayout.EndHorizontal();
            }

            //Gyro GUI. Active only if the craft has an active gyro
            if (GyroEnabled)
            {
                //Gyro Slider Label
                GUILayout.BeginHorizontal();
                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                GUILayout.Label("Gyro Sensitivity:  " + GyroSensitivity.ToString("P") + " + minimum gyroscopic torgue.", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                //Gyro Slider Controls.
                GUILayout.BeginHorizontal();
                GyroSensitivity = GUILayout.HorizontalSlider(GyroSensitivity, 0f, 1f, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                SetTorgue();
            }

            //Make the window draggable by the top bar only.
            GUI.DragWindow(new Rect(0, 0, WindowPosition.width, 16));
        }
Example #19
0
        /* ************************************************************************************************
         * Function Name: GetProcessors
         * Input: None
         * Output: None
         * Purpose: This function will generate a list of image processors installed on the telescope
         * craft.
         * ************************************************************************************************/
        private void GetProcessors()
        {
            Processors.Clear();

            foreach (Part p in FlightGlobals.ActiveVessel.Parts)
            {
                CactEyeProcessor cpu = p.GetComponent<CactEyeProcessor>();
                if (cpu != null)
                {
                    if (!Processors.Contains(cpu))
                    {
                        Processors.Add(cpu);
                    }
                }
            }

            Debug.Log("CactEye 2: Found " + Processors.Count().ToString() + " Processors.");

            if (Processors.Count<CactEyeProcessor>() > 0)
            {
                ActiveProcessor = Processors.First<CactEyeProcessor>();
                CurrentProcessorIndex = 0;

                //if (ActiveProcessor.GetProcessorType().Contains("Wide Field"))
                //{
                //    ActiveProcessor.Active = true;
                //}
            }
        }