Skip to content

Commit

Permalink
Move GetTrueAltitude to KethaneDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
Majiir committed Sep 4, 2014
1 parent 054a50b commit 6fda1ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
20 changes: 0 additions & 20 deletions Plugin/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ namespace Kethane
{
internal static class Misc
{
/// <summary>
/// Get true altitude above terrain (from MuMech lib)
/// Also from: http://kerbalspaceprogram.com/forum/index.php?topic=10324.msg161923#msg161923
/// </summary>
public static double GetTrueAltitude(Vessel vessel)
{
Vector3 CoM = vessel.findWorldCenterOfMass();
Vector3 up = (CoM - vessel.mainBody.position).normalized;
double altitudeASL = vessel.mainBody.GetAltitude(CoM);
double altitudeTrue = 0.0;
RaycastHit sfc;
if (Physics.Raycast(CoM, -up, out sfc, (float)altitudeASL + 10000.0F, 1 << 15))
altitudeTrue = sfc.distance;
else if (vessel.mainBody.pqsController != null)
altitudeTrue = vessel.mainBody.GetAltitude(CoM) - (vessel.mainBody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(vessel.mainBody.GetLongitude(CoM), Vector3d.down) * QuaternionD.AngleAxis(vessel.mainBody.GetLatitude(CoM), Vector3d.forward) * Vector3d.right) - vessel.mainBody.pqsController.radius);
else
altitudeTrue = vessel.mainBody.GetAltitude(CoM);
return altitudeTrue;
}

public static List<PartResource> GetConnectedResources(Part part, String resourceName)
{
var resourceDef = PartResourceLibrary.Instance.GetDefinition(resourceName);
Expand Down
22 changes: 20 additions & 2 deletions Plugin/PartModules/KethaneDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override void OnUpdate()
Events["EnableSounds"].active = !ScanningSound;
Events["DisableSounds"].active = ScanningSound;

if (Misc.GetTrueAltitude(vessel) <= this.DetectingHeight)
if (getTrueAltitude(vessel) <= this.DetectingHeight)
{
if (IsDetecting)
{
Expand All @@ -149,7 +149,7 @@ public override void OnUpdate()

public override void OnFixedUpdate()
{
double Altitude = Misc.GetTrueAltitude(vessel);
double Altitude = getTrueAltitude(vessel);
if (IsDetecting && this.vessel != null && this.vessel.gameObject.activeSelf && Altitude <= this.DetectingHeight)
{
var energyRequest = PowerConsumption * TimeWarp.fixedDeltaTime;
Expand Down Expand Up @@ -185,5 +185,23 @@ public override void OnFixedUpdate()
this.powerRatio = 0;
}
}

// Get true altitude above terrain (from MuMech lib)
// Also from: http://kerbalspaceprogram.com/forum/index.php?topic=10324.msg161923#msg161923
private static double getTrueAltitude(Vessel vessel)
{
Vector3 CoM = vessel.findWorldCenterOfMass();
Vector3 up = (CoM - vessel.mainBody.position).normalized;
double altitudeASL = vessel.mainBody.GetAltitude(CoM);
double altitudeTrue = 0.0;
RaycastHit sfc;
if (Physics.Raycast(CoM, -up, out sfc, (float)altitudeASL + 10000.0F, 1 << 15))
altitudeTrue = sfc.distance;
else if (vessel.mainBody.pqsController != null)
altitudeTrue = vessel.mainBody.GetAltitude(CoM) - (vessel.mainBody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(vessel.mainBody.GetLongitude(CoM), Vector3d.down) * QuaternionD.AngleAxis(vessel.mainBody.GetLatitude(CoM), Vector3d.forward) * Vector3d.right) - vessel.mainBody.pqsController.radius);
else
altitudeTrue = vessel.mainBody.GetAltitude(CoM);
return altitudeTrue;
}
}
}

0 comments on commit 6fda1ca

Please sign in to comment.