Beispiel #1
0
        private void Start()
        {
            // Arrrgh.
            if (!string.IsNullOrEmpty(iconColorSelf))
            {
                iconColorSelfValue = ConfigNode.ParseColor32(iconColorSelf);
            }
            if (!string.IsNullOrEmpty(iconColorTarget))
            {
                iconColorTargetValue = ConfigNode.ParseColor32(iconColorTarget);
            }
            if (!string.IsNullOrEmpty(iconColorUnvisitedAnomaly))
            {
                iconColorUnvisitedAnomalyValue = ConfigNode.ParseColor32(iconColorUnvisitedAnomaly);
            }
            if (!string.IsNullOrEmpty(iconColorVisitedAnomaly))
            {
                iconColorVisitedAnomalyValue = ConfigNode.ParseColor32(iconColorVisitedAnomaly);
            }
            if (!string.IsNullOrEmpty(iconColorShadow))
            {
                iconColorShadowValue = ConfigNode.ParseColor32(iconColorShadow);
            }
            if (!string.IsNullOrEmpty(iconColorAP))
            {
                iconColorAPValue = ConfigNode.ParseColor32(iconColorAP);
            }
            if (!string.IsNullOrEmpty(iconColorPE))
            {
                iconColorPEValue = ConfigNode.ParseColor32(iconColorPE);
            }
            if (!string.IsNullOrEmpty(iconColorANDN))
            {
                iconColorANDNValue = ConfigNode.ParseColor32(iconColorANDN);
            }
            if (!string.IsNullOrEmpty(iconColorNode))
            {
                iconColorNodeValue = ConfigNode.ParseColor32(iconColorNode);
            }
            if (!string.IsNullOrEmpty(trailColor))
            {
                trailColorValue = ConfigNode.ParseColor32(trailColor);
            }


            // Referencing the parent project should work, shouldn't it.
            persistentVarName = "scansat" + internalProp.propID;

            try {
                sat = part.FindModulesImplementing <SCANsat>().First();
            }
            catch {
                Debug.LogWarning("[SCANsatRPM] SCANsat module not attached to this IVA, check for Module Manager problems and make sure the RPMMapTraq.cfg file is in the SCANsat/MMconfigs folder");
                sat = null;
            }

            if (sat != null)
            {
                if (sat.RPMList.Count > 0)
                {
                    foreach (RPMPersistence RPMProp in sat.RPMList)
                    {
                        if (RPMProp.RPMID == persistentVarName)
                        {
                            persist = RPMProp;
                            break;
                        }
                    }
                }
                if (persist == null)
                {
                    persist = new RPMPersistence(persistentVarName);
                    sat.RPMList.Add(persist);
                    showLines = persist.RPMLines;
                }
            }

            trailMaterial = JUtil.DrawLineMaterial();

            LeaveTrail();

            if (!string.IsNullOrEmpty(scaleBar) && !string.IsNullOrEmpty(scaleLabels) && !string.IsNullOrEmpty(scaleLevels))
            {
                scaleBarTexture   = GameDatabase.Instance.GetTexture(scaleBar, false);
                scaleLabelTexture = GameDatabase.Instance.GetTexture(scaleLabels, false);
                var scales = new List <float>();
                foreach (string scl in scaleLevels.Split(','))
                {
                    float scale;
                    if (float.TryParse(scl.Trim(), out scale))
                    {
                        scales.Add(scale / 1000);
                    }
                }
                scaleLevelValues = scales.ToArray();
                Array.Sort(scaleLevelValues);
                scaleLabelSpan = 1f / scaleLevelValues.Length;
            }

            // Now the fun bit: Locate all cfg files depicting map features anywhere.

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("JSISCANSATVECTORMARK"))
            {
                mapMarkup.Add(new MapMarkupLine(node));
            }
        }
Beispiel #2
0
 //Gives the true anomaly (in a's orbit) at which a crosses its descending node
 //with b's orbit.
 //The returned value is always between 0 and 360.
 public static double DescendingNodeTrueAnomaly(this Orbit a, Orbit b)
 {
     return(JUtil.ClampDegrees360(a.AscendingNodeTrueAnomaly(b) + 180));
 }
