Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (timestep == 0)
     {                                                                           //This prevents a timestep of 0 which SERIOUSLY messes up the Verlet algorithm
         timestep = 0.0000001f;
     }
     GameObject[] massObject = GameObject.FindGameObjectsWithTag("massObject"); //Gathers all of the massObjects for updating
     for (int i = 0; i < massObject.Length; i++)
     {                                                                          //Updates relivant datapoints
         VerletObjectV1 massiveBody = massObject[i].GetComponent <VerletObjectV1>();
         massiveBody.timeStep = timestep;
         massiveBody.scale    = scale;
         float scaleValue = 6.68459e-09f * sizeScale * massiveBody.radius * scale;
         massObject[i].transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
     }
 }
Example #2
0
        public void calculateAcceleration()
        {
            Vector3d ForceVector = Vector3d.zero;

            for (int i = 0; i < massObject.Length; i++)
            {                                                                                                            //For the rest of the objects...
                if (massObject[i] != this.gameObject)
                {                                                                                                        //If the object isn't this object
                    VerletObjectV1 mO = massObject[i].GetComponent <VerletObjectV1>();                                   //The "O" is a letter not a number
                    distance = Mathd.Sqrt(Mathd.Pow(position.x - mO.position.x, 2) + Mathd.Pow(position.y - mO.position.y, 2) + Mathd.Pow(position.z - mO.position.z, 2));
                    double Force = (1.9934976 * Mathd.Pow(10, -44)) * ((mass * mO.mass)) * (1 / Mathd.Pow(distance, 2)); //This and ABOVE calculate force of gravity and distance between bodies respectively

                    Vector3d thisVector = (mO.position - position).normalized * Force;                                   //Updates the velocity vector based on each body, thus calculating all relationships
                    ForceVector = ForceVector + thisVector;
                }
            }
            acceleration = ForceVector * (1 / mass);                                                //Calculates the actual accleration
        }
Example #3
0
        private string time;                        //The current time (assists above)

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

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

            orbitFile.Load(@"Assets/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);
                    }
                    else if (subnode.Name == "radius")
                    {                                               //Get the radius (if available)
                        radius = float.Parse(subnode.InnerText);
                    }
                }
                DateTime currenttime  = DateTime.Now;                                               //The current date/time
                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;
                }
                Debug.Log(currenttime.Hour);
                string targetDateTime = "";
                if (currenttime.Hour == 0)
                {
                    targetDateTime = currenttime.Year.ToString() + "-" + currentMonth + "-" + currenttime.Day.ToString() + " 0" + currenttime.Hour + ":00:00.0000";
                }
                else
                {
                    targetDateTime = currenttime.Year.ToString() + "-" + currentMonth + "-" + currenttime.Day.ToString() + " " + currenttime.Hour + ":00:00.0000";
                }
                foreach (XmlNode orbitNode in orbitFile.DocumentElement.ChildNodes)
                {                   //For every planet
                    if (orbitNode.Attributes["name"].Value == bodyName)
                    {
                        Debug.Log("START");
                        Debug.Log(targetDateTime);
                        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);
                            }
                        }
                    }
                }
                //defaultBody.name = bodyName;										//This code sets the default body values to the given data and instantiates it
                VerletObjectV1 df = defaultBody.GetComponent <VerletObjectV1>();
                df.mass          = mass;
                df.inputPosition = new Vector3(x, y, z);
                df.inputVelocity = new Vector3(vx, vy, vz);
                df.radius        = radius;
                GameObject body = Instantiate(defaultBody);
                body.name = bodyName;
            }
        }
 // Use this for initialization
 void Start()
 {
     vO = massiveBody.GetComponent <VerletObjectV1>();
 }