Exemple #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, "删去物体,物体不再受该作用力发生器所产生的力");
        }
Exemple #2
0
 /// <summary>
 /// Crea un nuovo particle simulator che gestisce il dato numero di contatti per frame.
 /// Si può specificare il numero di iterazioni massime da usare.
 /// </summary>
 /// <param name="maxContacts">Massimo numero di contacts gestiti</param>
 /// <param name="iteration">Massimo numero di iterazioni nella risoluzione dei contacts</param>
 public ParticleWorld(uint maxContacts, uint iteration)
 {
     Particles              = new List <Particle>();
     forceRegistry          = new ForceRegistry();
     resolver               = new ParticleContactResolver(iteration);
     contactGenRegistration = new List <ParticleContactGenerator>();
     contacts               = new List <ParticleContact>();
 }
Exemple #3
0
 private void TestRemoveParticle(
     ForceRegistry forceRegistry,
     Particle p)
 {
     forceRegistry.Remove(p);
 }
Exemple #4
0
 private void TestRemoveForceGenerator(
     ForceRegistry forceRegistry,
     ParticleForceGenerator force)
 {
     forceRegistry.Remove(force);
 }
Exemple #5
0
 private void TestAddForceGenerator(
     ForceRegistry forceRegistry,
     ParticleForceGenerator force)
 {
     forceRegistry.Add(force);
 }
Exemple #6
0
 /// <summary>
 /// Create the manager that handles the RigidBodies
 /// </summary>
 /// <param name="maxContacts">Maximum of contacts managed in a single iteration</param>
 /// <param name="iteration">Number of iterations used to resolve contacts</param>
 public RigidBodyWorld(uint maxContacts, uint iteration)
 {
     rigidBodies   = new List <RigidBody>();
     forceRegistry = new ForceRegistry();
 }