Skip to content

Commit

Permalink
calculate flux differently
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigma88 committed Mar 19, 2020
1 parent d31af22 commit b72b814
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/Kopernicus/Components/KopernicusSolarPanels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void FixedUpdate()
KopernicusStar star = KopernicusStar.CelestialBodies[SP.trackingBody];
star.shifter.ApplyPhysics();

vessel.solarFlux = star.CalculateFluxAt(vessel);
vessel.solarFlux = star.CalculateFluxAt(vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;
}
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ void FixedUpdate()
{
KopernicusStar trackingStar = KopernicusStar.CelestialBodies[SP.trackingBody];

Double bestFlux = vessel.solarFlux;
Double bestFlux = vessel.solarFlux * 1360 / PhysicsGlobals.SolarLuminosityAtHome;
KopernicusStar bestStar = trackingStar;
Double totalFlux = 0;
Single totalAoA = SP.sunAOA;
Expand All @@ -124,7 +124,8 @@ void FixedUpdate()
{
// Use this star
star.shifter.ApplyPhysics();
vessel.solarFlux = star.CalculateFluxAt(vessel);
double flux = star.CalculateFluxAt(vessel);
vessel.solarFlux += flux * PhysicsGlobals.SolarLuminosityAtHome / 1360;

// Change the tracking body
SP.trackingBody = star.sun;
Expand All @@ -143,9 +144,9 @@ void FixedUpdate()
_totalFlow += SP._flowRate;
totalFlow += SP.flowRate;

if (bestFlux < vessel.solarFlux)
if (bestFlux < flux)
{
bestFlux = vessel.solarFlux;
bestFlux = flux;
bestStar = star;
}

Expand All @@ -161,7 +162,7 @@ void FixedUpdate()
// Restore the starting star
trackingStar.shifter.ApplyPhysics();

totalFlux += trackingStar.CalculateFluxAt(vessel);
totalFlux += trackingStar.CalculateFluxAt(vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;

vessel.solarFlux = totalFlux;
SP.sunAOA = totalAoA;
Expand Down
6 changes: 3 additions & 3 deletions src/Kopernicus/Components/KopernicusStar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public Double CalculateFluxAt(Vessel vessel)

if (directSunlight)
{
Double output = PhysicsGlobals.SolarLuminosity / (12.5663706143592 * realDistanceToSun * realDistanceToSun) * PhysicsGlobals.SolarLuminosityAtHome / 1360;
Double output = PhysicsGlobals.SolarLuminosity / (12.5663706143592 * realDistanceToSun * realDistanceToSun);
return output;
}

Expand Down Expand Up @@ -337,14 +337,14 @@ public static void SunBodyFlux(ModularFlightIntegrator MFI)
star.shifter.ApplyPhysics();

// Calculate Flux
solarFlux += star.CalculateFluxAt(MFI.Vessel);
solarFlux += star.CalculateFluxAt(MFI.Vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;
}

// Set Physics to the Current Star
KopernicusStar.Current.shifter.ApplyPhysics();

// Calculate Flux
solarFlux += Current.CalculateFluxAt(MFI.Vessel);
solarFlux += Current.CalculateFluxAt(MFI.Vessel) * PhysicsGlobals.SolarLuminosityAtHome / 1360;

// Reapply
MFI.Vessel.directSunlight = solarFlux > 0;
Expand Down

0 comments on commit b72b814

Please sign in to comment.