예제 #1
0
        public void Report(b2ContactVelocityConstraint[] constraints)
        {
            if (m_listener == null)
            {
                return;
            }

            b2ContactImpulse impulse = b2ContactImpulse.Create();

            for (int i = 0; i < m_contactCount; ++i)
            {
                b2Contact c = m_contacts[i];

                b2ContactVelocityConstraint vc = constraints[i];

                impulse.count = vc.pointCount;
                for (int j = 0; j < vc.pointCount; ++j)
                {
                    impulse.normalImpulses[j]  = vc.points[j].normalImpulse;
                    impulse.tangentImpulses[j] = vc.points[j].tangentImpulse;
                }

                m_listener.PostSolve(c, ref impulse);
            }
        }
예제 #2
0
 public static b2ContactImpulse Create()
 {
     b2ContactImpulse b = new b2ContactImpulse();
     b.normalImpulses = new float[b2Settings.b2_maxManifoldPoints];
     b.tangentImpulses = new float[b2Settings.b2_maxManifoldPoints];
     b.count = 0;
     return (b);
 }
예제 #3
0
        public static b2ContactImpulse Create()
        {
            b2ContactImpulse b = new b2ContactImpulse();

            b.normalImpulses  = new float[b2Settings.b2_maxManifoldPoints];
            b.tangentImpulses = new float[b2Settings.b2_maxManifoldPoints];
            b.count           = 0;
            return(b);
        }
예제 #4
0
        public override void PostSolve(b2Contact contact, ref b2ContactImpulse impulse)
        {
            if (m_broke)
            {
                // The body already broke.
                return;
            }

            // Should the body break?
            int count = contact.GetManifold().pointCount;

            float maxImpulse = 0.0f;
            for (int i = 0; i < count; ++i)
            {
                maxImpulse = Math.Max(maxImpulse, impulse.normalImpulses[i]);
            }

            if (maxImpulse > 40.0f)
            {
                // Flag the body for breaking.
                m_break = true;
            }
        }
예제 #5
0
 /// <summary>
 /// This lets you inspect a contact after the solver is finished. This is useful
 /// for inspecting impulses.
 /// Note: the contact manifold does not include time of impact impulses, which can be
 /// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
 /// in a separate data structure.
 /// Note: this is only called for contacts that are touching, solid, and awake.
 /// </summary>
 public abstract void PostSolve(b2Contact contact, ref b2ContactImpulse impulse);
예제 #6
0
 /// <summary>
 /// This lets you inspect a contact after the solver is finished. This is useful
 /// for inspecting impulses.
 /// Note: the contact manifold does not include time of impact impulses, which can be
 /// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
 /// in a separate data structure.
 /// Note: this is only called for contacts that are touching, solid, and awake.
 /// </summary>
 public abstract void PostSolve(b2Contact contact, ref b2ContactImpulse impulse);
예제 #7
0
 public override void PostSolve(b2Contact contact, ref b2ContactImpulse impulse)
 {
 }
예제 #8
0
 public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse)
 {
 }
예제 #9
0
 /**
  * This lets you inspect a contact after the solver is finished. This is useful
  * for inspecting impulses.
  * Note: the contact manifold does not include time of impact impulses, which can be
  * arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
  * in a separate data structure.
  * Note: this is only called for contacts that are touching, solid, and awake.
  */
 virtual public void PostSolve(b2Contact contact, b2ContactImpulse impulse)
 {
 }
예제 #10
0
 public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse)
 {
     // CCLog.Log("Post solve: {0} vs {1}", contact.FixtureA.Body.BodyType, contact.FixtureB.Body.BodyType);
 }
예제 #11
0
 /// <summary>
 /// This lets you inspect a contact after the solver is finished. This is useful
 /// for inspecting impulses.
 /// Note: the contact manifold does not include time of impact impulses, which can be
 /// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
 /// in a separate data structure.
 /// Note: this is only called for contacts that are touching, solid, and awake.
 /// </summary>
 public virtual void PostSolve(b2Contact contact, b2ContactImpulse impulse)
 {
 }
예제 #12
0
 public override void PostSolve(b2Contact contact, ref b2ContactImpulse impulse)
 {
     //throw new NotImplementedException ();
 }
예제 #13
0
 public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse)
 {
     //throw new NotImplementedException();
 }
        public void PostSolve(b2Contact contact, b2ContactImpulse impulse)
        {
            // http://stackoverflow.com/questions/11149091/box2d-damage-physics

            //M:\web\FlashHeatZeekerWithStarlingB2\XContactListener.as(34): col: 83 Error: Implicit coercion of a value of type __AS3__.vec:Vector.<Number> to an unrelated type __AS3__.vec:Vector.<*>.

            //double0 = __Enumerable.Sum_100669321(X.AsEnumerable_100664676(impulse.normalImpulses));

            // http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-6-collision-strength/
            var forceA = impulse.normalImpulses[0];
            // { impulse = { length = 2, forceA = 2.9642496469208197, forceB = 0 } }

            var forceB = impulse.normalImpulses[1];

            if (DiscardSmallImpulse)
                if (forceA < 0.5)
                    if (forceB < 0.5)
                    {
                        // do we care about friction?
                        return;
                    }

            //var min = impulse.normalImpulses.AsEnumerable().Min();
            //var max = impulse.normalImpulses.AsEnumerable().Max();

            //            System.Linq.Enumerable for Double Min(System.Collections.Generic.IEnumerable`1[System.Double]) used at
            //FlashHeatZeekerWithStarlingB2.XContactListener.PostSolve at offset 001d.

            var done = false;

            var fixA = contact.GetFixtureA();
            if (fixA != null)
            {
                var hitA = fixA.GetUserData() as Action<double>;
                if (hitA != null)
                {
                    //Console.WriteLine(new
                    //{
                    //    hitA = new
                    //    {
                    //        forceA,
                    //    }
                    //});

                    hitA(forceA);
                    done = true;
                }
            }

            var fixB = contact.GetFixtureB();
            if (fixB != null)
            {
                var hitB = fixB.GetUserData() as Action<double>;
                if (hitB != null)
                {
                    //Console.WriteLine(new
                    //{
                    //    hitB = new
                    //    {
                    //        forceA,
                    //    }
                    //});

                    hitB(forceA);
                    done = true;
                }
            }

            if (done) return;

            Console.WriteLine(new
            {
                impulse = new
                {
                    impulse.normalImpulses.length,
                    forceA,
                    fixA,
                    forceB,
                    fixB
                    //, min, max 
                }
            });
        }