示例#1
0
        public virtual bool CollisionBeginCallback(CCPhysicsContact contact)
        {
            bool ret = true;

            CCPhysicsShape shapeA = contact.GetShapeA();
            CCPhysicsShape shapeB = contact.GetShapeB();

            CCPhysicsBody bodyA = shapeA.Body;
            CCPhysicsBody bodyB = shapeB.Body;

            List <CCPhysicsJoint> jointsA = bodyA.GetJoints();

            // check the joint is collision enable or not
            foreach (CCPhysicsJoint joint in jointsA)
            {
                if (!Joints.Exists(j => j == joint))
                {
                    continue;
                }

                if (!joint.IsCollisionEnabled())
                {
                    CCPhysicsBody body = joint.BodyA == bodyA ? joint.BodyB : joint.BodyA;

                    if (body == bodyB)
                    {
                        contact.SetNotificationEnable(false);
                        return(false);
                    }
                }
            }

            // bitmask check
            if ((shapeA.CategoryBitmask & shapeB.ContactTestBitmask) == 0 ||
                (shapeA.ContactTestBitmask & shapeB.CategoryBitmask) == 0)
            {
                contact.SetNotificationEnable(false);
            }

            if (shapeA.Group != 0 && shapeA.Group == shapeB.Group)
            {
                ret = shapeA.Group > 0;
            }
            else
            {
                if ((shapeA.CategoryBitmask & shapeB.CollisionBitmask) == 0 ||
                    (shapeB.CategoryBitmask & shapeA.CollisionBitmask) == 0)
                {
                    ret = false;
                }
            }

            if (contact.IsNotificationEnabled())
            {
                contact.SetEventCode(EventCode.BEGIN);
                contact.SetWorld(this);

                Scene.DispatchEvent(contact);
            }


            return(ret ? contact.ResetResult() : false);
        }