Example #1
0
 /// <summary>
 /// SetOrbit
 /// Determine orbit params from an attached orbit component (if Kepler) otherwise use the velocity to
 /// determine the orbit
 /// </summary>
 /// <param name="forNbody"></param>
 /// <param name="aroundNBody"></param>
 public void SetOrbit(NBody forNbody, NBody aroundNBody)
 {
     nbody       = forNbody;
     centralMass = aroundNBody;
     if (nbody.engineRef.fixedBody != null)
     {
         OrbitEllipse orbitEllipse = nbody.GetComponent <OrbitEllipse>();
         if (orbitEllipse != null)
         {
             ecc         = orbitEllipse.ecc;
             a           = orbitEllipse.a;
             omega_lc    = orbitEllipse.omega_lc;
             omega_uc    = orbitEllipse.omega_uc;
             inclination = orbitEllipse.inclination;
             period      = CalcPeriod(a, aroundNBody);
             // need tau, period
             return;
         }
         OrbitHyper orbitHyper = nbody.GetComponent <OrbitHyper>();
         if (orbitHyper != null)
         {
             ecc         = orbitHyper.ecc;
             perihelion  = orbitHyper.perihelion;
             omega_lc    = orbitHyper.omega_lc;
             omega_uc    = orbitHyper.omega_uc;
             inclination = orbitHyper.inclination;
             // need phase, tau, period
             return;
         }
     }
     SetOrbitForVelocity(forNbody, aroundNBody);
 }
Example #2
0
    public override void OnInspectorGUI()
    {
        GUI.changed = false;
        OrbitEllipse orbit = (OrbitEllipse)target;

        OrbitEllipse.evolveType evolveMode = orbit.evolveMode;

        evolveMode = (OrbitEllipse.evolveType)EditorGUILayout.EnumPopup(new GUIContent("Evolve Mode", modeTip), orbit.evolveMode);

        if (GUI.changed)
        {
            Undo.RecordObject(orbit, "OrbitEllipse Change");
            orbit.evolveMode = evolveMode;
            EditorUtility.SetDirty(orbit);
        }
        base.OnInspectorGUI();

        // Display the Hill Radius as a guide for where to place moons...
        float r_hill = 0;

        if (orbit.GetCenterObject() != null)
        {
            r_hill = OrbitUtils.HillRadius(orbit.GetCenterObject(), orbit.transform.gameObject);
        }
        EditorGUILayout.LabelField(new GUIContent(string.Format("Hill Radius:  {0}", r_hill), hillTip));
        // EditorGUILayout.LabelField(new GUIContent(string.Format("Orbit Period: {0}", orbit.GetPeriod()), periodTip));

        if (axisUpdated)
        {
            orbit.ApplyScale(GravityEngine.Instance().GetLengthScale());
        }
    }
    private void TestRV(OrbitData od, GameObject planet, GameObject star, float orbitRadius)
    {
        GameObject   testPlanet  = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse testEllipse = testPlanet.GetComponent <OrbitEllipse>();

        // Run init explicitly to update transform details
        testEllipse.InitFromOrbitData(od);

        // Awkward but cannot add a new object to GE when it is stopped, so re-add all three
        GravityEngine ge = GravityEngine.Instance();

        ge.Clear();
        ge.AddBody(star);
        ge.AddBody(planet);
        ge.AddBody(testPlanet);
        ge.Setup();
        ge.LogDump();
        Vector3 r_od = ge.GetPhysicsPosition(testPlanet.GetComponent <NBody>());
        Vector3 v_od = ge.GetVelocity(testPlanet);
        Vector3 r_i  = ge.GetPhysicsPosition(planet.GetComponent <NBody>());
        Vector3 v_i  = ge.GetVelocity(planet);

        Debug.Log(" r_i=" + r_i + " r_od=" + r_od + " delta=" + Vector3.Distance(r_i, r_od));
        Debug.Log(" v_i=" + v_i + " v_od=" + v_od + " delta=" + Vector3.Distance(v_i, v_od));
        Assert.IsTrue(FloatEqual(Vector3.Distance(r_i, r_od), 0f, 1E-2));
        Assert.IsTrue(FloatEqual(Vector3.Distance(v_i, v_od), 0f, 1E-2));
    }
