Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        VerletObjectV2 center = (VerletObjectV2)GameObject.Find(CenterBody).GetComponent("VerletObjectV2");

        CenterBodyOffset = center.position;
        minicounter++;
        controllerDaysCounter = controllTimeCounter / 86400;
        //Debug.Log("On frame : "+minicounter+", "+counter+" loops have completed.");
        runThreads();
    }
Ejemplo n.º 2
0
    void runThreads()
    {
        float tmpTs = timeStep;                                                                 //Temperory timestep to prevent input mess

        if (multiThreadFlag == multithreadedJobs.Length && timeStep != 0)                       //If the threads have completed
        {
            float tmppTs = previousTimeStep;
            controllTimeCounter += previousTimeStep;
            counter             += 1;                                                           //Increase the counter of how many loops have gone through
            multiThreadFlag      = 0;                                                           //Flag that there are threads running
            massObject           = GameObject.FindGameObjectsWithTag("massObject");             //Gathers all of the massObjects for calculation
            float[]    masses    = new float[massObject.Length];                                //Gathers all of the masses in order
            Vector3d[] positions = new Vector3d[massObject.Length];                             //Gathers all of the vectors of the objects in order
            for (int i = 0; i < massObject.Length; i++)                                         //For every object
            {
                VerletObjectV2 obj = (VerletObjectV2)massObject[i].GetComponent("VerletObjectV2");
                masses[i]    = obj.mass;
                positions[i] = obj.position;
            }
            multithreadedJobs = new VerletV2Thread[massObject.Length];                                  //Create thread objects
            for (int i = 0; i < massObject.Length; i++)                                                 //For each thread object
            {
                multithreadedJobs[i] = new VerletV2Thread();
                VerletV2Thread thisJob = multithreadedJobs[i];
                thisJob.ThreadName = massObject[i].name + i;                                                          //Assign name
                thisJob.thisIndex  = i;                                                                               //Assign index (Unused I think)
                thisJob.m          = masses[i];                                                                       //Assign mass
                thisJob.p          = positions[i];                                                                    //Assign position of object
                thisJob.pp         = ((VerletObjectV2)massObject[i].GetComponent("VerletObjectV2")).previousPosition; //Assign previous position
                thisJob.m2         = masses;                                                                          //Assign mass of every object
                thisJob.p2         = positions;                                                                       //Assign psoition of every object
                thisJob.ts         = tmpTs;                                                                           //Assign timestep for the simulation
                thisJob.pts        = tmppTs;                                                                          //Assign previous timestep
                multithreadedJobs[i].Start();                                                                         //Start thread
                StartCoroutine("finished", multithreadedJobs[i]);                                                     //Start end coroutine
            }
            ///for(int i = 0; i < multithreadedJobs.Length; i++) {
            //	multithreadedJobs[i].Start();
            //	StartCoroutine ("finished" ,multithreadedJobs[i]);
            //}
            previousTimeStep = tmpTs;
        }
    }
