What if I put OnCollision here?

Sep 15, 2010 at 8:04 PM

It benefits me a lot to simply put OnCollision inside of StoreImpulses() inside of ContactSolver.

In fact, I had it in there while I was using the 3.0 beta, and after moving up to the release version

of 3.0, I still find that having it in there is more useful, and from what I can tell, faster.

To be more specific, This is where I've got it:


        public void StoreImpulses()
            for (int i = 0; i < _constraintCount; ++i)
                ContactConstraint c = Constraints[i];
                Manifold m = c.Manifold;

                for (int j = 0; j < c.PointCount; ++j)
                    var pj = m.Points[j];
                    var cp = c.Points[j];

                    pj.NormalImpulse = cp.NormalImpulse;
                    pj.TangentImpulse = cp.TangentImpulse;

                    m.Points[j] = pj;

                c.Manifold = m;
                _contacts[i].Manifold = m;

                //Oranjoose code start
                Contact tempContact = _contacts[i];
                Fixture fixA = tempContact.FixtureA;
                Fixture fixB = tempContact.FixtureB;
                if (fixA.OnCollision != null)
                    fixA.OnCollision(fixA, fixB, tempContact);
                if (fixB.OnCollision != null)
                    fixB.OnCollision(fixB, fixA, tempContact);
                //Oranjoose code stop

Having the OnCollision methods fire here gives me access to the Impulse values right here on the fly.

Any thoughts on the idea?

Sep 16, 2010 at 8:58 AM

The OnCollision delegate is similar to the BeginContact delegate, but on a per Fixture basis. If we were to move the OnCollision delegate into StoreImpulses(), it would have the following complications:

1. StoreImpulses is part of WarmStarting - newer versions of Box2D can fully disable WarmStarting.
2. The OnCollision delegate is evaluated before StoreImpulses is called. This is important because it makes it possible to disable contacts before impulses are calculated and stored for WarmStarting.
3. At the point where StoreImpulses() is called, the contact has already been created and evaluated.

Perhaps we could implement a ReportImpulse delegate that is called on a per fixture basis?

Sep 16, 2010 at 10:51 PM
Edited Sep 16, 2010 at 10:51 PM

I never really wanted to overwrite an existing and working feature, and the points you

bring up do indeed verify that the proposed change wouldn't be better for its purpose,

let alone in every way (which it would probably have to be if we were to justify replacing it).

However, I really do like the idea of adding that "ReportImpulse" delegate as a feature.

I feel there have been quite a few questions on the discussions about calculating "force"

on impact and other such inquiries.

Thanks for the reply! =)