Beispiel #3
0
        // Analysis disable once UnusedParameter
        public bool MapRenderer(RenderTexture screen, float cameraAspect)
        {
            // Just in case.
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return(false);
            }

            if (!TestForActiveSCANsat())
            {
                return(false);
            }

            if (screenWidth == 0 || screenHeight == 0)
            {
                int?loadedMode = persist.RPMMode;
                mapMode = loadedMode ?? 0;
                int?loadedZoom = persist.RPMZoom;
                zoomLevel = loadedZoom ?? 0;
                int?loadedColors = persist.RPMColor;
                SCANcontroller.controller.colours = loadedColors ?? 0;
                screenWidth  = screen.width;
                screenHeight = screen.height;
                iconMaterial = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));

                screenSpace = new Rect(0, 0, screenWidth, screenHeight);

                RedrawMap();

                return(false);
            }

            // In case SCANsat is present but not working, we can't run any of our code. :(
            if (map == null)
            {
                return(false);
            }

            start = Planetarium.GetUniversalTime();

            Graphics.Blit(map.map, screen);
            GL.PushMatrix();
            GL.LoadPixelMatrix(0, screenWidth, screenHeight, 0);

            // Markup lines are the lowest layer.
            if (showLines)
            {
                foreach (MapMarkupLine vectorLine in mapMarkup)
                {
                    if (vectorLine.body == orbitingBody && vectorLine.points.Count > 0)
                    {
                        DrawTrail(vectorLine.points, vectorLine.color, Vector2d.zero);
                    }
                }
            }

            // Trails go above markup lines
            if (showLines && trailLimit > 0 && trail.Count > 0)
            {
                DrawTrail(trail, trailColorValue, new Vector2d(vessel.longitude, vessel.latitude), true);
            }

            // Anomalies go above trails
            foreach (SCANdata.SCANanomaly anomaly in localAnomalies)
            {
                if (anomaly.known)
                {
                    DrawIcon(anomaly.longitude, anomaly.latitude,
                             anomaly.detail ? (VesselType)int.MaxValue : VesselType.Unknown,
                             anomaly.detail ? iconColorVisitedAnomalyValue : iconColorUnvisitedAnomalyValue);
                }
            }
            // Target orbit and targets go above anomalies
            if (targetVessel != null && targetVessel.mainBody == orbitingBody)
            {
                if (showLines && JUtil.OrbitMakesSense(targetVessel))
                {
                    DrawOrbit(targetVessel, targetVessel.orbit, start, iconColorTargetValue);
                    // Connect our orbit and the target orbit with a line at the point of closest approach...
                    if (JUtil.OrbitMakesSense(vessel))
                    {
                        double closestApproachMoment;
                        JUtil.GetClosestApproach(vessel.orbit, targetVessel.orbit, out closestApproachMoment);
                        Vector2d targetCoord, vesselCoord;
                        bool     targetCollision, vesselCollision;
                        // Analysis disable once CompareOfFloatsByEqualityOperator
                        if (closestApproachMoment != start &&
                            GetPositionAtT(targetVessel, targetVessel.orbit, start, closestApproachMoment, out targetCoord, out targetCollision) && !targetCollision &&
                            GetPositionAtT(vessel, targetVessel.orbit, start, closestApproachMoment, out vesselCoord, out vesselCollision) && !vesselCollision)
                        {
                            var endpoints = new List <Vector2d>();
                            endpoints.Add(targetCoord);
                            endpoints.Add(vesselCoord);
                            DrawTrail(endpoints, iconColorTargetValue, Vector2d.zero);
                        }
                    }
                }
                DrawIcon(targetVessel.longitude, targetVessel.latitude, targetVessel.vesselType, iconColorTargetValue);
                if (showLines)
                {
                    DrawOrbitIcon(targetVessel, MapIcons.OtherIcon.AP, iconColorTargetValue);
                    DrawOrbitIcon(targetVessel, MapIcons.OtherIcon.PE, iconColorTargetValue);
                }
            }
            // Own orbit goes above that.
            if (showLines && JUtil.OrbitMakesSense(vessel))
            {
                DrawOrbit(vessel, vessel.orbit, start, iconColorSelfValue);
                DrawOrbitIcon(vessel, MapIcons.OtherIcon.AP, iconColorAPValue);
                DrawOrbitIcon(vessel, MapIcons.OtherIcon.PE, iconColorPEValue);
                if (targetVessel != null && JUtil.OrbitMakesSense(targetVessel))
                {
                    if (vessel.orbit.AscendingNodeExists(targetVessel.orbit))
                    {
                        DrawOrbitIcon(vessel, MapIcons.OtherIcon.AN, iconColorANDNValue, vessel.orbit.TimeOfAscendingNode(targetVessel.orbit, start));
                    }
                    if (vessel.orbit.DescendingNodeExists(targetVessel.orbit))
                    {
                        DrawOrbitIcon(vessel, MapIcons.OtherIcon.DN, iconColorANDNValue, vessel.orbit.TimeOfDescendingNode(targetVessel.orbit, start));
                    }
                }
                // And the maneuver node and post-maneuver orbit:
                ManeuverNode node = vessel.patchedConicSolver.maneuverNodes.Count > 0 ? vessel.patchedConicSolver.maneuverNodes[0] : null;
                if (node != null)
                {
                    DrawOrbit(vessel, node.nextPatch, node.UT, iconColorNodeValue);
                    DrawOrbitIcon(vessel, MapIcons.OtherIcon.NODE, iconColorNodeValue, node.UT);
                }
            }
            // Own icon goes above that
            DrawIcon(vessel.longitude, vessel.latitude, vessel.vesselType, iconColorSelfValue);
            // And scale goes above everything.
            DrawScale();

            GL.PopMatrix();

            return(true);
        }
Beispiel #4
0
 //Returns whether a has a descending node with b. This can be false
 //if a is hyperbolic and the would-be descending node is within the opening
 //angle of the hyperbola.
 public static bool DescendingNodeExists(this Orbit a, Orbit b)
 {
     return(Math.Abs(JUtil.ClampDegrees180(a.DescendingNodeTrueAnomaly(b))) <= a.MaximumTrueAnomaly());
 }