示例#1
0
    // Use this for initialization
    void Start()
    {
        nbody = body.GetComponent <NBody>();
        if (nbody == null)
        {
            Debug.LogWarning("Cannot show orbit - Body requires NBody component");
            return;
        }
        aroundNBody = centerBody.GetComponent <NBody>();
        if (aroundNBody == null)
        {
            Debug.LogWarning("Cannot show orbit - centerBody requires NBody component");
            return;
        }
        initOk             = true;
        lineR              = GetComponent <LineRenderer>();
        lineR.numPositions = numPoints;
        orbitData          = new OrbitData();

        ellipseBase = transform.gameObject.AddComponent <EllipseBase>();
        ellipseBase.centerObject = centerBody;

        orbitHyper = transform.gameObject.AddComponent <OrbitHyper>();
        orbitHyper.centerObject = centerBody;
    }
示例#2
0
 private void showInputForm(Dataweb.NShape.Shape inShape)
 {
     if ((inShape != null) && (inShape.Template.Name == "Input" || inShape.Template.Name == "Operate"))
     {
         ModelInPutForm mpForm = new ModelInPutForm();
         mpForm.StartPosition = FormStartPosition.CenterParent;
         mpForm.Initial(inShape.Data, true);
         mpForm.ShowDialog();
         if (mpForm.DialogResult == DialogResult.OK)
         {
             string label = string.Empty;
             inShape.Data = mpForm.GetInfo(ref label);
             if (inShape.Template.Name == "Input")
             {
                 EllipseBase eb = (EllipseBase)inShape;
                 eb.SetCaptionText(0, label);
             }
             if (inShape.Template.Name == "Operate")
             {
                 DiamondBase db = (DiamondBase)inShape;
                 db.SetCaptionText(0, label);
             }
             display1.Refresh();
         }
     }
 }
示例#3
0
    void Start()
    {
        // calculate positions for the LineRenderer (cannot assume Editor script has been invoked to do this)
        GameObject parent = transform.parent.gameObject;

        if (parent != null)
        {
            EllipseBase ellipseBase = parent.GetComponent <EllipseBase>();
            if (ellipseBase != null)
            {
                orbitP = ellipseBase;
            }
            else
            {
                OrbitHyper orbitHyper = parent.GetComponent <OrbitHyper>();
                if (orbitHyper != null)
                {
                    orbitP = orbitHyper;
                }
                else
                {
                    Debug.LogWarning("Parent object must have OrbitEllipse or OrbitHyper - cannot compute positions for line");
                }
            }
        }
        else
        {
            Debug.LogWarning("No parent object - cannot compute positions for line");
        }
        lineR = GetComponent <LineRenderer>();
        lineR.positionCount = numPoints;
    }
示例#4
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);
	}
示例#5
0
    public static void SetEllipse(float epoch, EllipseBase ellipseBase, SolarBody sb)
    {
        // orbital element variation is not provided - only phase to determine
        // What is the delta to the reference epoch?
        float deltaYears = epoch - sb.epoch;
        float period     = SolarUtils.GetPeriodYears(sb);
        float numPeriod  = deltaYears / period;

        // epoch was for time at perihelion (i.e. longitude = 0)
        // w = w_bar - Omega,
        ellipseBase.phase = OrbitEllipse.MeanToTrueAnomoly(NUtils.DegressMod360(360f * numPeriod), ellipseBase.ecc);
//		Debug.Log(" numP=" + numPeriod + " M=" + NUtils.DegressMod360(360f*numPeriod) +
//			 " phase=" + ellipseBase.phase);
    }
示例#6
0
    private List <EllipseBase> EllipsesInSystem()
    {
        List <EllipseBase> ellipses = new List <EllipseBase>();

        NBody[] nbodies = GetComponentsInChildren <NBody>();
        foreach (NBody nbody in nbodies)
        {
            EllipseBase ellipseBase = nbody.transform.gameObject.GetComponent <EllipseBase>();
            if (ellipseBase != null)
            {
                ellipses.Add(ellipseBase);
            }
        }
        return(ellipses);
    }
