public override void DetectAllCollisions(List<Body> bodies, CollisionFunctor collisionFunctor, CollisionSkinPredicate2 collisionPredicate, float collTolerance)
        {
            int numSkins = skins.Count;
            int numBodies = bodies.Count;

            CollDetectInfo info = new CollDetectInfo();

            for (int ibody = 0; ibody < numBodies; ++ibody)
            {
                Body body = bodies[ibody];
                if(!body.IsActive)
                    continue;

                info.Skin0 = body.CollisionSkin;
                if (info.Skin0 == null)
                    continue;

                for (int skin = 0; skin < numSkins; ++skin)
                {
                    info.Skin1 = skins[skin];
                    if (info.Skin0 == info.Skin1)
                        continue;

                    // CHANGE
                    if (info.Skin1 == null)
                        continue;

                    bool skinSleeping = true;

                    if (info.Skin1.Owner != null && info.Skin1.Owner.IsActive)
                        skinSleeping = false;

                    if ((skinSleeping == false) && (info.Skin1.ID < info.Skin0.ID))
                        continue;

                    if((collisionPredicate != null) &&
                        collisionPredicate.ConsiderSkinPair(info.Skin0,info.Skin1) == false)
                    continue;

                    // basic bbox test
                    if(BoundingBoxHelper.OverlapTest(ref info.Skin0.WorldBoundingBox,
                        ref info.Skin1.WorldBoundingBox,collTolerance))
                    {
                        if (CheckCollidables(info.Skin0,info.Skin1))
                        {
                            int bodyPrimitives = info.Skin0.NumPrimitives;
                            int primitves = info.Skin1.NumPrimitives;

                            for(info.IndexPrim0 = 0; info.IndexPrim0 < bodyPrimitives; ++info.IndexPrim0)
                            {
                                for (info.IndexPrim1 = 0; info.IndexPrim1 < primitves; ++info.IndexPrim1)
                                {
                                    DetectFunctor f = GetCollDetectFunctor(info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0).Type,
                                        info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1).Type);
                                    if (f != null)
                                        f.CollDetect(info, collTolerance, collisionFunctor);
                                }
                            }
                        }
                    } // overlapt test
                } // loop over skins
            } // loop over bodies
        }
        public override void DetectAllCollisions(List<Body> bodies, CollisionFunctor collisionFunctor, CollisionSkinPredicate2 collisionPredicate, float collTolerance)
        {
            int numBodies = bodies.Count;

            CollDetectInfo info = new CollDetectInfo();

            for (int iBody = 0; iBody < numBodies; ++iBody)
            {
                Body body = bodies[iBody];
                if (!body.IsActive)
                    continue;

                info.Skin0 = body.CollisionSkin;
                if (info.Skin0 == null)
                    continue;

                tempGridLists.Clear();
                GetListsToCheck(tempGridLists, info.Skin0);

                for (int iList = tempGridLists.Count; iList-- != 0; )
                {
                    // first one is a placeholder;
                    GridEntry entry = tempGridLists[iList];
                    for (entry = entry.Next; entry != null; entry = entry.Next)
                    {
                        info.Skin1 = entry.Skin;
                        if (info.Skin1 == info.Skin0)
                            continue;

                        // CHANGE
                        if (info.Skin1 == null)
                            continue;

                        bool skinSleeping = true;

                        if ((info.Skin1.Owner != null) && (info.Skin1.Owner.IsActive))
                            skinSleeping = false;

                        // only do one per pair
                        if ((skinSleeping == false) && (info.Skin1.ID < info.Skin0.ID))
                             continue;

                        if ((collisionPredicate != null) && (!collisionPredicate.ConsiderSkinPair(info.Skin0, info.Skin1)))
                            continue;

                        // basic bbox test
                        if (BoundingBoxHelper.OverlapTest(ref info.Skin1.WorldBoundingBox,
                            ref info.Skin0.WorldBoundingBox, collTolerance))
                        {
                            if (CheckCollidables(info.Skin0, info.Skin1))
                            {
                                int bodyPrimitives = info.Skin0.NumPrimitives;
                                int primitves = info.Skin1.NumPrimitives;

                                for (info.IndexPrim0 = 0; info.IndexPrim0 < bodyPrimitives; ++info.IndexPrim0)
                                {
                                    for (info.IndexPrim1 = 0; info.IndexPrim1 < primitves; ++info.IndexPrim1)
                                    {
                                        DetectFunctor f = GetCollDetectFunctor(info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0).Type,
                                            info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1).Type);
                                        if (f != null)
                                            f.CollDetect(info, collTolerance, collisionFunctor);
                                    }
                                }
                            } // check collidables
                        } // overlapt test
                    }// loop over entries
                } // loop over lists
            } // loop over bodies
        }