Determining normal impulse from a collision

Topics: Developer Forum, User Forum
Dec 26, 2011 at 5:25 AM

Hi,

I'm new to farseer, and i'm stuck on a simple problem: i have two fixtures colliding and i need to determine the normal impulse that results at the contact.

Right now I have added an OnCollision event handler:

mainBody.OnCollision += OnCollision;

private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
    // Figure out normal impulse between f1 and f2 :s
     return true;
}

Is there a simple way to determine the impulse due to a collision?

Any help would be great.

Dec 28, 2011 at 4:55 PM
You should be able to do this:
 Vector2 normal;
    
                FarseerPhysics.Common.FixedArray2<Vector2> pointlist;
                contact.GetWorldManifold(out normal,out pointlist);
Then the normal should be returned. 

 

Dec 28, 2011 at 7:51 PM

Thanks a lot for the help Fredrik! 

I see that that would return the normal between body A and body B. But I was looking for the normal impulse that results from the collision. I found this code in BreakableBody, its a PostSolve delegate:

        private void PostSolve(Contact contact, ContactConstraint impulse)
        {
            if (!Broken)
            {
                if (Parts.Contains(contact.FixtureA) || Parts.Contains(contact.FixtureB))
                {
                    float maxImpulse = 0.0f;
                    int count = contact.Manifold.PointCount;

                    for (int i = 0; i < count; ++i)
                    {
                        maxImpulse = Math.Max(maxImpulse, impulse.Points[i].NormalImpulse);
                    }

                    if (maxImpulse > Strength)
                    {
                        // Flag the body for breaking.
                        _break = true;
                    }
                }
            }
        }
I will be using something similar.