Example #4
0
    public void OmegasEllipseInclination()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.InitNBody(1f, 1f);

        orbitEllipse.inclination = 35f;
        orbitEllipse.ecc         = 0.25f;
        orbitEllipse.Init();
        orbitEllipse.ApplyScale(1f);
        orbitEllipse.InitNBody(1f, 1f);

        // Try some values of om
        float[] omegaValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f };
        foreach (float omega in omegaValues)
        {
            orbitEllipse.omega_uc = omega;
            orbitEllipse.Init();
            orbitEllipse.InitNBody(1f, 1f);
            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            TestRV(od, planet, star, orbitRadius);
        }
    }
Example #5
0
    public void AddBody(string bodyType)
    {
        GameObject go = Instantiate(orbitingPrefab) as GameObject;

        go.transform.parent = star.transform;
        NBody nbody = go.GetComponent <NBody>();

        if (bodyType == "massless")
        {
            nbody.mass = 0f;
            masslessObjects.Add(go);
        }
        else
        {
            nbody.mass = 1f;                    // nominal
            massiveObjects.Add(go);
        }
        OrbitEllipse eb = go.GetComponent <OrbitEllipse>();

        if (eb == null)
        {
            Debug.LogError("Failed to get EllipseStart from prefab");
            return;
        }
        eb.paramBy     = EllipseBase.ParamBy.AXIS_A;
        eb.a           = Random.Range(MIN_RADIUS, MAX_RADIUS);
        eb.inclination = Random.Range(-30f, 30f);
        eb.Init();
        TrailRenderer[] trail = go.GetComponentsInChildren <TrailRenderer>();
        trail[0].material.color = colors[colorIndex];
        colorIndex = (colorIndex + 1) % colors.Length;
        GravityEngine.instance.AddBody(go);
    }
Example #6
0
    public void PhaseRetrogradeEllipse()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.ecc         = 0.4f;
        orbitEllipse.inclination = 180f;

        // Try some values of om
        float[] phaseValues = { 30f, 45f, 60f, 90f, 135f, 180f, 0f };
        foreach (float phase in phaseValues)
        {
            orbitEllipse.phase = phase;
            orbitEllipse.Init();
            orbitEllipse.ApplyScale(1f);
            orbitEllipse.InitNBody(1f, 1f);
            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            Debug.Log("phase = " + phase + " od.phase=" + od.phase);
            // Need a bit of leeway at 0 with error
            Assert.IsTrue(FloatEqual(phase, od.phase, 0.02));
            TestRV(od, planet, star, orbitRadius);
        }
    }