示例#7
0
 private void showOutputForm(Dataweb.NShape.Shape outShape)
 {
     if ((outShape != null) && (outShape.Template.Name == "Output"))
     {
         ModelOutPutForm moform = new ModelOutPutForm();
         moform.StartPosition = FormStartPosition.CenterParent;
         moform.ShowDialog();
         if (moform.DialogResult == DialogResult.OK)
         {
             string      label = moform.result;
             EllipseBase eb    = (EllipseBase)outShape;
             eb.SetCaptionText(0, label);
             display1.Refresh();
         }
     }
 }
示例#8
0
    /// <summary>
    /// Sets the ellipse parameters for epoch provided.
    /// </summary>
    /// <param name="epoch">Epoch.</param>
    /// <param name="ellipseBase">Ellipse base.</param>
    public void SetEllipseForEpoch(float epoch, EllipseBase ellipseBase)
    {
        switch (bodyType)
        {
        case SolarSystem.Type.PLANET:
            PlanetData.SetEllipse(epoch, ellipseBase, this);
            break;

        case SolarSystem.Type.ASTEROID:
            AsteroidData.SetEllipse(epoch, ellipseBase, this);
            break;

        case SolarSystem.Type.COMET:
            CometData.SetEllipse(epoch, ellipseBase, this);
            break;
        }
    }
示例#9
0
    /// <summary>
    /// Calculates the Hill Radius (radius at which the secondary's gravity becomes dominant, when the
    /// secondary is in orbit around the primary).
    /// </summary>
    /// <returns>The radius.</returns>
    /// <param name="primary">Primary.</param>
    /// <param name="secondary">Secondary. In orbit around primary</param>
    static public float HillRadius(GameObject primary, GameObject secondary)
    {
        NBody       primaryBody   = primary.GetComponent <NBody>();
        NBody       secondaryBody = secondary.GetComponent <NBody>();
        EllipseBase orbit         = secondary.GetComponent <EllipseBase>();

        if ((primaryBody == null) || (secondaryBody == null) || (orbit == null))
        {
            return(0);
        }
        float denom = 3f * (secondaryBody.mass + primaryBody.mass);

        if (Mathf.Abs(denom) < 1E-6)
        {
            return(0);
        }
        return(Mathf.Pow(secondaryBody.mass / denom, 1 / 3f) * orbit.a_scaled * (1 - orbit.ecc));
    }
示例#10
0
    /// <summary>
    /// Sets the ellipse parameters for planet.
    /// </summary>
    /// <param name="epoch">Epoch.</param>
    /// <param name="ellipseBase">Ellipse base.</param>
    public static void SetEllipse(float epoch, EllipseBase ellipseBase, SolarBody sb)
    {
        // Based on JPL data, apply the per century drift to the orbital parameters
        // T = number of centuries past J2000
        float T = (epoch - 2000f) / 100f;

        ellipseBase.a           = sb.a + sb.a_dot * T;
        ellipseBase.ecc         = sb.ecc + sb.ecc_dot * T;
        ellipseBase.inclination = sb.inclination + sb.inclination_dot * T;
        ellipseBase.omega_uc    = NUtils.DegreesMod360(sb.omega_uc + sb.omega_uc_dot * T);
        // following JPL doc (http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf)
        float current_omega_bar = sb.omega_lc_bar + sb.omega_lc_bar_dot * T;

        ellipseBase.omega_lc = NUtils.DegreesMod360(current_omega_bar - ellipseBase.omega_uc);
        float L            = sb.longitude + sb.longitudeDot * T;
        float mean_anomoly = NUtils.DegreesMod360(L - current_omega_bar);

        ellipseBase.phase = mean_anomoly;
    }
示例#11
0
 private void SetPhase(EllipseBase ellipseBase, SolarBody sbody)
 {
     sbody.SetEllipseForEpoch(_epochTime, ellipseBase);
 }
