Ejemplo n.º 1
0
    public void EarthForce()
    {
        GravitationalForce g = new GravitationalForce(Constants.Earth.MASS);

        Assert.That(g.compute(1.0), Is.EqualTo(G * Constants.Earth.MASS));
        Assert.That(g.compute(1e6), Is.EqualTo(G * Constants.Earth.MASS / 1e12));
    }
Ejemplo n.º 2
0
        public static void Tick()
        {
            if (gamePause)
            {
                return;
            }

            game.gamePictureBox.Invalidate();
            GravitationalForce.EnactGravity();

            foreach (IBehaviour b in tickables)
            {
                b.onUpdate();
            }

            foreach (IBehaviour b in addables)
            {
                tickables.Add(b);
            }

            foreach (IBehaviour b in removables)
            {
                tickables.Remove(b);
            }

            _addables   = new List <IBehaviour>();
            _removables = new List <IBehaviour>();
        }
Ejemplo n.º 3
0
    public void EarthMoonForce()
    {
        GravitationalForce g = new GravitationalForce(Constants.Earth.MASS, Constants.Moon.MASS);

        double d = 370.149120e6;
        double f = G * Constants.Earth.MASS * Constants.Moon.MASS / (d * d);

        Assert.That(g.compute(d), Is.EqualTo(f));
    }
Ejemplo n.º 4
0
    void Update()
    {
        //Debug.Log(1.0f / Time.deltaTime);
        if (!simulate)
        {
            return;
        }

        //Another way to do fps
        float dt = Time.deltaTime;

        fps           = (1.0f / dt);
        fpsAverage    = (fpsAverage * smoothing) + (fps * (1.0f - smoothing));
        fpsText.value = "FPS: " + fpsAverage.ToString("F1");
        //Debug.Log(fps);

        timeAccumulator += Time.deltaTime;

        GravitationalForce.ApplyForce(bodies, gravitation.value);

        //bodies.ForEach(body => body.shape.color = Color.red);

        while (timeAccumulator >= fixedDeltaTime)
        {
            bodies.ForEach(body => body.Step(fixedDeltaTime));
            bodies.ForEach(body => Integrator.ImplicitEuler(body, fixedDeltaTime));

            bodies.ForEach(body => body.shape.color = Color.cyan);

            if (collision)
            {
                Collision.CreateContacts(bodies, out List <Contact> contacts);
                contacts.ForEach(contact => { contact.bodyA.shape.color = Color.red; contact.bodyB.shape.color = Color.red; });
                ContactSolver.Resolve(contacts);
            }

            timeAccumulator = timeAccumulator - fixedDeltaTime;
        }

        if (wrap)
        {
            bodies.ForEach(body => body.position = Utilities.Wrap(body.position, -size, size));
        }

        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
Ejemplo n.º 5
0
    void Update()
    {
        float dt = Time.deltaTime;

        fps           = 1.0f / dt;
        fpsAverage    = (fpsAverage * smoothing) + (fps * (1.0f - smoothing));
        fpsText.value = "FPS: " + fpsAverage.ToString("F1");

        if (!simulate.value)
        {
            return;
        }

        GravitationalForce.ApplyForce(bodies, gravitation.value);
        springs.ForEach(spring => spring.ApplyForce());

        timeAccumulator += dt;
        while (timeAccumulator > fixedDeltaTime)
        {
            bodies.ForEach(body => body.Step(fixedDeltaTime));
            bodies.ForEach(body => Integrator.ExplicitEuler(body, fixedDeltaTime));

            bodies.ForEach(body => body.shape.color = Color.white);

            if (collision == true)
            {
                Collision.CreateContacts(bodies, out List <Contact> contacts);
                contacts.ForEach(contact => { contact.bodyA.shape.color = Color.red; contact.bodyB.shape.color = Color.red; });
                ContactSolver.Resolve(contacts);
            }

            timeAccumulator = timeAccumulator - fixedDeltaTime;
        }

        if (wrap)
        {
            bodies.ForEach(body => body.position = Utilities.Wrap(body.position, -size, size));
        }

        bodies.ForEach(body => body.Step(dt));
        bodies.ForEach(body => Integrator.SemiImplicitEuler(body, dt));

        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
Ejemplo n.º 6
0
    void Update()
    {
        Debug.Log($"system fps:{1.0f / Time.deltaTime}");
        Debug.Log($"fixed fps:{1.0f / fixedDT}");

        fpsText.value = $"FPS: {(1.0f / Time.deltaTime).ToString("F1")}";

        if (!simulate)
        {
            return;
        }

        float dt = Time.deltaTime;

        timeAccumulator += dt;

        GravitationalForce.ApplyForce(bodies, gravitation);
        springs.ForEach(spring => spring.applyForce());

        while (timeAccumulator >= fixedDT)
        {
            bodies.ForEach(body => body.step(fixedDT));
            bodies.ForEach(body => Integrator.semiImplicitEuler(body, fixedDT));

            bodies.ForEach(body => body.shape.color = Color.red);

            if (collision)
            {
                Collision.createContacts(bodies, out List <Contact> contacts);
                ContactResolver.resolve(contacts);

                contacts.ForEach(contact => contact.bodyA.shape.color = Color.cyan);
                contacts.ForEach(contact => contact.bodyB.shape.color = Color.cyan);
            }
            if (wrap)
            {
                bodies.ForEach(body => body.position = Utilities.wrap(body.position, -size, size));
            }

            timeAccumulator -= fixedDT;
        }
        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
Ejemplo n.º 7
0
    void Update()
    {
        springs.ForEach(spring => spring.Draw());
        if (!simulate.value)
        {
            return;
        }

        fps           = 1.0f / Time.deltaTime;
        fpsAverage    = (fpsAverage * smoothing) + (fps * (1.0f - smoothing));
        fpsText.value = string.Format("FPS: {0:F}", fpsAverage);

        GravitationalForce.ApplyForce(bodies, gravitation.value);
        forces.ForEach(force => bodies.ForEach(body => force.ApplyForce(body)));
        springs.ForEach(spring => spring.ApplyForce());

        timeAccumulator += Time.deltaTime;
        while (timeAccumulator > fixedDeltaTime)
        {
            bodies.ForEach(body => body.Step(fixedDeltaTime));
            bodies.ForEach(body => Integrator.SemiImplicitEuler(body, fixedDeltaTime));

            bodies.ForEach(body => body.shape.color = Color.white);

            if (collision)
            {
                Collision.CreateContacts(bodies, out List <Contact> contacts);
                contacts.ForEach(contact => { contact.bodyA.shape.color = Color.red; contact.bodyB.shape.color = Color.red; });
                ContactSolver.Resolve(contacts);
            }

            timeAccumulator -= fixedDeltaTime;
        }

        if (wrap)
        {
            bodies.ForEach(body => body.position = Utilities.Wrap(body.position, -size, size));
        }

        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
Ejemplo n.º 8
0
    public void UnitForce()
    {
        GravitationalForce g = new GravitationalForce(1.0, 1.0);

        Assert.That(g.compute(1.0), Is.EqualTo(G));
    }