Example #7
0
    public void CirclePhaseOmegaInclined()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.inclination = 20f;

        // Try some values of phase
        float[] phaseValues  = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f };
        float[] omegaUValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f };
        foreach (float phase in phaseValues)
        {
            foreach (float omegau in omegaUValues)
            {
                orbitEllipse.phase    = phase;
                orbitEllipse.omega_uc = omegau;
                orbitEllipse.Init();
                orbitEllipse.ApplyScale(1f);
                orbitEllipse.InitNBody(1f, 1f);
                orbitEllipse.Log("Initial circle:");
                OrbitData od = new OrbitData();
                od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
                Debug.Log("TEST: phase = " + phase + " od.phase=" + od.phase +
                          " omegaU = " + omegau + " od.omegau=" + od.omega_uc);
                TestRV(od, planet, star, orbitRadius);
            }
        }
    }
    public void OmegaULEllipseInclined()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.InitNBody(1f, 1f);

        orbitEllipse.inclination = 30f;
        orbitEllipse.ecc         = 0.2f;
        orbitEllipse.Init();
        orbitEllipse.ApplyScale(1f);
        orbitEllipse.InitNBody(1f, 1f);

        // Try some values of om
        float[] omegaUValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 310f };
        float[] omegaLValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 310f };
        foreach (float omegaU in omegaUValues)
        {
            foreach (float omegaL in omegaLValues)
            {
                orbitEllipse.omega_uc = omegaU;
                orbitEllipse.omega_lc = omegaL;
                TestSetupUtils.SetupGravityEngine(star, planet);

                orbitEllipse.Log("OmegaUL inclined:");
                OrbitData od = new OrbitData();
                od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
                Debug.Log("omegaU = " + omegaU + "omegaL = " + omegaL + " OD:=" + od.LogString());
                TestRV(od, planet, star, orbitRadius);
            }
        }
    }
    public void PhaseNoInclinationEllipse()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 20f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.ecc = 0.2f;

        // Try some values of om
        float[] phaseValues = { 30f, 45f, 60f, 90f, 135f, 180f, 225f, 270f, 325f, 0f };
        foreach (float phase in phaseValues)
        {
            orbitEllipse.phase = phase;
            TestSetupUtils.SetupGravityEngine(star, planet);

            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            orbitEllipse.Log("PhaseNoInclinationEllipse:");
            Debug.Log(od.LogString());
            // Need a bit of leeway at 0 with error
            Assert.IsTrue(FloatEqualMod360(phase, od.phase, 0.02));
            Assert.IsTrue(FloatEqualMod360(0f, od.omega_lc, 0.02));
            Assert.IsTrue(FloatEqualMod360(0f, od.omega_uc, 0.02));
            TestRV(od, planet, star, orbitRadius);
        }
    }
    public void CirclePhaseOmegaInclined()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.inclination = 20f;

        // Try some values of phase
        // omegaU for a circle does not make sense, no axis to relate it to.
        float[] phaseValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f };
        foreach (float phase in phaseValues)
        {
            orbitEllipse.phase    = phase;
            orbitEllipse.omega_uc = 0;
            TestSetupUtils.SetupGravityEngine(star, planet);
            Debug.LogFormat("Test for phase={0} omegau={1}", phase, 0);
            orbitEllipse.Log("Initial circle:");
            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            Debug.Log("OrbitData: " + od.LogString());
            Assert.IsTrue(FloatEqualMod360(phase, od.phase, 0.05));
            Assert.IsTrue(FloatEqualMod360(0, od.omega_uc, 0.05));
            TestRV(od, planet, star, orbitRadius);
        }
    }
    // Check eccentricity and inclination
    public void EllipseInclination()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        float eccentricity = 0.3f;

        orbitEllipse.ecc = eccentricity;
        TestSetupUtils.SetupGravityEngine(star, planet);

        // take the velocity and check
        OrbitData orbitData = new OrbitData();

        orbitData.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
        Assert.IsTrue(FloatEqual(orbitRadius, orbitData.a));
        Assert.IsTrue(FloatEqual(eccentricity, orbitData.ecc));

        // Try some values of inclination
        float[] inclinationValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f };
        foreach (float inc in inclinationValues)
        {
            Debug.Log("====EclipseInclination====    inc=" + inc);
            orbitEllipse.inclination = inc;
            TestSetupUtils.SetupGravityEngine(star, planet);
            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            Debug.Log("TEST: incl = " + orbitEllipse.inclination + " ecc=" + orbitEllipse.ecc + " od:" + od.LogString());
            Assert.IsTrue(FloatEqual(inc, od.inclination));
            TestRV(od, planet, star, orbitRadius);
        }
    }
Example #12
0
    public void OmegaUNoInclination()
    {
        const float  mass         = 1000f;
        GameObject   star         = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0));
        const float  orbitRadius  = 10f;
        GameObject   planet       = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius);
        OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>();

        orbitEllipse.InitNBody(1f, 1f);

        orbitEllipse.ecc = 0.1f;

        // Try some values of om
        float[] omegaValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f };
        foreach (float omega in omegaValues)
        {
            orbitEllipse.omega_uc = omega;
            orbitEllipse.Init();
            orbitEllipse.ApplyScale(1f);
            orbitEllipse.InitNBody(1f, 1f);
            OrbitData od = new OrbitData();
            od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>());
            Debug.Log("omega = " + omega + " od.omega_lc=" + od.omega_lc);
            Assert.IsTrue(FloatEqual(omega, od.omega_lc, 0.4));
        }
    }
