예제 #1
0
파일: World.cs 프로젝트: Brandon702/GAT315
    void Update()
    {
        float dt = Time.deltaTime;

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

        if (!simulate)
        {
            return;
        }

        //Gravitation stuff here goes below here:
        GravitionalForce.ApplyForce(bodies, gravitation.value);
        springs.ForEach(spring => spring.ApplyForce());

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


        timeAccumulator = 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 == 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.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
예제 #2
0
파일: World.cs 프로젝트: NBender8668/GAT315
    void Update()
    {
        float dt = Time.deltaTime;

        fps           = (1.0f / dt);
        fpsAverage    = (fpsAverage * smoothing) + (fps * (1.0f - smoothing));
        fpsText.value = "FPS: " + fpsAverage.ToString("F2");
        if (!simulate)
        {
            return;
        }

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


        timeAccumulator += dt;

        GravitionalForce.ApplyForce(bodies, gravitation.value);

        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 == true)
            {
                Collision.CreateContact(bodies, out List <Contact> contacts);
                contacts.ForEach(contact => { contact.bodyA.shape.color = Color.blue; contact.bodyB.shape.color = Color.blue; });
                ContactSolver.Resolve(contacts);
            }
            timeAccumulator = timeAccumulator - FixedDeltaTime;
        }

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

        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }