コード例 #1
0
        void drawLandingGuides()
        {
            if (HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                return;
            }
            if (soLandingGuide == null || FlightGlobals.ActiveVessel == null || soTDL == null || soTDR == null)
            {
                return;
            }

            // the vessel is not active?!? we don't deal with such alien spacecraft.
            if (FlightGlobals.ActiveVessel.state != Vessel.State.ACTIVE)
            {
                return;
            }

            // Only deal with flying things.
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.FLYING)
            {
                return;
            }


            vTDL = Camera.main.WorldToScreenPoint(soTDL.position);
            vTDR = Camera.main.WorldToScreenPoint(soTDR.position);

            vlgPos   = soLandingGuide.position;
            vcrPos   = FlightGlobals.ActiveVessel.GetWorldPos3D();
            distance = Vector3.Distance(vlgPos, vcrPos);


            if (distance > 15000)
            {
                return;
            }
            if (distance < 3)
            {
                return;
            }

            float flgWscale = 1f;
            float flgHscale = 1f;

            if (distance > 10000)
            {
                flgWscale = 250 / distance;
                flgHscale = 100 / distance;
            }
            else if (distance > 5000)
            {
                flgWscale = 500 / distance;
                flgHscale = 250 / distance;
            }
            else if (distance > 2500)
            {
                flgWscale = 750 / distance;
                flgHscale = 500 / distance;
            }
            else if (distance > 1000)
            {
                flgWscale = 1000 / distance;
                flgHscale = 750 / distance;
            }
            else
            {
                flgWscale = 1f;
                flgHscale = 1f;
            }



            Vector3  landingGuidePoint = soLandingGuide.position;
            Vector3d vesselPosition    = FlightGlobals.ActiveVessel.GetWorldPos3D();


            screenListStart = Camera.main.WorldToScreenPoint(landingGuidePoint);
            screenLineEnd   = Camera.main.WorldToScreenPoint(vesselPosition);


            fromShipToEnd = landingGuidePoint - vesselPosition;


            if (screenLineEnd != Vector3.zero && screenListStart != Vector3.zero)
            {
                // Draw the landing line depending on the angle
                if (distance < 8000)
                {
                    horizontalVector = Vector3.ProjectOnPlane(fromShipToEnd, soLandingGuide.transform.up);
                    glideAngle       = Mathf.Rad2Deg * Math.Acos(horizontalVector.magnitude / fromShipToEnd.magnitude);

                    if (glideAngle > 6f)
                    {
                        DebugDrawer.DebugLine(landingGuidePoint, vesselPosition, clTooHigh);
                    }
                    else
                    if (glideAngle > 4.5f)
                    {
                        DebugDrawer.DebugLine(landingGuidePoint, vesselPosition, clWarn);
                    }
                    else
                    if (glideAngle < 1.5f)
                    {
                        DebugDrawer.DebugLine(landingGuidePoint, vesselPosition, clWarn);
                    }
                    else
                    {
                        DebugDrawer.DebugLine(landingGuidePoint, vesselPosition, clRight);
                    }
                }


                // Check if we are past the landing guide
                if (Vector3d.Dot(soLandingGuide.transform.forward, fromShipToEnd) < 0)
                {
                    return;
                }


                Marker1 = new Rect((float)(screenListStart.x) - (25 * flgWscale), (float)(Screen.height - screenListStart.y) - 10, 50 * flgWscale, 4);
                Marker2 = new Rect((float)(screenListStart.x) - (50 * flgWscale), (float)(Screen.height - screenListStart.y) - 25, 100 * flgWscale, 4);
                Marker3 = new Rect((float)(screenListStart.x) - (75 * flgWscale), (float)(Screen.height - screenListStart.y) - 40, 150 * flgWscale, 4);

                Marker4 = new Rect((float)(Screen.width / 2) - (25 * flgWscale), (float)(Screen.height / 2) - 10, 50 * flgWscale, 4);
                Marker5 = new Rect((float)(Screen.width / 2) - (50 * flgWscale), (float)(Screen.height / 2) - 25, 100 * flgWscale, 4);
                Marker6 = new Rect((float)(Screen.width / 2) - (75 * flgWscale), (float)(Screen.height / 2) - 40, 150 * flgWscale, 4);

                if (distance < 15000)
                {
                    // Only draw this if we show in the right direction
                    if (Vector3.Dot((vesselPosition - FlightCamera.fetch.mainCamera.transform.position), landingGuidePoint) > 0)
                    {
                        GUI.DrawTexture(Marker1, tLGb, ScaleMode.StretchToFill, true);
                        GUI.DrawTexture(Marker2, tLGm, ScaleMode.StretchToFill, true);
                        GUI.DrawTexture(Marker3, tLGt, ScaleMode.StretchToFill, true);

                        if (vTDL != Vector3.zero && vTDR != Vector3.zero)
                        {
                            vTDR = Camera.main.WorldToScreenPoint(soTDR.position);
                            vTDL = Camera.main.WorldToScreenPoint(soTDL.position);

                            Marker7 = new Rect((float)(vTDL.x) - (50 * flgWscale), (float)(Screen.height - vTDL.y) - (140 * flgHscale), 100 * flgWscale, 150 * flgHscale);
                            Marker8 = new Rect((float)(vTDR.x) - (50 * flgWscale), (float)(Screen.height - vTDR.y) - (140 * flgHscale), 100 * flgWscale, 150 * flgHscale);

                            GUI.DrawTexture(Marker7, tTGL, ScaleMode.StretchToFill, true);
                            GUI.DrawTexture(Marker8, tTGR, ScaleMode.StretchToFill, true);
                        }
                    }
                    // make them less annoying
                    if (KerbalKonstructs.selectedInstance == null)
                    {
                        GUI.DrawTexture(Marker4, tLGb, ScaleMode.StretchToFill, true);
                        GUI.DrawTexture(Marker5, tLGm, ScaleMode.StretchToFill, true);
                        GUI.DrawTexture(Marker6, tLGt, ScaleMode.StretchToFill, true);
                    }
                }
            }
        }
