Ejemplo n.º 1
0
 public override void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     float currentLen = CurrentLength;
     if (currentLen == Length)
     {
         return;
     }
     ParticleContact contact = new ParticleContact();
     contact.Particles[0] = Particle;
     contact.Particles[1] = null;
     Vector3 normal = Anchor - Particle.Position;
     normal.Normalize();
     if (currentLen > Length)
     {
         contact.ContactNormal = normal;
         contact.Penetration = currentLen - Length;
     }
     else
     {
         contact.ContactNormal = normal * -1;
         contact.Penetration = Length - currentLen;
     }
     contact.Restitution = 0;
     contacts.Add(contact);
     return;
 }
Ejemplo n.º 2
0
 public override void  GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     ParticleContact contact = new ParticleContact();
     float currentLen = CurrentLength;
     if (currentLen == RodLength)
     {
         return;
     }
     contact.Particles[0] = Particles[0];
     contact.Particles[1] = Particles[1];
     Vector3 normal = Particles[1].Position - Particles[0].Position;
     normal.Normalize();
     if (currentLen > RodLength)
     {
         contact.ContactNormal = normal;
         contact.Penetration = currentLen - RodLength;
     }
     else
     {
         contact.ContactNormal = normal * -1;
         contact.Penetration = RodLength - currentLen;
     }
     contact.Restitution = 0;
     contacts.Add(contact);
 }
Ejemplo n.º 3
0
        public MassAggregateApplication(int particleCount)
        {
            World = new ParticleWorld(particleCount * 10);

            for (int i = 0; i < particleCount; i++)
            {
                World.Particles.Add(new Particle());
            }

            GroundContactGenerator = new GroundContacts(World.Particles);
            World.ContactGenerators.Add(GroundContactGenerator);
        }
 public void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     for (int i = 0; i < world.Particles.Count; i++)
     {
         for (int j = i + 1; j < world.Particles.Count; j++)
         {
             ParticleContact pc;
             if (getcollision(out pc, world.Particles[i], world.Particles[j]))
             {
                 contacts.Add(pc);
             }
         }
     }
 }
 public void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     for (int i = 0; i < world.Particles.Count; i++)
     {
         float y = world.Particles[i].Position.Y;
         if (y < Height)
         {
             ParticleContact c = new ParticleContact();
             c.ContactNormal = Vector3.Up;
             c.Particles[0] = world.Particles[i];
             c.Penetration = -(y - Height);
             c.Restitution = 0.8f;
             contacts.Add(c);
         }
     }
 }
Ejemplo n.º 6
0
 public override void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     float length = CurrentLength;
     if (length < MaxLength)
     {
         return;
     }
     ParticleContact contact = new ParticleContact();
     contact.Particles[0] = Particles[0];
     contact.Particles[1] = Particles[1];
     Vector3 normal = Particles[1].Position - Particles[0].Position;
     normal.Normalize();
     contact.ContactNormal = normal;
     contact.Penetration = length - MaxLength;
     contact.Restitution = Restitution;
     contacts.Add(contact);
 }
Ejemplo n.º 7
0
        public GameApplication(GameConfig game_cfg, GameWindow gameWindow)
        {
            Config = game_cfg;

            _gameWindow = gameWindow;

            Width  = Config.WindowConfig.ScreenWidth;
            Height = Config.WindowConfig.ScreenHeight;

            _timer = new GameTimer();

            world1 = new ParticleWorld(300, 16);

            respawn = new ParticleRespawn(1, 3);
            //radialWind = new ParticleWind(new ge.Vec3(100.0f, 100.0f, 0.0f), 10000.0f, 10.0f);
            //radialWind2 = new ParticleWind(new ge.Vec3(500.0f, 300.0f, 0.0f), 6000.0f, 15.0f);

            particleArray = new Particle[particleCount + freeParticles];
            for (int i = 0; i < (particleCount + freeParticles); ++i)
            {
                particleArray[i] = new Particle();
            }

            particleGravityArray = new ParticleGravity[(particleCount + freeParticles)];
            //particleGravityArray2 = new ParticleGravity[(particleCount + freeParticles)];

            for (int i = 0; i < (particleCount + freeParticles); i++)
            {
                world1.getParticles().Add(particleArray[i]);
            }

            groundContactGenerator = new GroundContact();
            groundContactGenerator.init(world1.getParticles());

            particleRods = new ParticleRod[cablesCount];

            sphereContactGenerator = new SphereContact();
            sphereContactGenerator.init(world1.getParticles());

            world1.getContactGenerators().Add(groundContactGenerator);
            world1.getContactGenerators().Add(sphereContactGenerator);
        }
