示例#1
0
        public void TestAsynchronousUpdate()
        {
            using (
                ParticleSystem <SimpleParticle> system = new ParticleSystem <SimpleParticle>(40)
                ) {
                system.Affectors.Add(
                    new MovementAffector <SimpleParticle>(SimpleParticleModifier.Default)
                    );

                for (int index = 0; index < 40; ++index)
                {
                    SimpleParticle particle = new SimpleParticle();
                    particle.Position.Y = (float)index;
                    particle.Velocity.X = 1.2f;
                    system.AddParticle(particle);
                }

                IAsyncResult asyncResult = system.BeginUpdate(2, 4, null, null);
                system.EndUpdate(asyncResult);

                for (int index = 0; index < system.Particles.Count; ++index)
                {
                    Assert.AreEqual(2.4f, system.Particles.Array[index].Position.X);
                }
            }
        }
示例#2
0
        public void TestAsynchronousPrune()
        {
            using (
                ParticleSystem <SimpleParticle> system = new ParticleSystem <SimpleParticle>(10)
                ) {
                for (int index = 0; index < 15; ++index)
                {
                    SimpleParticle particle = new SimpleParticle();
                    particle.Position.Y = (float)index;
                    system.AddParticle(particle);
                }

                for (int repetition = 0; repetition < 3; ++repetition)
                {
                    IAsyncResult asyncResult = system.BeginPrune(
                        delegate(ref SimpleParticle particle) {
                        Thread.Sleep(0); // yield time slice
                        return(particle.Position.Y < 5.0f);
                    },
                        null, null
                        );
                    system.EndPrune(asyncResult);
                }

                Assert.AreEqual(5, system.Particles.Count);
                for (int index = 0; index < system.Particles.Count; ++index)
                {
                    Assert.Less(system.Particles.Array[index].Position.Y, 5.0f);
                }
            }
        }
示例#3
0
        public void TestPrune()
        {
            using (
                ParticleSystem <SimpleParticle> system = new ParticleSystem <SimpleParticle>(10)
                ) {
                for (int index = 0; index < 10; ++index)
                {
                    SimpleParticle particle = new SimpleParticle();
                    particle.Position.Y = (float)index;
                    system.AddParticle(particle);
                }

                system.Prune(
                    delegate(ref SimpleParticle particle) {
                    return(particle.Position.Y < 5.0f);
                }
                    );

                Assert.AreEqual(5, system.Particles.Count);
                for (int index = 0; index < system.Particles.Count; ++index)
                {
                    Assert.Less(system.Particles.Array[index].Position.Y, 5.0f);
                }
            }
        }
    public void TestSetVelocity() {
      SimpleParticle particle = new SimpleParticle();

      Vector3 velocity = new Vector3(1.2f, 3.4f, 5.6f);
      SimpleParticleModifier.Default.SetVelocity(ref particle, ref velocity);

      Assert.AreEqual(velocity, particle.Velocity);
    }
    public void TestGetVelocity() {
      SimpleParticle particle = new SimpleParticle();
      particle.Velocity = new Vector3(1.2f, 3.4f, 5.6f);

      Vector3 velocity;
      SimpleParticleModifier.Default.GetVelocity(ref particle, out velocity);

      Assert.AreEqual(new Vector3(1.2f, 3.4f, 5.6f), velocity);
    }
示例#6
0
        public void TestSetVelocity()
        {
            SimpleParticle particle = new SimpleParticle();

            Vector3 velocity = new Vector3(1.2f, 3.4f, 5.6f);

            SimpleParticleModifier.Default.SetVelocity(ref particle, ref velocity);

            Assert.AreEqual(velocity, particle.Velocity);
        }
示例#7
0
        public void TestSetPosition()
        {
            SimpleParticle particle = new SimpleParticle();

            Vector3 position = new Vector3(1.2f, 3.4f, 5.6f);

            SimpleParticleModifier.Default.SetPosition(ref particle, ref position);

            Assert.AreEqual(position, particle.Position);
        }
