public static void DrawnPath(Rect r, float scaleX, float scaleY, DefaultAscentPath path, Color color) { float alt = 0; float downrange = 0; Vector2 p1 = new Vector2(r.xMin, r.yMax); Vector2 p2 = new Vector2(); while (alt < (path.autoPath ? path.autoTurnEndAltitude : path.turnEndAltitude) && downrange < r.width * scaleX) { float desiredAngle = (float)(alt < path.VerticalAscentEnd() ? 90 : path.FlightPathAngle(alt, 0)); alt += scaleY * Mathf.Sin(desiredAngle * Mathf.Deg2Rad); downrange += scaleX * Mathf.Cos(desiredAngle * Mathf.Deg2Rad); p2.x = r.xMin + downrange / scaleX; p2.y = r.yMax - alt / scaleY; if ((p1 - p2).sqrMagnitude >= 1.0) { Drawing.DrawLine(p1, p2, color, 2, true); p1.x = p2.x; p1.y = p2.y; } } }
//redraw the picture of the planned flight path private void UpdatePathTexture() { double scale = (path.autoPath ? path.autoTurnEndAltitude : path.turnEndAltitude) / pathTexture.height; //meters per pixel double maxAtmosphereAltitude = part.vessel.mainBody.RealMaxAtmosphereAltitude(); for (int y = 0; y < pathTexture.height; y++) { Color c = new Color(0.0F, 0.0F, (float)Math.Max(0.0, 1.0 - y * scale / maxAtmosphereAltitude)); for (int x = 0; x < pathTexture.width; x++) { pathTexture.SetPixel(x, y, c); } } double alt = 0; double downrange = 0; while (alt < (path.autoPath ? path.autoTurnEndAltitude : path.turnEndAltitude) && downrange < pathTexture.width * scale) { double desiredAngle = (alt < path.VerticalAscentEnd() ? 90 : path.FlightPathAngle(alt)); alt += scale * Math.Sin(desiredAngle * Math.PI / 180); downrange += scale * Math.Cos(desiredAngle * Math.PI / 180); for (int x = (int)(downrange / scale); x <= (downrange / scale) + 2 && x < pathTexture.width; x++) { for (int y = (int)(alt / scale) - 1; y <= (int)(alt / scale) + 1 && y < pathTexture.height; y++) { pathTexture.SetPixel(x, y, Color.red); } } } pathTexture.Apply(); pathTextureDrawnBefore = true; }
public static void DrawnPath(Rect r, float scaleX, float scaleY, DefaultAscentPath path, Color color) { float alt = 0; float downrange = 0; Vector2 p1 = new Vector2(r.xMin, r.yMax); Vector2 p2 = new Vector2(); while (alt < (path.autoPath ? path.autoTurnEndAltitude : path.turnEndAltitude) && downrange < r.width * scaleX) { float desiredAngle = (float)(alt < path.VerticalAscentEnd() ? 90 : path.FlightPathAngle(alt, 0)); alt += scaleY * Mathf.Sin(desiredAngle * Mathf.Deg2Rad); downrange += scaleX * Mathf.Cos(desiredAngle * Mathf.Deg2Rad); p2.x = r.xMin + downrange / scaleX; p2.y = r.yMax - alt / scaleY; if ((p1 - p2).sqrMagnitude >= 1.0) { Drawing.DrawLine(p1, p2, color, 2, true); p1.x = p2.x; p1.y = p2.y; } } }