Beispiel #1
0
        public void TestUpdate()
        {
            var forceRegistry = new ForceRegistry();
            var force         = new ParticleConstantForce(new Vector2D(5, 0));
            var p             = new Particle {
                Mass = 1
            };

            force.Add(p);

            this.TestAddForceGenerator(forceRegistry, force);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(5, 0), p.Acceleration, "物体被赋予正确的加速度");

            p.Acceleration = Vector2D.Zero;
            this.TestRemoveForceGenerator(forceRegistry, force);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(0, 0), p.Acceleration, "删去作用力发生器,物体不再受该作用力发生器所产生的力");

            force.Add(p);
            this.TestAddForceGenerator(forceRegistry, force);
            this.TestRemoveParticle(forceRegistry, p);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(0, 0), p.Acceleration, "删去物体,物体不再受该作用力发生器所产生的力");
        }
Beispiel #2
0
        /// <summary>
        /// Processes all the physics for the particle world.
        /// </summary>
        /// <param name="secondsElapsed">Seconds since last run</param>
        private void RunPhysics(float secondsElapsed)
        {
            //Apply all force generators
            forceRegistry.Update(secondsElapsed);

            //Integrate to update position, velocity, acceleration and orientation
            Integrate(secondsElapsed);

            //TODO: implements contact generators and resolvers
            //Genera i contacts tra le particles
            //uint usedContacts = GenerateContacts();

            //Processa i contacts
            //if (calculateIterations) resolver.SetIterations(usedContacts * 2);
            //if (usedContacts > 0)
            //    resolver.ResolveContacts(contacts, usedContacts, duration);

            // Svuota gli accumularori di forze all'interno delle particelle
            //for (int i = 0; i < rigidBodies.Count; i++)
            //    rigidBodies[i].ClearAccumulator();
        }
Beispiel #3
0
        /// <summary>
        /// Processes all the physics for the particle world.
        /// </summary>
        /// <param name="duration">Secondi</param>
        public void RunPhysics(float duration)
        {
            //Applica tutti i force generator
            forceRegistry.Update(duration);

            //Integra le forze per aggiornarne la posizione
            Integrate(duration);

            //Genera i contacts tra le particles
            uint usedContacts = GenerateContacts();

            //Processa i contacts
            //if (calculateIterations) resolver.SetIterations(usedContacts * 2);
            if (usedContacts > 0)
            {
                resolver.ResolveContacts(contacts, usedContacts, duration);
            }

            // Svuota gli accumularori di forze all'interno delle particelle
            //for (int i = 0; i < Particles.Count; i++)
            //    Particles[i].ClearAccumulator();
        }