private void DrawOrbitIcon(Vessel thatVessel, MapIcons.OtherIcon iconType, Color iconColor, double givenPoint = 0) { double timePoint = start; switch (iconType) { case MapIcons.OtherIcon.AP: timePoint += thatVessel.orbit.timeToAp; break; case MapIcons.OtherIcon.PE: timePoint += thatVessel.orbit.timeToPe; break; case MapIcons.OtherIcon.AN: case MapIcons.OtherIcon.DN: case MapIcons.OtherIcon.NODE: timePoint = givenPoint; break; } if (JUtil.OrbitMakesSense(thatVessel)) { bool collision; Vector2d coord; if (GetPositionAtT(thatVessel, thatVessel.orbit, start, timePoint, out coord, out collision) && !collision) { DrawIcon(coord.x, coord.y, thatVessel.vesselType, iconColor, iconType); } } }
private void DrawOrbitIcon(Vessel thatVessel, SCANicon.OrbitIcon iconType, Color iconColor, double givenPoint = 0) { double timePoint = start; switch (iconType) { case SCANicon.OrbitIcon.Ap: timePoint += thatVessel.orbit.timeToAp; break; case SCANicon.OrbitIcon.Pe: timePoint += thatVessel.orbit.timeToPe; break; case SCANicon.OrbitIcon.AN: case SCANicon.OrbitIcon.DN: case SCANicon.OrbitIcon.ManeuverNode: timePoint = givenPoint; break; default: iconType = SCANicon.orbitIconForVesselType(thatVessel.vesselType); break; } if (JUtil.OrbitMakesSense(thatVessel)) { bool collision; Vector2d coord; if (GetPositionAtT(thatVessel, thatVessel.orbit, start, timePoint, out coord, out collision) && !collision) { DrawIcon(coord.x, coord.y, iconType, iconColor); } } }
// Analysis disable once UnusedParameter public bool MapRenderer(RenderTexture screen, float cameraAspect) { // Just in case. if (!HighLogic.LoadedSceneIsFlight) { return(false); } if (!TestForActiveSCANsat()) { return(false); } if (!startupComplete) { JUtil.AnnoyUser(this); } if (screenWidth == 0 || screenHeight == 0) { int?loadedMode = persistence.GetVar(persistentVarName + "mode"); mapMode = loadedMode ?? 0; int?loadedZoom = persistence.GetVar(persistentVarName + "zoom"); zoomLevel = loadedZoom ?? 0; int?loadedColors = persistence.GetVar(persistentVarName + "color"); 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); }