示例#8
0
        public void TestGetVelocity()
        {
            SimpleParticle particle = new SimpleParticle();

            particle.Velocity = new Vector3(1.2f, 3.4f, 5.6f);

            Vector3 velocity;

            SimpleParticleModifier.Default.GetVelocity(ref particle, out velocity);

            Assert.AreEqual(new Vector3(1.2f, 3.4f, 5.6f), velocity);
        }
    public void TestConstructor() {
      SimpleParticle particle = new SimpleParticle(
        new Vector3(1.1f, 2.2f, 3.3f), new Vector3(4.4f, 5.5f, 6.6f)
      );

      Assert.AreEqual(1.1f, particle.Position.X);
      Assert.AreEqual(2.2f, particle.Position.Y);
      Assert.AreEqual(3.3f, particle.Position.Z);
      Assert.AreEqual(4.4f, particle.Velocity.X);
      Assert.AreEqual(5.5f, particle.Velocity.Y);
      Assert.AreEqual(6.6f, particle.Velocity.Z);
    }
示例#10
0
        public void TestGetPosition()
        {
            SimpleParticle particle = new SimpleParticle();

            particle.Position = new Vector3(1.2f, 3.4f, 5.6f);

            Vector3 position;

            SimpleParticleModifier.Default.GetPosition(ref particle, out position);

            Assert.AreEqual(new Vector3(1.2f, 3.4f, 5.6f), position);
        }
示例#11
0
        public void TestAddToVelocity()
        {
            SimpleParticle[] particles = new SimpleParticle[] {
                new SimpleParticle(), new SimpleParticle()
            };

            Vector3 adjustment = new Vector3(1.2f, 3.4f, 5.6f);

            SimpleParticleModifier.Default.AddToVelocity(particles, 0, 2, ref adjustment);

            Assert.AreEqual(adjustment, particles[0].Velocity);
            Assert.AreEqual(adjustment, particles[1].Velocity);
        }
示例#12
0
        public void TestConstructor()
        {
            SimpleParticle particle = new SimpleParticle(
                new Vector3(1.1f, 2.2f, 3.3f), new Vector3(4.4f, 5.5f, 6.6f)
                );

            Assert.AreEqual(1.1f, particle.Position.X);
            Assert.AreEqual(2.2f, particle.Position.Y);
            Assert.AreEqual(3.3f, particle.Position.Z);
            Assert.AreEqual(4.4f, particle.Velocity.X);
            Assert.AreEqual(5.5f, particle.Velocity.Y);
            Assert.AreEqual(6.6f, particle.Velocity.Z);
        }
示例#13
0
        public void TestAddScaledVelocityToPosition()
        {
            SimpleParticle[] particles = new SimpleParticle[] {
                new SimpleParticle(), new SimpleParticle()
            };

            particles[0].Velocity = new Vector3(1.0f, 2.0f, 3.0f);
            particles[1].Velocity = new Vector3(4.0f, 5.0f, 6.0f);

            SimpleParticleModifier.Default.AddScaledVelocityToPosition(particles, 0, 2, 2.5f);

            Assert.AreEqual(particles[0].Velocity * 2.5f, particles[0].Position);
            Assert.AreEqual(particles[1].Velocity * 2.5f, particles[1].Position);
        }
    public void TestGravity() {
      GravityAffector<SimpleParticle> affector = new GravityAffector<SimpleParticle>(
        SimpleParticleModifier.Default
      );

      SimpleParticle[/*100*/] particles = new SimpleParticle[100];
      affector.Affect(particles, 25, 50, (int)affector.UpdatesPerSecond);

      for(int index = 0; index < 25; ++index) {
        Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
      }
      for(int index = 25; index < 50; ++index) {
        Assert.AreEqual(affector.Gravity, particles[index].Velocity);
      }
      for(int index = 75; index < 100; ++index) {
        Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
      }
    }