コード例 #2
0
        public void Update()
        {
            // dont do anything when its not in flight
            if (HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                SetAllOff();
                return;
            }

            // hmm no vessel found.. thats bad because you are not flying...
            if (FlightGlobals.ActiveVessel == null)
            {
                SetAllOff();
                return;
            }

            // the vessel is not active?!? we don't deal with such alien spacecraft.
            if (FlightGlobals.ActiveVessel.state != Vessel.State.ACTIVE)
            {
                SetAllOff();
                return;
            }

            // Only deal with flying things.
            if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.FLYING)
            {
                SetAllOff();
                return;
            }

            // from here it should be save to do acually some things.

            touchDownPoint    = staticInstance.gameObject.transform.position + (directionsMult * staticInstance.gameObject.transform.forward.normalized * touchDownOffset);
            vesselPosition    = FlightGlobals.ActiveVessel.GetWorldPos3D();
            fromVesseltoPoint = (touchDownPoint - FlightGlobals.ActiveVessel.GetWorldPos3D());
            horizontalVector  = Vector3.ProjectOnPlane(fromVesseltoPoint, staticInstance.gameObject.transform.up);

            if (Vector3d.Dot(horizontalVector, directionsMult * staticInstance.gameObject.transform.forward.normalized) < 0)
            {
                // we are behind the lights. no need to update them anymore.
                SetAllOff();
                return;
            }

            currentDistance = horizontalVector.magnitude;

            // Do nothing if too far away
            if (currentDistance > maxDist)
            {
                SetAllOff();
                return;
            }

            if (showDebug)
            {
                DebugDrawer.DebugVector(touchDownPoint, -horizontalVector, new Color(0.2f, 0.2f, 0.7f));
                DebugDrawer.DebugLine(touchDownPoint, vesselPosition, new Color(0.2f, 0.7f, 0.2f));
            }

            currentState = GetCurrentGlideState();

            if (lastState != currentState)
            {
                //Log.Normal("PAPI: Switching State: " + lastState.ToString() + " to " + currentState.ToString());
                lastState = currentState;

                switch (currentState)
                {
                case GlideState.TooHigh:
                    if (animTooHigh != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetWhite(animHigh, AnimNameHigh);
                        SetWhite(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.High:
                    if (animHigh != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetWhite(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.Right:
                    if (animRight != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetWhite(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }

                    break;

                case GlideState.Low:
                    if (animLow != null)
                    {
                        SetWhite(animLow, AminNameTooLow);
                        SetRed(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }
                    break;

                case GlideState.TooLow:
                    if (animLow != null)
                    {
                        SetRed(animLow, AminNameTooLow);
                        SetRed(animRight, AnimNameRight);
                        SetRed(animHigh, AnimNameHigh);
                        SetRed(animTooHigh, AnimNameTooHigh);
                    }
                    break;
                }
            }
        }