Example #1
0
    /// <summary>
    /// Reads the csv file and fills the x, y, z arrays with values
    /// </summary>
    private void readCsv()
    {
        DateTime d = DateTime.Now;

        using (var reader = new StreamReader("Assets/Resources/stars.csv"))
        {
            int count = 0;
            while (!reader.EndOfStream)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');


                if (count != 0 && count < starAmmount && ((moduloActivated && count % moduloAmmount == 1) || !moduloActivated))
                {
                    //Note that y and z coordinates are flipped because unity has a different coordinate system.  Y is up/down
                    StarObj star = new StarObj(float.Parse(values[17]) * scaler, float.Parse(values[19]) * scaler, float.Parse(values[18]) * scaler);
                    //StarObj star = new StarObj(float.Parse(values[17]) * scaler, 0, float.Parse(values[18]) * scaler);
                    star.velocity.x = float.Parse(values[20]) * scaler;
                    star.velocity.y = float.Parse(values[22]) * scaler;
                    star.velocity.z = float.Parse(values[21]) * scaler;
                    star.mass       = (float)Math.Pow(float.Parse((values[14])), 1 / 3.5);
                    if (float.IsNaN(star.mass))
                    {
                        star.mass = 0.50f;
                    }
                    stars.Add(star);

                    partSystem.Emit(1);
                    starSize += 1;
                }
                else
                {
                    //print (values [16]);
                }

                if (count == starAmmount)
                {
                    break;
                }

                count += 1;
            }
        }
        //print (DateTime.Now.Second - d.Second );
    }
Example #2
0
    private Point calculateAccel(int indexOfStar)
    {
        Point   acceleration = new Point(0, 0, 0);
        StarObj starTarget   = stars[indexOfStar];
        int     count        = 0;

        foreach (StarObj star in stars)
        {
            if (indexOfStar != count)
            {
                float r = (float)(Math.Pow((starTarget.x - star.x), 2) +
                                  Math.Pow((starTarget.y - star.y), 2) +
                                  Math.Pow((starTarget.z - star.z), 2));
                r = (float)Math.Sqrt(r);

                float temp = G_CONST * star.mass / (float)Math.Pow(r, 3);
                acceleration.x += temp * (star.x - starTarget.x);
                acceleration.y += temp * (star.y - starTarget.y);
                acceleration.z += temp * (star.z - starTarget.z);
            }
            count += 1;
        }
        return(acceleration);
    }