Ejemplo n.º 3
0
    void TestTime(DateTime currenttime, String body)
    {
        XmlDocument dataFile = new XmlDocument();                                                                       //The file of data about the bodies

        dataFile.Load(@"Assets/Big-Birtha/PlanetaryData/filename.xml");
        XmlDocument orbitFile = new XmlDocument();                                                                      //The file of the orbit data for each body

        orbitFile.Load(@"Assets/Big-Birtha/PlanetaryData/orbitData.xml");
        foreach (XmlNode node in dataFile.DocumentElement.ChildNodes)                           //For every body
        {
            bodyName = node.Attributes["name"].Value;                                           //Name the body
            foreach (XmlNode subnode in node.ChildNodes)                                        //For all accociated data
            {
                if (subnode.Name == "mass")                                                     //Get the mass
                //mass = float.Parse(subnode.InnerText);
                {
                    bool successfullyParsed = float.TryParse(subnode.InnerText, out mass);
                    if (!successfullyParsed)
                    {
                        flag = true;
                        break;
                    }
                }
                else if (subnode.Name == "radius")                                                                      //Get the radius (if available)
                {
                    radius = float.Parse(subnode.InnerText);
                }
                else if (subnode.Name == "rotation")
                {
                    rotation = float.Parse(subnode.InnerText);
                }
            }
            string currentMonth = "";
            switch (currenttime.Month)                                                                                                  //Getting the month correct
            {
            case 1:
                currentMonth = "Jan";
                break;

            case 2:
                currentMonth = "Feb";
                break;

            case 3:
                currentMonth = "Mar";
                break;

            case 4:
                currentMonth = "Apr";
                break;

            case 5:
                currentMonth = "May";
                break;

            case 6:
                currentMonth = "Jun";
                break;

            case 7:
                currentMonth = "Jul";
                break;

            case 8:
                currentMonth = "Aug";
                break;

            case 9:
                currentMonth = "Sep";
                break;

            case 10:
                currentMonth = "Oct";
                break;

            case 11:
                currentMonth = "Nov";
                break;

            case 12:
                currentMonth = "Dec";
                break;
            }
            string targetDateTime = currenttime.Year.ToString() + "-" + currentMonth + "-";
            if (currenttime.Day < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Day.ToString() + " ";
            if (currenttime.Hour < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Hour + ":00:00.0000";

            foreach (XmlNode orbitNode in orbitFile.DocumentElement.ChildNodes)                 //For every planet
            {
                if (orbitNode.Attributes["name"].Value == bodyName)
                {
                    foreach (XmlNode orbitsubnode in orbitNode.ChildNodes)                              //For every orbit datapoint
                    {
                        if (orbitsubnode.Attributes["timeStamp"].Value == targetDateTime)
                        {
                            x  = float.Parse(orbitsubnode["X"].InnerText);                                      //(above) if the timestamp is the reqested one
                            y  = float.Parse(orbitsubnode["Y"].InnerText);                                      //		Get the data
                            z  = float.Parse(orbitsubnode["Z"].InnerText);
                            vx = float.Parse(orbitsubnode["VX"].InnerText);
                            vy = float.Parse(orbitsubnode["VY"].InnerText);
                            vz = float.Parse(orbitsubnode["VZ"].InnerText);
                        }
                    }
                }
            }
            if (!flag)                                                                          //Flag prevents bad input
            //defaultBody.name = bodyName;										//This code sets the default body values to the given data and instantiates it
            {
                if (bodyName == body)
                {
                    VerletObjectV2 theBody = (VerletObjectV2)GameObject.Find(body).GetComponent("VerletObjectV2");
                    Double         drift   = dist(theBody.position, new Vector3d(x, y, z));
                    Debug.Log(drift);
                }
            }
            else
            {
                flag = false;
            }
        }
    }
Ejemplo n.º 4
0
    private float z;              //The Z position of the object

    // Use this for initialization
    private void Start()
    {
        var dataFile = new XmlDocument(); //The file of data about the bodies

        dataFile.Load(@"Assets/Big-Birtha/PlanetaryData/filename.xml");
        var orbitFile = new XmlDocument(); //The file of the orbit data for each body

        orbitFile.Load(@"Assets/Big-Birtha/PlanetaryData/orbitData.xml");
        foreach (XmlNode node in dataFile.DocumentElement.ChildNodes)
        {
            //For every body
            bodyName = node.Attributes["name"].Value; //Name the body
            foreach (XmlNode subnode in node.ChildNodes)
            {
                //For all accociated data
                if (subnode.Name == "mass")
                {
                    //Get the mass
                    //mass = float.Parse(subnode.InnerText);
                    var successfullyParsed = float.TryParse(subnode.InnerText, out mass);
                    if (!successfullyParsed)
                    {
                        flag = true;
                        break;
                    }
                }
                else if (subnode.Name == "radius")
                {
                    //Get the radius (if available)
                    radius = float.Parse(subnode.InnerText);
                }
                else if (subnode.Name == "rotation")
                {
                    rotation = float.Parse(subnode.InnerText);
                }
            }

            var currenttime  = DateTime.Now; //The current date/time
            var currentMonth = "";
            switch (currenttime.Month)
            {
            //Getting the month correct
            case 1:
                currentMonth = "Jan";
                break;

            case 2:
                currentMonth = "Feb";
                break;

            case 3:
                currentMonth = "Mar";
                break;

            case 4:
                currentMonth = "Apr";
                break;

            case 5:
                currentMonth = "May";
                break;

            case 6:
                currentMonth = "Jun";
                break;

            case 7:
                currentMonth = "Jul";
                break;

            case 8:
                currentMonth = "Aug";
                break;

            case 9:
                currentMonth = "Sep";
                break;

            case 10:
                currentMonth = "Oct";
                break;

            case 11:
                currentMonth = "Nov";
                break;

            case 12:
                currentMonth = "Dec";
                break;
            }

            var targetDateTime = currenttime.Year + "-" + currentMonth + "-";
            if (currenttime.Day < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Day + " ";
            if (currenttime.Hour < 10)
            {
                targetDateTime += "0";
            }
            targetDateTime += currenttime.Hour + ":00:00.0000";

            foreach (XmlNode orbitNode in orbitFile.DocumentElement.ChildNodes)
            {
                //For every planet
                if (orbitNode.Attributes["name"].Value == bodyName)
                {
                    foreach (XmlNode orbitsubnode in orbitNode.ChildNodes)
                    {
                        //For every orbit datapoint
                        if (orbitsubnode.Attributes["timeStamp"].Value == targetDateTime)
                        {
                            x  = float.Parse(orbitsubnode["X"].InnerText); //(above) if the timestamp is the reqested one
                            y  = float.Parse(orbitsubnode["Y"].InnerText); //		Get the data
                            z  = float.Parse(orbitsubnode["Z"].InnerText);
                            vx = float.Parse(orbitsubnode["VX"].InnerText);
                            vy = float.Parse(orbitsubnode["VY"].InnerText);
                            vz = float.Parse(orbitsubnode["VZ"].InnerText);
                        }
                    }
                }
            }

            if (!flag)
            {
                //Flag prevents bad input
                //defaultBody.name = bodyName;										//This code sets the default body values to the given data and instantiates it
                var df = VerletObjectV2.Constructor();
                //VerletObjectV2 df = defaultBody.GetComponent<VerletObjectV2>();
                df.gameObject.name = bodyName;
                df.mass            = mass;
                df.inputPosition   = new Vector3(x, y, z);
                df.inputVelocity   = new Vector3(vx, vy, vz);
                df.radius          = radius;
                df.rotation        = rotation;
                //GameObject body = Instantiate(defaultBody);
                //body.name = bodyName;
                rotation = 0;
                radius   = 1737;
            }
            else
            {
                flag = false;
            }
        }
    }