Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 91e89a49c6f7
Choose a base ref
...
head repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 897a754f7b98
Choose a head ref
  • 3 commits
  • 9 files changed
  • 1 contributor

Commits on May 23, 2017

  1. Update dependencies

    Dorian Stoll committed May 23, 2017
    Copy the full SHA
    f30faaf View commit details
  2. Revert scaling madness

    Dorian Stoll committed May 23, 2017
    Copy the full SHA
    2bf2e61 View commit details
  3. Try to fix the stars properly

    Dorian Stoll committed May 23, 2017
    Copy the full SHA
    897a754 View commit details
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@PART[*]
{
@MODULE[ModuleDeployableSolarPanel]
{
@name = KopernicusSolarPanel
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -5,22 +5,22 @@
"VERSION":{
"MAJOR": 1,
"MINOR": 2,
"PATCH": 2,
"PATCH": 4,
"BUILD": 0
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 2,
"PATCH": 0
"PATCH": 2
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
"MINOR": 2,
"PATCH": 0
"PATCH": 2
},
"KSP_VERSION_MAX": {
"MAJOR": 1,
"MINOR": 2,
"PATCH": 0
"PATCH": 2
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@
<Compile Include="GLTools.cs" />
<Compile Include="HazardousOcean.cs" />
<Compile Include="KopernicusBuoyancy.cs" />
<Compile Include="KopernicusSolarPanel.cs" />
<Compile Include="KSC.cs" />
<Compile Include="LightShifter.cs" />
<Compile Include="MaterialWrapper\AerialTransCutout.cs" />
63 changes: 63 additions & 0 deletions Kopernicus/Kopernicus.Components/KopernicusSolarPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Kopernicus Planetary System Modifier
* ====================================
* Created by: BryceSchroeder and Teknoman117 (aka. Nathaniel R. Lewis)
* Maintained by: Thomas P., NathanKell and KillAshley
* Additional Content by: Gravitasi, aftokino, KCreator, Padishar, Kragrathea, OvenProofMars, zengei, MrHappyFace, Sigma88
* -------------------------------------------------------------
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This library is intended to be used as a plugin for Kerbal Space Program
* which is copyright 2011-2015 Squad. Your usage of Kerbal Space Program
* itself is governed by the terms of its EULA, not the license above.
*
* https://kerbalspaceprogram.com
*/

using UnityEngine;
using System;
using System.Linq;

namespace Kopernicus
{
namespace Components
{
/// <summary>
/// An extension for the Solar Panel to calculate the flux properly
/// </summary>
public class KopernicusSolarPanel : ModuleDeployableSolarPanel
{
public override void PostCalculateTracking(Boolean trackingLOS, Vector3 trackingDirection)
{
// Ugly hack ahead
Boolean oldUseCurve = useCurve;
if (!useCurve)
{
Single distMult = 0;
foreach (KopernicusStar star in KopernicusStar.Stars)
{
if (KopernicusStar.SolarFlux.ContainsKey(star.name))
distMult += (Single)(KopernicusStar.SolarFlux[star.name] / star.shifter.solarLuminosity);
}
powerCurve = new FloatCurve(new [] { new Keyframe(0, distMult), new Keyframe(1, distMult) });
useCurve = true;
}
base.PostCalculateTracking(trackingLOS, trackingDirection);
useCurve = oldUseCurve;
}
}
}
}
39 changes: 15 additions & 24 deletions Kopernicus/Kopernicus.Components/KopernicusStar.cs
Original file line number Diff line number Diff line change
@@ -89,8 +89,6 @@ public static void SunBodyFlux(ModularFlightIntegrator flightIntegrator)
// FI Values
bool directSunlight = flightIntegrator.Vessel.directSunlight;
double solarFlux = flightIntegrator.solarFlux;
double bodyEmissiveFlux = flightIntegrator.bodyEmissiveFlux;
double bodyAlbedoFlux = flightIntegrator.bodyAlbedoFlux;
if (!SolarFlux.ContainsKey(Current.name))
SolarFlux.Add(Current.name, solarFlux);
else
@@ -105,25 +103,21 @@ public static void SunBodyFlux(ModularFlightIntegrator flightIntegrator)
CalculatePhysics();

// Calculate Flux
Flux(flightIntegrator, star);
Double flux = Flux(flightIntegrator, star);

// And save them
if (flightIntegrator.Vessel.directSunlight)
if (flux > 0)
directSunlight = true;
solarFlux += flightIntegrator.solarFlux;
bodyEmissiveFlux += flightIntegrator.bodyEmissiveFlux;
bodyAlbedoFlux += flightIntegrator.bodyAlbedoFlux;
solarFlux += flux;
if (!SolarFlux.ContainsKey(star.name))
SolarFlux.Add(star.name, solarFlux);
SolarFlux.Add(star.name, flux);
else
SolarFlux[star.name] = solarFlux;
SolarFlux[star.name] = flux;
}

// Reapply
flightIntegrator.Vessel.directSunlight = directSunlight;
flightIntegrator.solarFlux = solarFlux;
flightIntegrator.bodyEmissiveFlux = bodyEmissiveFlux;
flightIntegrator.bodyAlbedoFlux = bodyAlbedoFlux;

// Set Physics
PhysicsGlobals.SolarLuminosityAtHome = Current.shifter.solarLuminosity;
@@ -149,51 +143,48 @@ public static void CalculatePhysics()
/// <summary>
/// Small method to handle flux
/// </summary>
public static void Flux(ModularFlightIntegrator fi, KopernicusStar star)
public static Double Flux(ModularFlightIntegrator fi, KopernicusStar star)
{
// Nullchecks
if (fi.Vessel == null || fi.Vessel.state == Vessel.State.DEAD || fi.CurrentMainBody == null)
{
return;
return 0;
}

// Get sunVector
RaycastHit raycastHit;
fi.Vessel.directSunlight = false;
Boolean directSunlight = false;
Vector3d scaledSpace = ScaledSpace.LocalToScaledSpace(fi.IntegratorTransform.position);
double scale = Math.Max((star.sun.scaledBody.transform.position - scaledSpace).magnitude, 1);
Vector3 sunVector = (star.sun.scaledBody.transform.position - scaledSpace) / scale;
Ray ray = new Ray(ScaledSpace.LocalToScaledSpace(fi.IntegratorTransform.position), sunVector);

// Get Body flux
fi.solarFlux = 0;
fi.sunDot = Vector3d.Dot(fi.sunVector, fi.Vessel.upAxis);
fi.CurrentMainBody.GetAtmoThermalStats(true, FlightIntegrator.sunBody, fi.sunVector, fi.sunDot, fi.Vessel.upAxis, fi.altitude, out fi.atmosphereTemperatureOffset, out fi.bodyEmissiveFlux, out fi.bodyAlbedoFlux);
Vector3d scaleFactor = ((Vector3d)star.sun.scaledBody.transform.position - fi.CurrentMainBody.scaledBody.transform.position) * (double)ScaledSpace.ScaleFactor;

// Get Solar Flux
double realDistanceToSun = 0;
if (!Physics.Raycast(ray, out raycastHit, Single.MaxValue, ModularFlightIntegrator.SunLayerMask))
{
fi.Vessel.directSunlight = true;
directSunlight = true;
realDistanceToSun = scale * ScaledSpace.ScaleFactor - star.sun.Radius;
}
else if (raycastHit.transform.GetComponent<ScaledMovement>().celestialBody == star.sun)
{
realDistanceToSun = ScaledSpace.ScaleFactor * raycastHit.distance;
fi.Vessel.directSunlight = true;
directSunlight = true;
}
if (fi.Vessel.directSunlight)
if (directSunlight)
{
fi.solarFlux = PhysicsGlobals.SolarLuminosity/(12.5663706143592*realDistanceToSun*realDistanceToSun);
return PhysicsGlobals.SolarLuminosity/(12.5663706143592*realDistanceToSun*realDistanceToSun);
}
return 0;
}

/// <summary>
/// Returns the star the given body orbits
/// </summary>
public static KopernicusStar GetNearest(CelestialBody body)
{
return Stars.OrderBy(s => Vector3.Distance(body.position, s.sun.position)).First();

CelestialBody homeBody = body;
while (Stars.All(s => s.sun != homeBody.referenceBody) && homeBody.referenceBody != null)
homeBody = homeBody.referenceBody;
4 changes: 2 additions & 2 deletions Kopernicus/Kopernicus.Components/Ring.cs
Original file line number Diff line number Diff line change
@@ -166,8 +166,8 @@ public void BuildRing()

ringMR.material.SetTexture("_MainTex", texture);

ringMR.material.SetFloat("innerRadius", innerRadius / parent.transform.localScale.x);
ringMR.material.SetFloat("outerRadius", outerRadius / parent.transform.localScale.x);
ringMR.material.SetFloat("innerRadius", innerRadius * parent.transform.localScale.x);
ringMR.material.SetFloat("outerRadius", outerRadius * parent.transform.localScale.x);

if (useNewShader)
{
2 changes: 1 addition & 1 deletion Kopernicus/Kopernicus/RuntimeUtility/StarLightSwitcher.cs
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public class StarComponent : MonoBehaviour
public CelestialBody celestialBody { get; set; }

// We need to patch the sun Transform of the Radiators
private static FieldInfo radiatorSun { get; }
private static FieldInfo radiatorSun { get; set; }

// get the FieldInfo
static StarComponent()