Example #13
0
	public static void SetEllipse(float epoch, EllipseBase ellipseBase, SolarBody sb) {
		// orbital element variation is not provided - only phase to determine
		// What is the delat to the reference epoch?
		float deltaYears = epoch - sb.epoch;
		float period = SolarUtils.GetPeriodYears(sb);
		float numPeriod = deltaYears/period;
		ellipseBase.phase = OrbitEllipse.MeanToTrueAnomoly(NUtils.DegressMod360( sb.longitude + 360f*numPeriod), ellipseBase.ecc);
	}
Example #14
0
        public static OrbitEllipse CreateOrbitEllipse(SceneMgr mgr, Vector position, float radiusX, float radiusY, Color color)
        {
            OrbitEllipse ellipse = new OrbitEllipse(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId()), radiusX, radiusY);

            ellipse.Position = position;
            ellipse.Color    = color;
            ellipse.SetGeometry(SceneGeometryFactory.CreateConstantColorEllipseGeometry(ellipse));

            return(ellipse);
        }
Example #15
0
 /// <summary>
 /// Construct an orbit data routine from an existing orbit ellipse by copying the orbital elements
 /// </summary>
 /// <param name="orbitEllipse"></param>
 public OrbitData(OrbitEllipse orbitEllipse)
 {
     a           = orbitEllipse.a_scaled;
     omega_lc    = orbitEllipse.omega_lc;
     omega_uc    = orbitEllipse.omega_uc;
     inclination = orbitEllipse.inclination;
     ecc         = orbitEllipse.ecc;
     phase       = orbitEllipse.phase;
     centralMass = orbitEllipse.centerObject.GetComponent <NBody>();
     mu          = GravityEngine.Instance().GetPhysicsMass(centralMass);
     period      = CalcPeriod();
 }
Example #16
0
        private void SpawnNewEllipse()
        {
            OrbitEllipse ellipse = SceneObjectFactory.CreateOrbitEllipse(me.SceneMgr, line.End, 2.5f, 2.5f, Colors.Black);

            MiningEllipseControl control = new MiningEllipseControl();

            control.LineToFollow = line;

            ellipse.AddControl(control);

            me.SceneMgr.DelayedAttachToScene(ellipse);
        }
Example #17
0
    public void InitOrbit(SolarBody sbody)
    {
        // check there is an Ellipse Base
        OrbitEllipse orbitEllipse = sbody.GetComponent <OrbitEllipse>();

        if (orbitEllipse == null)
        {
            Debug.LogError("Prefab must have OrbitEllipse component");
            return;
        }
        orbitEllipse.InitFromSolarBody(sbody);
        ScaleModel(sbody.transform.gameObject, sbody);
        SetPhase(orbitEllipse, sbody);
    }
