コード例 #1
0
    public static Exoplanet[] LoadExoplanets()
    {
        Dictionary <string, int> labels;

        TextAsset planetDatabase = (TextAsset)Resources.Load("exoplanets");

        string[] lines           = planetDatabase.text.Split('\n');
        int      numberOfPlanets = lines.Length - 1;

        Debug.Log("Parsing " + numberOfPlanets + " planets...");
        Exoplanet[] exoplanets = new Exoplanet[numberOfPlanets];

        // The first line has captions about the data...
        labels = ParseLabels(lines[0]);

        int currentPlanet = 0;

        for (int lineIndex = 1; lineIndex < lines.Length - 1; lineIndex++) // skip first line that contains headers
        {
            exoplanets[currentPlanet++] = ParseExoplanet(labels, lines[lineIndex]);

            if (currentPlanet > exoplanets.Length)
            {
                break;
            }
        }
        Debug.Log(currentPlanet + " planets parsed!");
        Array.Resize(ref exoplanets, currentPlanet);

        return(exoplanets);
    }
コード例 #2
0
    static System.Collections.Generic.List <Exoplanet> GetOurPlanets()
    {
        System.Collections.Generic.List <Exoplanet> planets = new System.Collections.Generic.List <Exoplanet>();

        Exoplanet merkurius = new Exoplanet();
        Exoplanet venus     = new Exoplanet();
        Exoplanet earth     = new Exoplanet();
        Exoplanet mars      = new Exoplanet();
        Exoplanet jupiter   = new Exoplanet();
        Exoplanet saturnus  = new Exoplanet();
        Exoplanet uranus    = new Exoplanet();
        Exoplanet neptunus  = new Exoplanet();

        merkurius.PlanetaryRadius = 0.03413f;
        venus.PlanetaryRadius     = 0.084639f;
        earth.PlanetaryRadius     = 0.089213f;
        mars.PlanetaryRadius      = 0.047516f;
        jupiter.PlanetaryRadius   = 1f;
        saturnus.PlanetaryRadius  = 0.843003f;
        uranus.PlanetaryRadius    = 0.357509f;
        neptunus.PlanetaryRadius  = 0.346388f;

        merkurius.SemiMajorAxis = 0.387098f;
        venus.SemiMajorAxis     = 0.723327f;
        earth.SemiMajorAxis     = 1f;
        mars.SemiMajorAxis      = 1.523679f;
        jupiter.SemiMajorAxis   = 5.204267f;
        saturnus.SemiMajorAxis  = 9.58201720f;
        uranus.SemiMajorAxis    = 19.22941195f;
        neptunus.SemiMajorAxis  = 30f;

        merkurius.OrbitalPeriod = 39.264f;
        venus.OrbitalPeriod     = 224.7f;
        earth.OrbitalPeriod     = 365.2422f;
        mars.OrbitalPeriod      = 686.98f;
        jupiter.OrbitalPeriod   = 4331.77f;
        saturnus.OrbitalPeriod  = 10760f;
        uranus.OrbitalPeriod    = 30684f;
        neptunus.OrbitalPeriod  = 60188.3f;

        planets.Add(merkurius);
        planets.Add(venus);
        planets.Add(earth);
        planets.Add(mars);
        planets.Add(jupiter);
        planets.Add(saturnus);
        planets.Add(uranus);
        planets.Add(neptunus);

        return(planets);
    }
コード例 #3
0
    private static Exoplanet ParseExoplanet(Dictionary <string, int> labels, string data)
    {
        Exoplanet exoplanet = new Exoplanet();

        exoplanet.SystemName          = ParseString(data, labels["STAR"]);
        exoplanet.PlanetName          = ParseString(data, labels["NAME"]);
        exoplanet.SemiMajorAxis       = ParseFloat(data, labels["A"]);
        exoplanet.OrbitalEccentricity = ParseFloat(data, labels["ECC"]);
        exoplanet.OrbitalPeriod       = ParseFloat(data, labels["PER"]);
        exoplanet.PlanetaryRadius     = ParseFloat(data, labels["R"]);
        exoplanet.StarRadius          = ParseFloat(data, labels["RSTAR"]);
        exoplanet.Inclination         = ParseFloat(data, labels["I"]);



        return(exoplanet);
    }
