Exemplo n.º 1
0
    public static void Plot_Star_Cluster(StarContainer stars, ParticleSystem particle,
                                         double latitude, double longitude, DateTime dt, bool plot_xyz)
    {
        double dayOffset = (dt - new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)).TotalDays;
        double LST       = (100.46 + 0.985647 * dayOffset + longitude + 15 * (dt.Hour + dt.Minute / 60d) + 360) % 360;

        int star_length = stars.Stars.Count;

        particle.Clear();
        for (int i = 0; i < star_length; i++)
        {
            particle.Emit(1);
        }
        ParticleSystem.Particle[] arrParts;
        arrParts = new ParticleSystem.Particle[star_length];
        particle.GetParticles(arrParts);
        for (int i = 0; i < star_length; i++)
        {
            ParticleSystem.Particle par = arrParts[i];


            Star s = stars.Stars[i];

            double x;
            double y;
            double z;

            //Plot based on XYZ or RA/DEC
            if (!plot_xyz)
            {
                double HA = (LST - s.Ra + 360) % 360;
                x = Math.Cos(HA * (Math.PI / 180)) * Math.Cos(s.Dec * (Math.PI / 180));
                y = Math.Sin(HA * (Math.PI / 180)) * Math.Cos(s.Dec * (Math.PI / 180));
                z = Math.Sin(s.Dec * (Math.PI / 180));
            }
            else
            {
                x = s.X;
                y = s.Y;
                z = s.Z;
            }


            Vector3 orig_vec = new Vector3((float)x, (float)z, (float)y);
            Vector3 norm     = orig_vec.normalized * Camera.main.farClipPlane * 0.98f;

            par.startColor = Color.white * (1.0f - (s.Mag + 1.40f) / 8) * 2;
            par.startSize  = 8;
            par.position   = norm;
            arrParts[i]    = par;
        }
        particle.SetParticles(arrParts, star_length);
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        StarContainer s = StarPlotter.Create_Star_Cluster(star_Data);

        StarPlotter.Plot_Star_Cluster(s, particleSys, ROCHESTER_LAT, ROCHESTER_LONG, dt, true);
    }
    private void Plot_Stars(StarContainer s)
    {
        //Create particles
        for (int i = 0; i < s.starLength(); i++)
        {
            partSystem.Emit(1);
        }

        //Get particles to place.
        ParticleSystem.Particle[] arrParts;
        arrParts = new ParticleSystem.Particle[s.starLength()];
        partSystem.GetParticles(arrParts);

        //Get values
        for (int i = 0; i < s.starLength(); i++)
        {
            //Get the particle system.
            ParticleSystem.Particle par = arrParts[i];

            //Get the star.
            Star star = s.GetStar(i);

            //Set the position to be the position times the scalar.
            par.position = new Vector3(
                star.x * s.scaleVal,
                star.y * s.scaleVal,
                star.z * s.scaleVal
                );

            //If color accurate is true then set true color.
            if (s.isTrueColor())
            {
                if (is_b_minus_v_value)
                {
                    ColorIndex c = B_Minus_V_Calc(star.b_minus_v);
                    par.startColor = new Color((float)c.r, (float)c.g, (float)c.b);
                }
                else
                {
                    ColorIndex c = s.GetColor(i);
                    if (c != null)
                    {
                        float r = scale_one_through_zero_value((float)c.r, s.max_r_val, 1.0f);
                        float g = scale_one_through_zero_value((float)c.g, s.max_g_val, 1.0f);
                        float b = scale_one_through_zero_value((float)c.b, s.max_b_val, 1.0f);
                        par.startColor = new Color(r, g, b);
                    }
                    else
                    {
                        par.startColor = Color.white;
                    }
                }
            }


            float par_size = scale_one_through_zero_value((float)star.radius, s.max_radius, 5.0f);
            par.startSize = par_size + 0.1f;
            arrParts [i]  = par;
        }
        partSystem.SetParticles(arrParts, s.starLength());
    }
    /// <summary>
    /// Start function reads in the csv files and then subsequently creates the stars.
    /// </summary>
    void Start()
    {
        StarContainer s = Generic_Parser.Create_Star_Cluster(file, MOD_VAL, pScalar);

        Plot_Stars(s);
    }
