Exemplo n.º 1
0
    private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbit, CelestialBodyData targetPlanet, ref bool drawn)
    {
        List <double> list = new List <double>();

        if (orbit.periapsis < targetPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetPlanet.orbitData.orbitHeightM)
        {
            double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity);
            list.Add(trueAnomalyAtRadius);
            list.Add(-trueAnomalyAtRadius);
        }
        else
        {
            if (!orbit.CanPasSOI(targetPlanet.orbitData.orbitHeightM, targetPlanet.mapData.showClosestApproachDistance))
            {
                return;
            }
            if (orbit.apoapsis < targetPlanet.orbitData.orbitHeightM)
            {
                list.Add(3.1415927410125732);
            }
            else
            {
                list.Add(0.0);
            }
        }
        double  num  = double.PositiveInfinity;
        Double3 posA = Double3.zero;
        Double3 posB = Double3.zero;

        for (int i = 0; i < list.Count; i++)
        {
            double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]);
            if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime)
            {
                Double3 position       = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis);
                Double3 posOut         = targetPlanet.GetPosOut(nextTrueAnomalyPassageTime);
                double  sqrMagnitude2d = (position - posOut).sqrMagnitude2d;
                if (sqrMagnitude2d <= num)
                {
                    num  = sqrMagnitude2d;
                    posA = position;
                    posB = posOut;
                }
            }
        }
        if (list.Count > 0)
        {
            ClosestApproach.SetLine(closestApproachLine, posA, posB, Ref.map.mapRefs[targetPlanet.parentBody].holder);
            drawn = true;
        }
    }
Exemplo n.º 2
0
    private bool CalculateClosestApproach(Orbit orbit, CelestialBodyData targetingPlanet)
    {
        double  num     = double.PositiveInfinity;
        Double3 @double = Double3.zero;
        Double3 a       = Double3.zero;
        bool    flag    = false;

        if (orbit.planet != targetingPlanet)
        {
            List <double> list = new List <double>();
            if (orbit.periapsis < targetingPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetingPlanet.orbitData.orbitHeightM)
            {
                double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetingPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity);
                list.Add(trueAnomalyAtRadius);
                list.Add(-trueAnomalyAtRadius);
            }
            else
            {
                if (!orbit.CanPasSOI(targetingPlanet.orbitData.orbitHeightM, targetingPlanet.mapData.showClosestApproachDistance))
                {
                    return(false);
                }
                if (orbit.apoapsis < targetingPlanet.orbitData.orbitHeightM)
                {
                    list.Add(3.1415927410125732);
                }
                else
                {
                    list.Add(0.0);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]);
                if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime)
                {
                    Double3 position       = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis);
                    Double3 double2        = (!(orbit.planet != targetingPlanet)) ? Double3.zero : targetingPlanet.GetPosOut(nextTrueAnomalyPassageTime);
                    double  sqrMagnitude2d = (position - double2).sqrMagnitude2d;
                    if (sqrMagnitude2d < num)
                    {
                        num     = sqrMagnitude2d;
                        @double = position;
                        a       = double2;
                        flag    = true;
                    }
                }
            }
        }
        else
        {
            @double = Kepler.GetPosition(orbit.periapsis, 0.0, orbit.argumentOfPeriapsis);
            flag    = true;
        }
        if (!flag)
        {
            return(false);
        }
        Transform transform = (!(orbit.planet != targetingPlanet)) ? targetingPlanet.mapRefs.holder : targetingPlanet.parentBody.mapRefs.holder;

        if (this.transferWindow.closestApproachMarker.transform.parent != transform)
        {
            this.transferWindow.closestApproachMarker.transform.parent = transform;
        }
        this.transferWindow.closestApproachMarker.transform.localPosition = (@double / 10000.0).toVector3;
        Double3 double3 = (a - @double) / 10000.0;

        this.transferWindow.closestApproachMarker.SetPosition(1, double3.toVector3);
        this.transferWindow.closestApproachMarker.sharedMaterial.mainTextureScale = new Vector2(Mathf.Max(1.6f, (float)(double3.magnitude2d / -(float)this.mapPosition.z * 80.0) + 0.6f), 1f);
        return(true);
    }