Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Please always post your [KSP.log file](https://gist.github.com/JonnyOThan/04c207
### New Features

- Add support for scrolling through orbit patches on the MFD (thanks @andymac-2)
- Allow targeting flags and landed vessels (thanks @andymac-2)

### Bug Fixes

Expand Down Expand Up @@ -300,4 +301,4 @@ Many thanks to Manul and Zorkinian on the KSP forums for pinpointing the root ca

### Changes

- Updated for KSP 1.8.X
- Updated for KSP 1.8.X
12 changes: 6 additions & 6 deletions RasterPropMonitor/Core/RPMCEvaluators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,21 +1714,21 @@ internal NumericVariableEvaluator GetNumericEvaluator(string input, out Variable
case "TIMETOANWITHTARGETSECS":
return (RPMVesselComputer comp) =>
{
if (comp.target == null || comp.targetOrbit == null)
if (comp.target == null)
return double.NaN;
return vessel.GetOrbit().TimeOfAscendingNode(comp.targetOrbit, Planetarium.GetUniversalTime()) - Planetarium.GetUniversalTime();
return vessel.GetOrbit().TimeOfAscendingNode(comp.target.GetOrbit(), Planetarium.GetUniversalTime()) - Planetarium.GetUniversalTime();
};
case "TIMETODNWITHTARGETSECS":
return (RPMVesselComputer comp) =>
{
if (comp.target == null || comp.targetOrbit == null)
if (comp.target == null)
return double.NaN;
return vessel.GetOrbit().TimeOfDescendingNode(comp.targetOrbit, Planetarium.GetUniversalTime()) - Planetarium.GetUniversalTime();
return vessel.GetOrbit().TimeOfDescendingNode(comp.target.GetOrbit(), Planetarium.GetUniversalTime()) - Planetarium.GetUniversalTime();
};
case "TARGETCLOSESTAPPROACHTIME":
return (RPMVesselComputer comp) =>
{
if (comp.target == null || comp.targetOrbit == null || orbitSensibility == false)
if (comp.target == null || orbitSensibility == false)
{
return double.NaN;
}
Expand All @@ -1742,7 +1742,7 @@ internal NumericVariableEvaluator GetNumericEvaluator(string input, out Variable
case "TARGETCLOSESTAPPROACHDISTANCE":
return (RPMVesselComputer comp) =>
{
if (comp.target == null || comp.targetOrbit == null || orbitSensibility == false)
if (comp.target == null || orbitSensibility == false)
{
return double.NaN;
}
Expand Down
42 changes: 10 additions & 32 deletions RasterPropMonitor/Core/UtilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,41 +1112,19 @@ public static string CurrentBiome(this Vessel thatVessel)
return "Space over " + thatVessel.mainBody.bodyName;
}


// Pseudo-orbit for closest approach to a landed object
public static Orbit OrbitFromSurfacePos(CelestialBody body, double lat, double lon, double alt, double UT)
public static Vector3d ClosestApproachSrfOrbit(Orbit vesselOrbit, Vessel target, out double UT, out double distance)
{
double t0 = Planetarium.GetUniversalTime();
double angle = body.rotates ? (UT - t0) * 360.0 / body.rotationPeriod : 0;

double LAN = (lon + body.rotationAngle + angle - 90.0) % 360.0;
Orbit orbit = new Orbit(lat, 0, body.Radius + alt, LAN, 90.0, 0, UT, body);
CelestialBody body = target.mainBody;

orbit.pos = orbit.getRelativePositionAtT(0);
if (body.rotates)
orbit.vel = Vector3d.Cross(body.zUpAngularVelocity, -orbit.pos);
else
orbit.vel = orbit.getOrbitalVelocityAtObT(Time.fixedDeltaTime);
orbit.h = Vector3d.Cross(orbit.pos, orbit.vel);

orbit.StartUT = t0;
orbit.EndUT = UT + orbit.period;
if (body.rotates)
orbit.period = body.rotationPeriod;
orbit.patchEndTransition = Orbit.PatchTransitionType.FINAL;
return orbit;
}
// longitude and latitude calculations are offset by a different amount every
// time we load the scene. We can use a zero latitude/longitude to find out what
// that offset is.
Vector3d zeroPos = body.GetRelSurfacePosition(0, 0, 0);
body.GetLatLonAltOrbital(zeroPos, out var zeroLat, out var zeroLon, out var _);

public static Orbit ClosestApproachSrfOrbit(Orbit vesselOrbit, Vessel target, out double UT, out double distance)
{
return ClosestApproachSrfOrbit(vesselOrbit, target.mainBody, target.latitude, target.longitude, target.altitude, out UT, out distance);
}

public static Orbit ClosestApproachSrfOrbit(Orbit vesselOrbit, CelestialBody body, double lat, double lon, double alt, out double UT, out double distance)
{
Vector3d pos = body.GetRelSurfacePosition(lat, lon, alt);
Vector3d pos = body.GetRelSurfacePosition(target.latitude - zeroLat, target.longitude - zeroLon, target.altitude);
distance = GetClosestApproach(vesselOrbit, body, pos, out UT);
return OrbitFromSurfacePos(body, lat, lon, alt, UT);
return pos;
}

public static double GetClosestApproach(Orbit vesselOrbit, ITargetable target, out double timeAtClosestApproach)
Expand All @@ -1171,7 +1149,7 @@ public static double GetClosestApproach(Orbit vesselOrbit, ITargetable target, o
if (targetVessel.LandedOrSplashed)
{
double closestApproach;
Orbit targetOrbit = JUtil.ClosestApproachSrfOrbit(vesselOrbit, targetVessel, out timeAtClosestApproach, out closestApproach);
ClosestApproachSrfOrbit(vesselOrbit, targetVessel, out timeAtClosestApproach, out closestApproach);
return closestApproach;
}
else
Expand Down
41 changes: 23 additions & 18 deletions RasterPropMonitor/Handlers/JSIOrbitDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static void DrawOrbitSegment(
Vector3 midStraight = (startVertex + endVertex) * 0.5f;
// Debug.Log($"startTA: {startTA}, endTA: {endTA}, startVertex: {startVertex}, endVertex: {endVertex}, midVertex: {midVertex}, midStraight: {midStraight}");

if (Math.Abs(startTA - endTA) < 0.01 || (midStraight - midVertex).sqrMagnitude < 9.0)
if (Math.Abs(startTA - endTA) < 0.01 || (midStraight - midVertex).sqrMagnitude < 16.0)
{
GL.Vertex3(startVertex.x, startVertex.y, 0.0f);
GL.Vertex3(midVertex.x, midVertex.y, 0.0f);
Expand Down Expand Up @@ -569,29 +569,31 @@ public bool RenderOrbit(RenderTexture screen, float cameraAspect)
{
var orbit = (targetVessel != null) ? targetVessel.GetOrbit() : targetBody.GetOrbit();

double tClosestApproach, dClosestApproach;
double tClosestApproach;

if (targetVessel != null && targetVessel.LandedOrSplashed)
{
orbit = JUtil.ClosestApproachSrfOrbit(selectedPatch, targetVessel, out tClosestApproach, out dClosestApproach);
Vector3d position = JUtil.ClosestApproachSrfOrbit(selectedPatch, targetVessel, out tClosestApproach, out double _);
transformedPosition = screenTransform.MultiplyPoint3x4(position);
DrawIcon(transformedPosition.x, transformedPosition.y, targetVessel.vesselType, iconColorTargetValue);
}
else
{
dClosestApproach = JUtil.GetClosestApproach(selectedPatch, orbit, out tClosestApproach);
JUtil.GetClosestApproach(selectedPatch, orbit, out tClosestApproach);

DrawNextPe(orbit, selectedPatch.referenceBody, now, iconColorTargetValue, screenTransform);
DrawNextAp(orbit, selectedPatch.referenceBody, now, iconColorTargetValue, screenTransform);
}

if (targetBody != null)
{
transformedPosition = screenTransform.MultiplyPoint3x4(targetBody.getTruePositionAtUT(now) - selectedPatch.referenceBody.getTruePositionAtUT(now));
DrawIcon(transformedPosition.x, transformedPosition.y, VesselType.Unknown, iconColorTargetValue, MapIcons.OtherIcon.PLANET);
}
else
{
transformedPosition = screenTransform.MultiplyPoint3x4(orbit.SwappedRelativePositionAtUT(now));
DrawIcon(transformedPosition.x, transformedPosition.y, targetVessel.vesselType, iconColorTargetValue);
if (targetBody != null)
{
transformedPosition = screenTransform.MultiplyPoint3x4(targetBody.getTruePositionAtUT(now) - selectedPatch.referenceBody.getTruePositionAtUT(now));
DrawIcon(transformedPosition.x, transformedPosition.y, VesselType.Unknown, iconColorTargetValue, MapIcons.OtherIcon.PLANET);
}
else
{
transformedPosition = screenTransform.MultiplyPoint3x4(orbit.SwappedRelativePositionAtUT(now));
DrawIcon(transformedPosition.x, transformedPosition.y, targetVessel.vesselType, iconColorTargetValue);
}
}

if (selectedPatch.AscendingNodeExists(orbit))
Expand Down Expand Up @@ -621,10 +623,13 @@ public bool RenderOrbit(RenderTexture screen, float cameraAspect)
DrawIcon(transformedPosition.x, transformedPosition.y, VesselType.Unknown, iconColorClosestApproachValue, MapIcons.OtherIcon.SHIPATINTERCEPT);
}

// Unconditionally try to draw the closest approach point on
// the target orbit.
transformedPosition = screenTransform.MultiplyPoint3x4(orbit.SwappedRelativePositionAtUT(tClosestApproach));
DrawIcon(transformedPosition.x, transformedPosition.y, VesselType.Unknown, iconColorClosestApproachValue, MapIcons.OtherIcon.TGTATINTERCEPT);
if (!targetVessel.LandedOrSplashed)
{
// Unconditionally try to draw the closest approach point on
// the target orbit.
transformedPosition = screenTransform.MultiplyPoint3x4(orbit.SwappedRelativePositionAtUT(tClosestApproach));
DrawIcon(transformedPosition.x, transformedPosition.y, VesselType.Unknown, iconColorClosestApproachValue, MapIcons.OtherIcon.TGTATINTERCEPT);
}
}
else
{
Expand Down
Loading