Exemplo n.º 1
0
 private CollisionData ManageCollisions(CollisionDetector detect, ICollideable left, ICollideable right, float duration)
 {
     CollisionData data = new CollisionData();
     data.restitution = this.Restitution;
     data.friction = this.Friction;
     detect.FindContacts(left.GeometryData.Prim, right.GeometryData.Prim, data);
     return data;
 }
Exemplo n.º 2
0
        private void PumpCollisions(float duration)
        {
            List<ICollideable> colliders = this.ICollideables;

            IEnumerable<ICollideable> gameObjectsLeft = colliders;
            IEnumerable<ICollideable> gameObjectsRight = colliders;

            CollisionDetector detect = new CollisionDetector();
            List<Contact> contacts = new List<Contact>();
            foreach (ICollideable left in gameObjectsLeft)
            {
                foreach (ICollideable right in gameObjectsRight)
                {
                    if (left != right)
                    {

                        CollisionData data = ManageCollisions(detect, left, right, duration);
                        contacts.AddRange(data.contacts);

                    }
                }
            }

            ContactResolver.FullContactResolution(contacts, duration);
            if (this.CaptureBodyContacts)
            {

                foreach (Contact contact in contacts)
                {
                    if (contact.Bodies[1] != null)
                    {
                        captured.Add(contact);
                    }
                }
            }
            if (contacts.Count > 0)
            {
                saveLastContact(contacts[0]);
            }
        }
        public void IntersectionTests_SphereVsSphere_Overlapping()
        {
            Vector3 sphereOnePosition = new Vector3(0.5f, 0f, 0f);
            IRigidBody sphereOneBody = new NoBody(Matrix.CreateTranslation(sphereOnePosition));

            float sphereOneRadius = 1f;
            Matrix sphereOneMatrix = Matrix.Identity;
            Sphere sphereOne = new Sphere(sphereOneBody, sphereOneMatrix, sphereOneRadius);

            Vector3 sphereTwoPosition = Vector3.UnitX;
            IRigidBody sphereTwoBody = new NoBody(Matrix.CreateTranslation(sphereTwoPosition));

            float sphereTwoRadius = 1f;
            Matrix sphereTwoMatrix = Matrix.Identity;
            Sphere sphereTwo = new Sphere(sphereTwoBody, sphereTwoMatrix, sphereTwoRadius);

            CollisionDetector detect = new CollisionDetector();

            CollisionData data = new CollisionData();
            Assert.AreEqual(1, IntersectionTests.sphereAndSphere(sphereOne, sphereTwo, data), "How many contacts?");

            Contact contact;

            Assert.NotNull(data.contacts, "Contacts Container");
            Assert.AreEqual(1, data.contacts.Count, "One Contact Expected");
            contact = data.contacts[0];
            Assert.AreEqual(0, contact.Friction, "0 friction");
            Assert.AreEqual(1f, contact.Restitution, "1 restitution");
            Assert.AreEqual(1.5f, contact.Penetration, "0 penetration (surface collision)");
            Assert.AreEqual(new Vector3(0.75f, 0f, 0f), contact.Point, "expected contact point");
            Assert.AreEqual(-Vector3.UnitX, contact.Normal, "expected contact normal");

            //Assymetric

            data = new CollisionData();

            IntersectionTests.sphereAndSphere(sphereTwo, sphereOne, data);
            Assert.NotNull(data.contacts, "Contacts Container");
            Assert.AreEqual(1, data.contacts.Count, "One Contact Expected");
            contact = data.contacts[0];
            Assert.AreEqual(0, contact.Friction, "0 friction");
            Assert.AreEqual(1f, contact.Restitution, "1 restitution");
            Assert.AreEqual(1.5f, contact.Penetration, "0 penetration (surface collision)");
            Assert.AreEqual(new Vector3(0.75f, 0f, 0f), contact.Point, "expected contact point");
            Assert.AreEqual(Vector3.UnitX, contact.Normal, "expected contact normal");
        }