Example #18
0
 /// <summary>
 /// SetOrbit
 /// Determine orbit params from an attached orbit component (if Kepler) otherwise use the velocity to
 /// determine the orbit
 /// </summary>
 /// <param name="forNbody"></param>
 /// <param name="aroundNBody"></param>
 public void SetOrbit(NBody forNbody, NBody aroundNBody)
 {
     nbody       = forNbody;
     centralMass = aroundNBody;
     // is this a Kepler body
     if (nbody.engineRef.fixedBody != null)
     {
         OrbitEllipse orbitEllipse = nbody.GetComponent <OrbitEllipse>();
         if (orbitEllipse != null)
         {
             ecc         = orbitEllipse.ecc;
             a           = orbitEllipse.a * GravityEngine.Instance().GetLengthScale();
             omega_lc    = orbitEllipse.omega_lc;
             omega_uc    = orbitEllipse.omega_uc;
             inclination = orbitEllipse.inclination;
             mu          = GravityEngine.Instance().GetPhysicsMass(aroundNBody);
             period      = CalcPeriod();
             // TODO:  tau
             phase = orbitEllipse.phase;
             return;
         }
         OrbitUniversal orbitU = nbody.GetComponent <OrbitUniversal>();
         if (orbitU != null)
         {
             ecc = (float)orbitU.eccentricity;
             // Might need to make a > 0 for hyperbola since OrbitData got this wrong??
             a           = (float)orbitU.p / (1 - ecc * ecc);
             omega_lc    = (float)orbitU.omega_lc;
             omega_uc    = (float)orbitU.omega_uc;
             inclination = (float)orbitU.inclination;
             mu          = GravityEngine.Instance().GetPhysicsMass(aroundNBody);
             period      = CalcPeriod();
             // TODO:  tau
             phase = (float)orbitU.phase;
             return;
         }
         OrbitHyper orbitHyper = nbody.GetComponent <OrbitHyper>();
         if (orbitHyper != null)
         {
             ecc         = orbitHyper.ecc;
             perihelion  = orbitHyper.perihelion * GravityEngine.Instance().GetLengthScale();
             omega_lc    = orbitHyper.omega_lc;
             omega_uc    = orbitHyper.omega_uc;
             inclination = orbitHyper.inclination;
             // need phase, tau, period
             return;
         }
     }
     SetOrbitForVelocity(forNbody, aroundNBody);
 }
Example #19
0
    public void AddBody(string bodyType)
    {
        GameObject go = Instantiate(orbitingPrefab) as GameObject;

        go.transform.parent = star.transform;
        NBody nbody = go.GetComponent <NBody>();

        if (bodyType == MASSLESS)
        {
            nbody.mass = 0f;
            masslessObjects.Add(go);
        }
        else if (bodyType == KEPLER)
        {
            nbody.mass = 0f;
            keplerObjects.Add(go);
        }
        else
        {
            nbody.mass = mass;                  // nominal
            massiveObjects.Add(go);
        }

        OrbitEllipse eb = go.GetComponent <OrbitEllipse>();

        if (eb == null)
        {
            Debug.LogError("Failed to get EllipseStart from prefab");
            return;
        }
        eb.paramBy     = EllipseBase.ParamBy.AXIS_A;
        eb.a           = Random.Range(minRadius, maxRadius);
        eb.inclination = Random.Range(-80f, 80f);
        if (bodyType == KEPLER)
        {
            eb.evolveMode = OrbitEllipse.evolveType.KEPLERS_EQN;
        }
        eb.Init();
        GravityEngine.instance.AddBody(go);

        // Do this after added otherwise Kepler trails have a segment to origin
        TrailRenderer trail = go.GetComponentInChildren <TrailRenderer>();

        if (trail != null)
        {
            trail.material.color = colors[colorIndex];
            colorIndex           = (colorIndex + 1) % colors.Length;
            trail.enabled        = true;
        }
    }
    // 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 #21
0
    /// <summary>
    /// Determine if and how many objects are orbital parents.
    /// e.g. Sun = 0, planet=1, moon=2
    /// </summary>
    public void CalcOrbitDepth()
    {
        GameObject go = gameObject;

        do
        {
            OrbitEllipse ellipse = go.GetComponent <OrbitEllipse>();
            if (ellipse != null)
            {
                go = ellipse.centerObject;
                orbitDepth++;
                continue;
            }
            OrbitUniversal orbitU = go.GetComponent <OrbitUniversal>();
            if (orbitU != null)
            {
                go = orbitU.centerNbody.gameObject;
                orbitDepth++;
                continue;
            }
            OrbitHyper hyper = go.GetComponent <OrbitHyper>();
            if (hyper != null)
            {
                go = hyper.centerObject;
                orbitDepth++;
                continue;
            }
            if (go.transform.parent != null)
            {
                BinaryPair bp = go.transform.parent.gameObject.GetComponent <BinaryPair>();
                if (bp != null)
                {
                    go = bp.gameObject;
                    orbitDepth++;
                    continue;
                }
                // If parent has an NBody, then it's an orbital parent, since need to inherit its velocity
                NBody nbody_parent = go.transform.parent.gameObject.GetComponent <NBody>();
                if (nbody_parent != null)
                {
                    go = nbody_parent.gameObject;
                    orbitDepth++;
                    continue;
                }
            }
            go = null;
        } while (go != null);
    }