示例#15
0
        public void TestMovement()
        {
            MovementAffector <SimpleParticle> affector = new MovementAffector <SimpleParticle>(
                SimpleParticleModifier.Default
                );

            SimpleParticle[] /*100*/ particles = new SimpleParticle[100];
            particles[0].Velocity    = Vector3.One;
            particles[25].Velocity.X = 1.2f;
            particles[50].Velocity.Y = 3.4f;
            particles[75].Velocity.Z = 5.6f;
            particles[99].Velocity   = -Vector3.One;

            affector.Affect(particles, 20, 60, 1);

            for (int index = 0; index < 100; ++index)
            {
                switch (index)
                {
                case 25: {
                    Assert.AreEqual(new Vector3(1.2f, 0.0f, 0.0f), particles[index].Position);
                    break;
                }

                case 50: {
                    Assert.AreEqual(new Vector3(0.0f, 3.4f, 0.0f), particles[index].Position);
                    break;
                }

                case 75: {
                    Assert.AreEqual(new Vector3(0.0f, 0.0f, 5.6f), particles[index].Position);
                    break;
                }

                default: {
                    Assert.AreEqual(Vector3.Zero, particles[index].Position);
                    break;
                }
                }
            }
        }
示例#16
0
        public void TestGravity()
        {
            GravityAffector <SimpleParticle> affector = new GravityAffector <SimpleParticle>(
                SimpleParticleModifier.Default
                );

            SimpleParticle[] /*100*/ particles = new SimpleParticle[100];
            affector.Affect(particles, 25, 50, (int)affector.UpdatesPerSecond);

            for (int index = 0; index < 25; ++index)
            {
                Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
            }
            for (int index = 25; index < 50; ++index)
            {
                Assert.AreEqual(affector.Gravity, particles[index].Velocity);
            }
            for (int index = 75; index < 100; ++index)
            {
                Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
            }
        }
示例#17
0
        public void TestSetWeight()
        {
            SimpleParticle particle = new SimpleParticle();

            SimpleParticleModifier.Default.SetWeight(ref particle, 12.34f);
        }
示例#18
0
        public void TestGetWeight()
        {
            SimpleParticle particle = new SimpleParticle();

            Assert.AreEqual(0.0f, SimpleParticleModifier.Default.GetWeight(ref particle));
        }
    public void TestGetPosition() {
      SimpleParticle particle = new SimpleParticle();
      particle.Position = new Vector3(1.2f, 3.4f, 5.6f);

      Vector3 position;
      SimpleParticleModifier.Default.GetPosition(ref particle, out position);

      Assert.AreEqual(new Vector3(1.2f, 3.4f, 5.6f), position);
    }
    public void TestSetPosition() {
      SimpleParticle particle = new SimpleParticle();

      Vector3 position = new Vector3(1.2f, 3.4f, 5.6f);
      SimpleParticleModifier.Default.SetPosition(ref particle, ref position);

      Assert.AreEqual(position, particle.Position);
    }
 public void TestSetWeight() {
   SimpleParticle particle = new SimpleParticle();
   SimpleParticleModifier.Default.SetWeight(ref particle, 12.34f);
 }
 public void TestGetWeight() {
   SimpleParticle particle = new SimpleParticle();
   Assert.AreEqual(0.0f, SimpleParticleModifier.Default.GetWeight(ref particle));
 }
    public void TestAddScaledVelocityToPosition() {
      SimpleParticle[] particles = new SimpleParticle[] {
        new SimpleParticle(), new SimpleParticle()
      };

      particles[0].Velocity = new Vector3(1.0f, 2.0f, 3.0f);
      particles[1].Velocity = new Vector3(4.0f, 5.0f, 6.0f);

      SimpleParticleModifier.Default.AddScaledVelocityToPosition(particles, 0, 2, 2.5f);

      Assert.AreEqual(particles[0].Velocity * 2.5f, particles[0].Position);
      Assert.AreEqual(particles[1].Velocity * 2.5f, particles[1].Position);
    }
    public void TestAddToVelocity() {
      SimpleParticle[] particles = new SimpleParticle[] {
        new SimpleParticle(), new SimpleParticle()
      };

      Vector3 adjustment = new Vector3(1.2f, 3.4f, 5.6f);
      SimpleParticleModifier.Default.AddToVelocity(particles, 0, 2, ref adjustment);

      Assert.AreEqual(adjustment, particles[0].Velocity);
      Assert.AreEqual(adjustment, particles[1].Velocity);
    }