Ejemplo n.º 8
0
        private void Initialize()
        {
            particles = new List <Particle>();

            //alfa
            Particle alfa = new Particle();

            alfa.Position = new Vector3(5, 0, 0);
            alfa.Mass     = 1;
            particles.Add(alfa);

            //alfa
            Particle zero = new Particle();

            zero.Position = new Vector3(0, 0, 0);
            zero.Mass     = 1;
            particles.Add(zero);

            //particleWorld
            particleWorld = new ParticleWorld(50, 50);
        }
 public void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
     for (int i = 0; i < world.Particles.Count; i++)
     {
         float y = world.Particles[i].Position.Y;
         if ((y) < ParticleRadius)
         {
             ParticleContact c = new ParticleContact();
             c.ContactNormal = Vector3.Up;
             c.Particles[0] = world.Particles[i];
             c.Penetration = -(y - ParticleRadius);
             c.Restitution = 0.8f;
             contacts.Add(c);
         }
         for (int j = i + 1; j < world.Particles.Count; j++)
         {
             ParticleContact pc;
             if (getcollision(out pc, world.Particles[i], world.Particles[j]))
             {
                 contacts.Add(pc);
             }
         }
     }
 }
Ejemplo n.º 10
0
        public void Test_ParticleSpring_Update()
        {
            Particle alfa = scenario.Particle_alfa;
            Particle zero = scenario.Particle_zero;

            alfa.Position = new Microsoft.Xna.Framework.Vector3(5, 2, 0);
            alfa.Mass     = 1;
            zero.Position = new Microsoft.Xna.Framework.Vector3(0, 2, 0);
            zero.Mass     = 1;

            ParticleWorld particleWorld = scenario.Particle_World;
            DataTable     data          = expectedData.GetParticleSpring_Data();

            particleWorld.Particles.Add(alfa);
            particleWorld.forceRegistry.Add(alfa, new SpringForce(zero, 1f, (float)Math.Abs((zero.Position - alfa.Position).Length()) * 1.5f));

            float precision            = 0.0001f;
            float duration             = 0;
            float expectedPosition     = 0;
            float expectedVelocity     = 0;
            float expectedAcceleration = 0;

            for (int i = 0; i < data.Rows.Count; i++)
            {
                duration             = float.Parse(data.Rows[i]["duration (s)"].ToString());
                expectedPosition     = float.Parse(data.Rows[i]["position (m)"].ToString());
                expectedVelocity     = float.Parse(data.Rows[i]["velocity (m/s)"].ToString());
                expectedAcceleration = float.Parse(data.Rows[i]["acceleration (m/s^2)"].ToString());

                Assert.IsTrue(alfa.Position.X.NearlyEquals(expectedPosition, precision));
                Assert.IsTrue(alfa.Velocity.X.NearlyEquals(expectedVelocity, precision));
                Assert.IsTrue(alfa.LinearAcceleration.X.NearlyEquals(expectedAcceleration, precision));

                particleWorld.RunPhysics(duration);
            }
        }
Ejemplo n.º 11
0
 public virtual void GetContacts(List<ParticleContact> contacts, ParticleWorld world)
 {
 }
Ejemplo n.º 12
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ParticleWorld obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 13
0
 public SfereContactGenerator(ParticleWorld particleWorld)
 {
     pworld = particleWorld;
 }