コード例 #4
0
    public void CreatePlanets(System.Collections.Generic.List <Exoplanet> planets)
    {
        Universe universe = Object.FindObjectOfType(typeof(Universe)) as Universe;

        _PlanetOrbits = new GameObject[planets.Count];
        _PlanetData   = planets.ToArray();
        _Planets      = new Transform[planets.Count];
        for (int i = 0; i < planets.Count; i++)
        {
            Exoplanet    planet       = planets[i];
            GameObject   planetParent = new GameObject("planetParent");
            GameObject   go           = new GameObject("planet");
            MeshFilter   meshFilter   = go.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>();
            Mesh         mesh         = GenerateMesh(Color.white);
            meshFilter.sharedMesh       = mesh;
            meshRenderer.sharedMaterial = universe.PlanetMaterial;


            planetParent.transform.parent        = transform;
            planetParent.transform.localPosition = Vector3.zero;
            go.transform.parent = planetParent.transform;

            float inclination = _PlanetData[i].Inclination;
            if (inclination == 0)
            {
                inclination = Random.Range(80, 100);
            }
            planetParent.transform.localRotation = Quaternion.Euler(0, inclination, 0);
            go.transform.localPosition           = new Vector3(planet.SemiMajorAxis, 0, 0);
            if (planet.PlanetaryRadius == 0)
            {
                go.transform.localScale = Vector3.one * 0.1f;
            }
            else
            {
                go.transform.localScale = Vector3.one * 0.1f * planet.PlanetaryRadius;
            }

            _Planets[i]      = go.transform;
            _PlanetOrbits[i] = Orbit.CreateOrbitObject(Vector3.zero, planet.SemiMajorAxis, planet.SemiMajorAxis, 0, inclination, planet.OrbitalEccentricity, universe.AsteroidMaterial);
            _PlanetOrbits[i].transform.parent = this.transform;
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        _Rotation += Time.deltaTime;
        Quaternion rot = Quaternion.Euler(_Rotation * RotationSpeed, 0f, 0f);
        Matrix4x4  m   = Matrix4x4.TRS(Vector3.zero, rot, new Vector3(1, 1, 1));

        Material material = GetComponent <MeshRenderer>().sharedMaterial;

        material.SetMatrix("_Rotation", m);
        material.SetFloat("_Blend", Scale);

        _DelayTimer += Time.deltaTime;
        if (_DelayTimer > _Delay)
        {
            Scale += Time.deltaTime * _ScaleSpeed;
        }

        if (Scale > 1)
        {
            Scale = 1;
        }

        transform.localScale = Vector3.one * Scale;

        // Updat1e Orbit
        if (_Planets != null && _Planets.Length > 0)
        {
            for (int i = 0; i < _Planets.Length; i++)
            {
                Transform planet     = _Planets[i];
                Exoplanet planetData = _PlanetData[i];

                float semiMinorAxis = Mathf.Sqrt(-(Mathf.Pow(planetData.OrbitalEccentricity, 2) * Mathf.Pow(planetData.SemiMajorAxis, 2) - Mathf.Pow(planetData.SemiMajorAxis, 2)));

                float   angle    = (Time.time * 356 / planetData.OrbitalPeriod) * Mathf.PI * 2;
                Vector3 position = new Vector3(Mathf.Cos(angle) * planetData.SemiMajorAxis, Mathf.Sin(angle) * semiMinorAxis, 0);
                planet.localPosition = position;
            }
        }

        transform.position = OriginalPos * Scaler.Scale;
    }
コード例 #6
0
    IEnumerator GetStars()
    {
        UnityWebRequest www = UnityWebRequest.Get("https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=pl_hostname,st_rad,st_teff,ra,dec,st_dist&order=pl_disc&format=json");

        yield return(www.SendWebRequest());

        if (www.isDone)
        {
            if (www.isNetworkError)
            {
                Debug.Log("Network Error: " + www.error);
            }

            if (www.isHttpError)
            {
                Debug.Log("HTTP Error: " + www.error);
            }
            else
            {
                Debug.Log("download size: " + www.downloadHandler.data.Length);

                celestialData = JsonUtility.FromJson <Observed>("{\"rawData\":" + www.downloadHandler.text + "}");
                var rawData = new List <RawData>(celestialData.rawData);
                Debug.Log("Total number of planets: " + rawData.Count);

                foreach (RawData r in rawData)
                {
                    Exoplanet ep = new Exoplanet();
                    ep.name         = r.pl_name;
                    ep.inclination  = r.pl_orbincl;
                    ep.period       = r.pl_orbper;
                    ep.eccentricity = r.pl_orbseccen;
                    ep.smAxis       = r.pl_orbsmax;

                    if (Systems.stars.FindIndex(star => star.name == r.pl_hostname) < 0)
                    {
                        Star s = new Star();
                        s.name        = r.pl_hostname;
                        s.distance    = r.st_dist;
                        s.temperature = r.st_teff;

                        if (r.st_rad > 0)
                        {
                            var log = Mathf.Log(r.st_rad, 10);
                            s.size = log >= 0.5f ? log : 0.5f;
                        }
                        else
                        {
                            s.size = 1;
                        }

                        float x = Mathf.Cos(r.ra) * Mathf.Cos(r.dec);
                        float y = Mathf.Sin(r.ra) * Mathf.Cos(r.dec);
                        float z = Mathf.Sin(r.dec);

                        s.startingPosition = new Vector3(x, y, z);
                        if (s.distance > 0)
                        {
                            s.location = Mathf.Log(s.distance, 10) * s.startingPosition;
                        }
                        else
                        {
                            s.location = s.startingPosition;
                        }
                        s.planets = new List <Exoplanet>();
                        Systems.stars.Add(s);
                    }
                    Systems.stars.Find(star => star.name == r.pl_hostname).planets.Add(ep);
                }
                Debug.Log("Total number of stars: " + Systems.stars.Count);
            }
        }
    }
コード例 #7
0
    public static void Load(Star[] stars)
    {
        Exoplanet[] exoplanets = LoadExoplanets();
        Dictionary <int, List <int> > planetsByHDID  = new Dictionary <int, List <int> >();
        Dictionary <int, List <int> > planetsByHiPID = new Dictionary <int, List <int> >();
        Dictionary <int, List <int> > planetsByHDR   = new Dictionary <int, List <int> >();

        for (int i = 0; i < exoplanets.Length; i++)
        {
            Exoplanet exoplanet = exoplanets[i];
            if (exoplanet.SystemName.StartsWith("HD"))
            {
                string id = exoplanet.SystemName.Substring(3);

                // remove extra chars after hdID like 'A' and 'B'
                int spaceingIndex = id.IndexOf(' ');
                if (spaceingIndex > 0)
                {
                    id = id.Remove(spaceingIndex);
                }

                int hdID;
                if (int.TryParse(id, out hdID) == false)
                {
                    UnityEngine.Debug.Log("failed to parse hdID: " + id);
                    continue;
                }

                if (!planetsByHDID.ContainsKey(hdID))
                {
                    planetsByHDID[hdID] = new List <int>();
                }
                planetsByHDID[hdID].Add(i);
            }
            else if (exoplanet.SystemName.StartsWith("HIP"))
            {
                string id = exoplanet.SystemName.Substring(4);
                int    hipID;
                if (int.TryParse(id, out hipID) == false)
                {
                    UnityEngine.Debug.Log("failed to parse hipID: " + id);
                    continue;
                }

                if (!planetsByHiPID.ContainsKey(hipID))
                {
                    planetsByHiPID[hipID] = new List <int>();
                }
                planetsByHiPID[hipID].Add(i);
            }
            else if (exoplanet.SystemName.StartsWith("HR"))
            {
                string id = exoplanet.SystemName.Substring(3);
                int    hrID;
                if (int.TryParse(id, out hrID) == false)
                {
                    UnityEngine.Debug.Log("failed to parse hrID: " + id);
                    continue;
                }

                if (!planetsByHDR.ContainsKey(hrID))
                {
                    planetsByHDR[hrID] = new List <int>();
                }
                planetsByHDR[hrID].Add(i);
            }
        }

        UnityEngine.Debug.Log("planetsByHDID: " + planetsByHDID.Count);
        UnityEngine.Debug.Log("planetsByHiPID: " + planetsByHiPID.Count);
        UnityEngine.Debug.Log("planetsByHDR: " + planetsByHDR.Count);

        int planetsWithStars = 0;

        Dictionary <int, List <Exoplanet> > starMap = new Dictionary <int, List <Exoplanet> >();

        foreach (Star star in stars)
        {
            if (star.HD != 0)
            {
                List <int> planets;
                if (planetsByHiPID.TryGetValue(star.HD, out planets))
                {
                    foreach (int planetID in planets)
                    {
                        star.Planets.Add(exoplanets[planetID]);
                        planetsWithStars++;
                    }
                }
            }
            if (star.HIP != 0)
            {
                List <int> planets;
                if (planetsByHDID.TryGetValue(star.HIP, out planets))
                {
                    foreach (int planetID in planets)
                    {
                        star.Planets.Add(exoplanets[planetID]);
                        planetsWithStars++;
                    }
                }
            }
            if (star.HR != 0)
            {
                List <int> planets;
                if (planetsByHDR.TryGetValue(star.HR, out planets))
                {
                    foreach (int planetID in planets)
                    {
                        star.Planets.Add(exoplanets[planetID]);
                        planetsWithStars++;
                    }
                }
            }
        }

        UnityEngine.Debug.Log("planets with stars: " + planetsWithStars);
    }
コード例 #8
0
    void LateUpdate()
    {
        Vector3 camPos = Camera.mainCamera.transform.position;

        _DataList.Clear();
        if (guiManager.ShowPlanets())
        {
            foreach (Star star in StarPicker.Stars)
            {
                List <Exoplanet> planets = star.Planets;

                if (guiManager.ShowOnlyWithPlanets() && star.Planets.Count == 0)
                {
                    continue;
                }

                Vector3 starPos    = new Vector3(star.X, star.Y, star.Z) * Scaler.Scale;
                float   distance3D = Vector3.SqrMagnitude(camPos - starPos);

                float planetFilter = guiManager.GetPlanetFilter();
                if (guiManager.ShowOnlyWithPlanets())
                {
                    planetFilter *= 10;
                }

                if (distance3D < planetFilter * planetFilter * Scaler.Scale)
                {
                    Bounds bounds = new Bounds(starPos, Vector3.one);
                    if (GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(Camera.main), bounds) == false)
                    {
                        continue;
                    }

                    Vector3 screenPos3D = Camera.mainCamera.WorldToScreenPoint(starPos);
                    screenPos3D.y = Screen.height - screenPos3D.y;

                    if (screenPos3D.z < 0)
                    {
                        continue;
                    }

                    float   distance  = Vector3.Distance(starPos, camPos);
                    Vector2 screenPos = new Vector2(screenPos3D.x, screenPos3D.y);

                    NameData newData = new NameData();
                    newData.ScreenPos = screenPos;
                    newData.Star      = star;
                    newData.Distance  = distance;
                    _DataList.Add(newData);
                }
            }
        }

        _PlanetDataList.Clear();
        if (PickedStar != null && PickedStar.Planets.Count > 0)
        {
            for (int i = 0; i < Sun.Instance._Planets.Length; i++)
            {
                Transform planetTransform = Sun.Instance._Planets[i];
                Exoplanet planet          = PickedStar.Planets[i];

                Vector3 planetPos  = planetTransform.position;
                float   distance3D = Vector3.SqrMagnitude(camPos - planetPos);

                //if (distance3D < guiManager.GetPlanetFilter() * guiManager.GetPlanetFilter() * Scaler.Scale)
                {
                    Bounds bounds = new Bounds(planetPos, Vector3.one);
                    if (GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(Camera.main), bounds) == false)
                    {
                        continue;
                    }

                    Vector3 screenPos3D = Camera.mainCamera.WorldToScreenPoint(planetPos);
                    screenPos3D.y = Screen.height - screenPos3D.y;

                    if (screenPos3D.z < 0)
                    {
                        continue;
                    }

                    float   distance  = Vector3.Distance(planetPos, camPos);
                    Vector2 screenPos = new Vector2(screenPos3D.x, screenPos3D.y);

                    PlanetNameData newData = new PlanetNameData();
                    newData.ScreenPos = screenPos;
                    newData.Planet    = planet;
                    newData.Distance  = distance;
                    _PlanetDataList.Add(newData);
                }
            }
        }
    }