示例#1
0
    private void HyperInit(GameObject go, NBody nbody, GameObject parent)
    {
        OrbitHyper hyper = go.GetComponent <OrbitHyper>();

        if (hyper == null)
        {
            Debug.LogError("Failed to get OrbitHyper from prefab:" + go.name);
            return;
        }
        // Awkward test code
        if (parent == star)
        {
            hyper.perihelion = Random.Range(minRadius, maxRadius);
            // aribitrary - start at fixed distance from peri
            hyper.r_initial    = 1.0f * hyper.perihelion;
            hyper.inclination  = Random.Range(-80f, 80f);
            hyper.ecc          = Random.Range(1.1f, 2f);
            hyper.centerObject = parent;
        }
        hyper.SetNBody(nbody);
        hyper.Init();
        OrbitPredictor op = go.GetComponentInChildren <OrbitPredictor>();

        if (op != null)
        {
            op.SetNBody(nbody);
            op.SetCenterObject(parent);
        }
    }
 /// <summary>
 /// Do hand off from one center to a new center in the OrbitUniversal class.
 /// </summary>
 /// <param name="newObject"></param>
 /// <param name="oldObject"></param>
 public void OnNewInfluencer(NBody newObject, NBody oldObject)
 {
     if (keplerSeq != null)
     {
         orbitU = keplerSeq.GetCurrentOrbit();
     }
     orbitU.SetNewCenter(newObject);
     if (orbitPredictor != null)
     {
         orbitPredictor.SetCenterObject(newObject.gameObject);
     }
 }
    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);
    }
示例#4
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);
        }
    }
 /// <summary>
 /// Callback for when ship enters the moons SOI. Change the center object of the moon orbit predictor
 /// to be the moon.
 /// </summary>
 /// <param name="orbitU"></param>
 public void EnterMoonSoi(OrbitUniversal orbitU)
 {
     shipOrbitPredictor.SetCenterObject(moonBody.gameObject);
     shipOrbitPredictor.hyperDisplayRadius = soiRadius;
 }
 /// <summary>
 /// Callback for when ship enters the moons SOI. Change the center object of the moon orbit predictor
 /// to be the moon.
 /// </summary>
 /// <param name="orbitU"></param>
 public void EnterMoonSoi(OrbitUniversal orbitU)
 {
     Debug.Log("Enter SOI");
     toMoonOrbit.SetCenterObject(moonBody.gameObject);
 }