示例#12
0
    public override void OnInspectorGUI()
    {
        GUI.changed = false;
        EllipseBase ellipseBase = (EllipseBase)target;
        // fields in class
        GameObject centerObject = null;

        EllipseBase.ParamBy paramBy = EllipseBase.ParamBy.AXIS_A;
        float ecc         = 0;
        float a           = 0;
        float p           = 0;
        float omega_uc    = 0;
        float omega_lc    = 0;
        float inclination = 0;
        float phase       = 0;

        if (!(target is BinaryPair))
        {
            centerObject = (GameObject)EditorGUILayout.ObjectField(
                new GUIContent("CenterObject", centerTip),
                ellipseBase.centerObject,
                typeof(GameObject),
                true);
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Ellipse Parameters", EditorStyles.boldLabel);

        // If there is a SolarBody, it is the one place data can be changed. The EB holds the
        // orbit scaled per SolarSystem scale.
        SolarBody sbody = ellipseBase.GetComponent <SolarBody>();

        if (sbody != null)
        {
            EditorGUILayout.LabelField("\tEllipse parameters controlled by SolarBody settings.");
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Semi-Major Axis", "a", ellipseBase.a), EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Eccentricity", "e", ellipseBase.ecc), EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Incliniation", "i", ellipseBase.inclination), EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Arg. of pericenter", "\u03c9", ellipseBase.omega_lc), EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Longitude of node", "\u03a9", ellipseBase.omega_uc), EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                     "Phase", "M", ellipseBase.phase), EditorStyles.wordWrappedLabel);
            return;
        }

        paramBy =
            (EllipseBase.ParamBy)EditorGUILayout.EnumPopup(new GUIContent("Parameter Choice", paramTip), ellipseBase.paramBy);

        ecc = EditorGUILayout.Slider(new GUIContent("Eccentricity", eTip), ellipseBase.ecc, 0f, 0.99f);


        axisUpdated = false;
        // backwards compatibility when loading scenes before unit scaling:
        if (ellipseBase.a_scaled < 0)
        {
            axisUpdated = true;
        }
        GravityScaler.Units units = GravityEngine.Instance().units;
        if (ellipseBase.paramBy == EllipseBase.ParamBy.AXIS_A)
        {
            float oldLabelWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = oldLabelWidth + 30f;
            string prompt = string.Format("Semi-Major Axis (a) [{0}]", GravityScaler.LengthUnits(units));
            a = EditorGUILayout.DelayedFloatField(new GUIContent(prompt, aTip), ellipseBase.a);
            if (a != ellipseBase.a)
            {
                axisUpdated = true;
            }
            EditorGUILayout.LabelField("Scaled a (Unity units):   " + ellipseBase.a_scaled);
            EditorGUIUtility.labelWidth = oldLabelWidth;
            p = a * (1 - ecc);
        }
        else
        {
            string prompt = string.Format("Pericenter [{0}]", GravityScaler.LengthUnits(units));
            p = EditorGUILayout.DelayedFloatField(new GUIContent(prompt, pTip), ellipseBase.p);
            if (p != ellipseBase.p)
            {
                axisUpdated = true;
            }
            EditorGUILayout.LabelField("Scaled p (Unity units) " + ellipseBase.p_scaled);
            a = p / (1 - ecc);
        }
        // implementation uses AngleAxis, so degrees are more natural
        omega_uc    = EditorGUILayout.Slider(new GUIContent("\u03a9 (Longitude of AN)", omega_ucTip), ellipseBase.omega_uc, 0, 360f);
        omega_lc    = EditorGUILayout.Slider(new GUIContent("\u03c9 (AN to Pericenter)", omega_lcTip), ellipseBase.omega_lc, 0, 360f);
        inclination = EditorGUILayout.Slider(new GUIContent("Inclination", inclinationTip), ellipseBase.inclination, 0f, 180f);
        // physics uses radians - but ask user for degrees to be consistent
        phase = EditorGUILayout.Slider(new GUIContent("Starting Phase", phaseTip), ellipseBase.phase, 0, 360f);

        // Checking the Event type lets us update after Undo and Redo commands.
        // A redo updates _lengthScale but does not run the setter
//        if (Event.current.type == EventType.ExecuteCommand &&
//            Event.current.commandName == "UndoRedoPerformed") {
//			ellipseBase.ApplyScale(GravityEngine.Instance().GetLengthScale());
//        }

        if (GUI.changed)
        {
            Undo.RecordObject(ellipseBase, "EllipseBase Change");
            ellipseBase.a            = a;
            ellipseBase.p            = p;
            ellipseBase.ecc          = ecc;
            ellipseBase.centerObject = centerObject;
            ellipseBase.omega_lc     = omega_lc;
            ellipseBase.omega_uc     = omega_uc;
            ellipseBase.inclination  = inclination;
            ellipseBase.phase        = phase;
            ellipseBase.paramBy      = paramBy;
            EditorUtility.SetDirty(ellipseBase);
        }
    }