Example #22
0
        public static DrawingGroup CreateConstantColorEllipseGeometry(OrbitEllipse e)
        {
            DrawingGroup d = null;

            e.SceneMgr.Invoke(new Action(() =>
            {
                EllipseGeometry geom = new EllipseGeometry(new Point(e.RadiusX, e.RadiusY), e.RadiusX, e.RadiusY);
                d = new DrawingGroup();
                d.Children.Add(new GeometryDrawing(new SolidColorBrush(e.Color), null, geom));

                TransformGroup tg = new TransformGroup();
                tg.Children.Add(new TranslateTransform(e.Position.X, e.Position.Y));
                d.Transform = tg;
            }));

            return(d);
        }
    private void AddBody()
    {
        // Pick a prefab
        int prefabNum = (int)Random.Range(0, planetPrefabs.Length);

        GameObject planet = Instantiate(planetPrefabs[prefabNum]) as GameObject;

        // make a child of this object
        planet.transform.parent = gameObject.transform;

        OrbitEllipse oe = planet.GetComponent <OrbitEllipse>();

        oe.centerObject = gameObject;
        // set ranges with appropriate limits
        oe.a           = Random.Range(Mathf.Max(a_min, 0.1f), a_max);
        oe.ecc         = Random.Range(Mathf.Max(ecc_min, 0f), Mathf.Min(0.99f, ecc_max));
        oe.inclination = Random.Range(Mathf.Max(0, incl_min), Mathf.Min(180f, incl_max));
        oe.omega_lc    = Random.Range(Mathf.Max(0, omega_lc_min), Mathf.Min(359.9f, omega_lc_max));
        oe.omega_uc    = Random.Range(Mathf.Max(0, omega_uc_min), Mathf.Min(359.9f, omega_uc_max));
        oe.phase       = Random.Range(Mathf.Max(0, phase_min), Mathf.Min(359.9f, phase_max));

        // If there is a MeshRenderer - apply scale
        MeshRenderer mr = planet.GetComponentInChildren <MeshRenderer>();

        if (mr != null)
        {
            mr.transform.localScale = Random.Range(Mathf.Max(scale_min, 0.01f), scale_max) * Vector3.one;
        }

        // If there is an OrbitPredictor, assign the parent
        OrbitPredictor op = planet.GetComponentInChildren <OrbitPredictor>();

        if (op != null)
        {
            op.body = planet;
            op.SetNBody(planet.GetComponent <NBody>());
            op.SetCenterObject(gameObject);
        }
        GravityEngine.Instance().AddBody(planet);
    }
Example #24
0
    private void EllipseInit(GameObject go, NBody nbody, GameObject parent, string bodyType)
    {
        OrbitEllipse eb = go.GetComponent <OrbitEllipse>();

        eb.centerObject = parent;
        if (eb == null)
        {
            Debug.LogError("Failed to get OrbitEllipse from prefab:" + go.name);
            return;
        }
        // Awkward test code
        if (parent == star)
        {
            eb.paramBy     = EllipseBase.ParamBy.AXIS_A;
            eb.a           = Random.Range(minRadius, maxRadius);
            eb.inclination = Random.Range(-80f, 80f);
            eb.ecc         = Random.Range(minEccentricity, maxEccentricity);
        }
        else
        {
            // moon test, so keep "a" small
            eb.paramBy     = EllipseBase.ParamBy.AXIS_A;
            eb.a           = moonRadius;
            eb.inclination = Random.Range(-80f, 80f);
            eb.ecc         = 0;
        }
        if (bodyType == KEPLER)
        {
            eb.evolveMode = OrbitEllipse.evolveType.KEPLERS_EQN;
        }
        eb.Init();
        OrbitPredictor op = go.GetComponentInChildren <OrbitPredictor>();

        if (op != null)
        {
            op.SetNBody(nbody);
            op.SetCenterObject(parent);
        }
    }