// Use this for initialization
    void Start()
    {
        ge     = GravityEngine.Instance();
        x_axis = new Vector3d(1, 0, 0);

        // mass scaling will cancel in this ratio
        soiRadius = OrbitUtils.SoiRadius(planet, moonBody);

        // TODO: allow moon to be OrbitUniversal as well.
        OrbitUniversal moonOrbit = moonBody.gameObject.GetComponent <OrbitUniversal>();

        if (moonOrbit == null)
        {
            Debug.LogError("Moon is required to have OrbitUniversal");
        }
        moonRadius = moonOrbit.GetMajorAxis();

        shipOrbit = spaceship.GetComponent <OrbitUniversal>();
        if (shipOrbit == null)
        {
            Debug.LogError("Require that the ship have an OrbitU");
        }
        if (shipOrbit.evolveMode != OrbitUniversal.EvolveMode.KEPLERS_EQN)
        {
            Debug.LogError("Controller requires ship on-rails but spaceship is off-rails");
        }

        // assuming circular orbit for ship
        shipRadius = shipOrbit.GetApogee();

        shipOrbitPredictor = spaceship.GetComponentInChildren <OrbitPredictor>();
    }
Example #2
0
    /// <summary>
    /// Determine the SOI radius in internal physics units.
    /// </summary>
    /// <param name="planet"></param>
    /// <param name="moon"></param>
    /// <returns></returns>
    public static float SoiRadius(NBody planet, NBody moon)
    {
        // to allow to run before GE is up, use Ellipse component to get radius
        OrbitEllipse moonEllipse = moon.gameObject.GetComponent <OrbitEllipse>();
        float        a;

        if (moonEllipse != null)
        {
            a = moonEllipse.a_scaled;
        }
        else
        {
            OrbitUniversal orbitU = moon.GetComponent <OrbitUniversal>();
            if (orbitU != null)
            {
                a = (float)orbitU.GetApogee();
            }
            else
            {
                Debug.LogWarning("Could not get moon orbit size");
                return(float.NaN);
            }
        }
        // mass scaling will cancel in this ratio
        return(Mathf.Pow(moon.mass / planet.mass, 0.4f) * a);
    }
    // Use this for initialization
    void Start()
    {
        ge = GravityEngine.Instance();

        shipAngle = shipAngleDeg * Mathf.Deg2Rad;
        soiAngle  = soiAngleDeg * Mathf.Deg2Rad;

        // disable maneuver predictor until things settle (can get Invalid local AABB otherwise)
        SetOrbitDisplays(false);

        // mass scaling will cancel in this ratio
        soiRadius = OrbitUtils.SoiRadius(planet, moonBody);
        toMoonOrbit.hyperDisplayRadius = soiRadius;

        // TODO: allow moon to be OrbitUniversal as well.
        OrbitEllipse moonEllipse = moonBody.gameObject.GetComponent <OrbitEllipse>();

        moonRadius  = moonEllipse.a_scaled;
        targetPoint = new Vector3d(moonRadius, soiRadius, 0);

        float        inclination = 0;
        OrbitEllipse shipEllipse = spaceship.gameObject.GetComponent <OrbitEllipse>();

        if (shipEllipse != null)
        {
            shipRadius  = shipEllipse.a_scaled;
            inclination = shipEllipse.inclination;
        }
        else
        {
            OrbitUniversal orbitU = spaceship.GetComponent <OrbitUniversal>();
            if (orbitU != null)
            {
                // assuming circular orbit
                shipRadius  = (float)orbitU.GetApogee();
                inclination = (float)orbitU.inclination;
            }
        }

        // check moon and ship orbit are co-planar
        if (Mathf.Abs(inclination - moonEllipse.inclination) > 1E-3)
        {
            Debug.LogWarning("Ship inclination and moon inclination are not equal.");
        }

        startPoint = new Vector3d(0, -shipRadius, 0);
        UpdateSoiPosition();
        UpdateStartPosition();
    }
Example #4
0
    void Update()
    {
        OrbitUniversal orbitU = orbitPredictor.GetOrbitUniversal();
        float          apogee = (float)orbitU.GetApogee();

        apogee_text.text = string.Format(apogee_str, apogee);
        if (orbitU.eccentricity < 1f)
        {
            float perigee = (float)orbitU.GetPerigee();
            perigee_text.text = string.Format(perigee_str, perigee);
        }
        else
        {
            perigee_text.text = string.Format("     Perigee: N/A");
        }
        e_text.text      = string.Format(ecc_str, orbitU.eccentricity);
        i_text.text      = string.Format(incl_str, orbitU.inclination);
        UOmega_text.text = string.Format(Omega_str, orbitU.omega_uc);
        LOmega_text.text = string.Format(omega_str, orbitU.omega_lc);
    }