Exemple #1
0
        //public void Draw()
        //{
        //	if (DebugDrawMask != cpDrawFlags.None)
        //	{
        //		_debugDraw.Begin();
        //		_info.getSpace().DrawDebugData();
        //		_debugDraw.End();
        //	}
        //}


        //public virtual void DebugDraw()
        //{

        //	if (_debugDraw == null)
        //	{
        //		_debugDraw = new PhysicsDebugDraw(this);
        //	}

        //	if (_debugDraw != null && _bodies.Count > 0)
        //	{
        //		if (_debugDraw.Begin())
        //		{
        //			if (DebugDrawMask == cpDrawFlags.ALL || DebugDrawMask == cpDrawFlags.Shape)
        //			{
        //				foreach (CCPhysicsBody body in _bodies)
        //				{

        //					if (!body.IsEnabled())
        //					{
        //						continue;
        //					}

        //					foreach (CCPhysicsShape shape in body.GetShapes())
        //					{
        //						_debugDraw.DrawShape(shape);

        //					}
        //				}
        //			}

        //			if (DebugDrawMask == cpDrawFlags.ALL || DebugDrawMask == cpDrawFlags.Joint)
        //			{
        //				foreach (CCPhysicsJoint joint in _joints)
        //				{
        //					_debugDraw.DrawJoint(joint);
        //				}
        //			}

        //			_debugDraw.End();
        //		}
        //	}

        //}

        public virtual bool CollisionBeginCallback(CCPhysicsContact contact)
        {
            bool ret = true;

            CCPhysicsShape        shapeA  = contact.GetShapeA();
            CCPhysicsShape        shapeB  = contact.GetShapeB();
            CCPhysicsBody         bodyA   = shapeA.GetBody();
            CCPhysicsBody         bodyB   = shapeB.GetBody();
            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.GetBodyA() == bodyA?joint.GetBodyB() : joint.GetBodyA();

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

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

            if (shapeA.GetGroup() != 0 && shapeA.GetGroup() == shapeB.GetGroup())
            {
                ret = shapeA.GetGroup() > 0;
            }
            else
            {
                if ((shapeA.GetCategoryBitmask() & shapeB.GetCollisionBitmask()) == 0 ||
                    (shapeB.GetCategoryBitmask() & shapeA.GetCollisionBitmask()) == 0)
                {
                    ret = false;
                }
            }

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

                _scene.DispatchEvent(contact);
            }


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