Exemplo n.º 5
0
    public static StarContainer Create_Star_Cluster(TextAsset file)
    {
        string[] lines = file.text.Split('\n');

        StarContainer sc = new StarContainer();

        int ra_index  = -1;
        int dec_index = -1;
        int mag_index = -1;
        int x_index   = -1;
        int y_index   = -1;
        int z_index   = -1;

        int count = 0;

        bool first_val = true;

        foreach (string line in lines)
        {
            string[] line_parts = line.Split(',');
            if (first_val)
            {
                for (int i = 0; i < line_parts.Length; i++)
                {
                    if (line_parts[i].ToLower().Equals(RA))
                    {
                        ra_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(DEC))
                    {
                        dec_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(MAG))
                    {
                        mag_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(X))
                    {
                        x_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(Y))
                    {
                        y_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(Z))
                    {
                        z_index = i;
                    }
                }
                first_val = false;
            }
            else
            {
                try{
                    float ra_val = float.Parse(line_parts[ra_index]);
                    ra_val = Scale_One_Through_Zero_Value(ra_val, 24f, 360f);
                    float dec_val = float.Parse(line_parts[dec_index]);
                    float mag     = float.Parse(line_parts[mag_index]);
                    float x       = float.Parse(line_parts[x_index]);
                    float y       = float.Parse(line_parts[y_index]);
                    float z       = float.Parse(line_parts[z_index]);
                    if (x != 0 && y != 0 && z != 0)
                    {
                        Star s = new Star(ra_val, dec_val, mag, x, y, z);
                        sc.AddStar(s);
                    }
                } catch (IndexOutOfRangeException) {
                    count += 1;
                }
            }
        }
        Debug.Log(count + " stars without adequate data");
        return(sc);
    }
    public static StarContainer Create_Star_Cluster(TextAsset file, int mod_val, float scale_val)
    {
        StarContainer s = new StarContainer(mod_val, scale_val);

        string[] lines = file.text.Split('\n');

        //X, Y, Z coordinates for plotting
        int x_index = -1;
        int y_index = -1;
        int z_index = -1;

        //RGB values for display.
        int r_index = -1;
        int g_index = -1;
        int b_index = -1;

        //Radius of the star
        int radius_index = -1;

        //B-V value
        int b_minx_v_index = -1;

        //If rgb values are found
        bool rgb_found = false;

        int count = 0;

        //int total_rgb_vals = 0;

        float max_r_val = 0;
        float max_g_val = 0;
        float max_b_val = 0;

        float max_radius = 0;

        float max_b_minus_v = 0;

        bool first_val = true;

        foreach (string line in lines)
        {
            if (first_val)
            {
                string[] line_parts = line.Split(',');
                for (int i = 0; i < line_parts.Length; i++)
                {
                    line_parts[i] = line_parts[i].Trim();
                    if (line_parts[i].ToLower().Equals(X_COL))
                    {
                        x_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(Y_COL))
                    {
                        y_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(Z_COL))
                    {
                        z_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(R_COL))
                    {
                        r_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(G_COL))
                    {
                        g_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(B_COL))
                    {
                        b_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(B_MINUS_V))
                    {
                        b_minx_v_index = i;
                    }
                    if (line_parts[i].ToLower().Equals(RADIUS))
                    {
                        radius_index = i;
                    }
                }
                first_val = false;
            }
            else
            {
                string[] line_parts = line.Split(',');
                if (line_parts.Length != 1 && count % mod_val == 0)
                {
                    ColorIndex ci      = null;
                    float      b_minus = 4.0f;
                    //If color found then populate it.
                    if (rgb_found)
                    {
                        try{
                            ci = new ColorIndex(float.Parse(line_parts[r_index]),
                                                float.Parse(line_parts[g_index]),
                                                float.Parse(line_parts[b_index]));

                            Debug.Log(line_parts[r_index]);
                            if (float.Parse(line_parts[r_index]) > max_r_val)
                            {
                                max_r_val = float.Parse(line_parts[r_index]);
                            }
                            if (float.Parse(line_parts[g_index]) > max_g_val)
                            {
                                max_g_val = float.Parse(line_parts[g_index]);
                            }
                            if (float.Parse(line_parts[b_index]) > max_b_val)
                            {
                                max_b_val = float.Parse(line_parts[b_index]);
                            }
                        }catch {
                            ci = new ColorIndex(15.0f, 15.0f, 15.0f);
                        }
                        try{
                            b_minus = float.Parse(line_parts[b_minx_v_index]);
                            if (b_minus > max_b_minus_v)
                            {
                                max_b_minus_v = b_minus;
                            }
                        }catch {
                            b_minus = 4.0f;
                        }
                    }

                    //Populate star container with a new star. (y,z are flipped for unity.)
                    s.addStar(float.Parse(line_parts[x_index]),
                              float.Parse(line_parts[z_index]),
                              float.Parse(line_parts[y_index]),
                              float.Parse(line_parts[radius_index]),
                              ci, b_minus);
                    if (float.Parse(line_parts[radius_index]) > max_radius)
                    {
                        max_radius = float.Parse(line_parts[radius_index]);
                    }
                }
                count += 1;
            }

            //RGB values present
            if (r_index != -1 && g_index != -1 && b_index != -1)
            {
                rgb_found = true;
            }
            //Did not find
            if (x_index == -1 || y_index == -1 || z_index == -1 || radius_index == -1)
            {
                return(null);
            }
        }

        s.max_r_val  = max_r_val;
        s.max_g_val  = max_g_val;
        s.max_b_val  = max_b_val;
        s.max_radius = max_radius;

        return(s);
    }