Ejemplo n.º 1
0
    private void TestRV(OrbitData od, GameObject planet, GameObject star)
    {
        GameObject testPlanet = TestSetupUtils.CreatePlanetInHyper(star, 1f);

        testPlanet.name = "TestPlanet";
        OrbitHyper testHyper = testPlanet.GetComponent <OrbitHyper>();

        testHyper.InitFromOrbitData(od);

        planet.name = "Planet";

        // Awkward but cannot add a new object to GE when it is stopped, so re-add all three
        GravityEngine ge = GravityEngine.Instance();

        ge.Clear();
        ge.AddBody(star);
        ge.AddBody(planet);
        ge.AddBody(testPlanet);
        ge.Setup();
        ge.LogDump();
        Vector3 r_od = ge.GetPhysicsPosition(testPlanet.GetComponent <NBody>());
        Vector3 v_od = ge.GetVelocity(testPlanet);
        Vector3 r_i  = ge.GetPhysicsPosition(planet.GetComponent <NBody>());
        Vector3 v_i  = ge.GetVelocity(planet);

        Debug.Log(" r_i=" + r_i + " r_od=" + r_od + " delta=" + Vector3.Distance(r_i, r_od));
        Debug.Log(" v_i=" + v_i + " v_od=" + v_od + " delta=" + Vector3.Distance(v_i, v_od));
        Assert.IsTrue(FloatEqual(Vector3.Distance(r_i, r_od), 0f, 5E-2));
        Assert.IsTrue(FloatEqual(Vector3.Distance(v_i, v_od), 0f, 5E-2));
    }
Ejemplo n.º 2
0
    private void TestRV(OrbitData od, GameObject planet, GameObject star)
    {
        Vector3 r_initial = planet.transform.position;
        Vector3 v_initial = planet.GetComponent <NBody>().vel;

        GameObject testPlanet = TestSetupUtils.CreatePlanetInHyper(star, 1f);
        OrbitHyper testHyper  = testPlanet.GetComponent <OrbitHyper>();

        testHyper.InitFromOrbitData(od);
        testHyper.Init();
        testHyper.InitNBody(1f, 1f);
        Vector3 r = testPlanet.transform.position;
        Vector3 v = testPlanet.GetComponent <NBody>().vel;

        Debug.Log(" r_i=" + r_initial + " r=" + r + " delta=" + Vector3.Distance(r_initial, r));
        Debug.Log(" v_i=" + v_initial + " v=" + v + " delta=" + Vector3.Distance(v_initial, v));
        Assert.IsTrue(FloatEqual(Vector3.Distance(r_initial, r), 0f, 5E-2));
        Assert.IsTrue(FloatEqual(Vector3.Distance(v_initial, v), 0f, 5E-2));
    }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (initOk)
     {
         // velocities not normally updated in NBody (to reduce CPU). Need to ask
         // object to update its velocity from Gravity Engine if engine is running
         if (GravityEngine.instance.GetEvolve())
         {
             nbody.UpdateVelocity();
         }
         orbitData.SetOrbitForVelocity(nbody, aroundNBody);
         // Is the resulting orbit and ellipse or hyperbola?
         if (orbitData.ecc < 1f)
         {
             ellipseBase.InitFromOrbitData(orbitData);
             lineR.SetPositions(ellipseBase.OrbitPositions(numPoints));
         }
         else
         {
             orbitHyper.InitFromOrbitData(orbitData);
             lineR.SetPositions(orbitHyper.OrbitPositions(numPoints));
         }
     }
 }