Пример #1
0
        public static void CollisionSeparateCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world)
        {
            CCPhysicsContact contact = (CCPhysicsContact)(arb.data);

            if (contact != null)
            {
                world.CollisionSeparateCallback(contact);
            }
            //delete contact;
        }
Пример #2
0
        public virtual void CollisionSeparateCallback(CCPhysicsContact contact)
        {
            if (!contact.IsNotificationEnabled())
            {
                return;
            }

            contact.SetEventCode(EventCode.SEPERATE);
            contact.SetWorld(this);
            _scene.DispatchEvent(contact);
        }
Пример #3
0
        public virtual void CollisionPostSolveCallback(CCPhysicsContact contact)
        {
            if (!contact.IsNotificationEnabled())
            {
                return;
            }

            contact.SetEventCode(EventCode.POSTSOLVE);
            contact.SetWorld(this);
            _scene.DispatchEvent(contact);
        }
Пример #4
0
        public virtual bool CollisionPreSolveCallback(CCPhysicsContact contact)
        {
            if (!contact.IsNotificationEnabled())
            {
                (contact._contactInfo as cpArbiter).Ignore();
                return(true);
            }

            contact.SetEventCode(EventCode.PRESOLVE);
            contact.SetWorld(this);
            _scene.DispatchEvent(contact);

            return(contact.ResetResult() ? true : false);
        }
Пример #5
0
        public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world)
        {
            cpShape a, b;

            arb.GetShapes(out a, out b);

            CCPhysicsShapeInfo ita = null, itb = null;

            cp.AssertWarn(CCPhysicsShapeInfo.Map.TryGetValue(a, out ita) && CCPhysicsShapeInfo.Map.TryGetValue(b, out itb));
            if (a != null || b != null)
            {
                return(false);
            }

            CCPhysicsContact contact = new CCPhysicsContact(ita.getShape(), itb.getShape());

            arb.data             = contact;
            contact._contactInfo = arb;

            return(world.CollisionBeginCallback(contact));
        }
Пример #6
0
		public virtual void CollisionSeparateCallback(CCPhysicsContact contact)
		{
			if (!contact.IsNotificationEnabled())
			{
				return;
			}

			contact.SetEventCode(EventCode.SEPERATE);
			contact.SetWorld(this);
			_scene.DispatchEvent(contact);
		}
Пример #7
0
		public virtual void CollisionPostSolveCallback(CCPhysicsContact contact)
		{
			if (!contact.IsNotificationEnabled())
			{
				return;
			}

			contact.SetEventCode(EventCode.POSTSOLVE);
			contact.SetWorld(this);
			_scene.DispatchEvent(contact);
		}
Пример #8
0
		public virtual bool CollisionPreSolveCallback(CCPhysicsContact contact)
		{
			if (!contact.IsNotificationEnabled())
			{
				(contact._contactInfo as cpArbiter).Ignore();
				return true;
			}

			contact.SetEventCode(EventCode.PRESOLVE);
			contact.SetWorld(this);
			_scene.DispatchEvent(contact);

			return contact.ResetResult() ? true : false;
		}
Пример #9
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;

		}
Пример #10
0
		public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world)
		{

			cpShape a, b;
			arb.GetShapes(out a, out b);

			CCPhysicsShapeInfo ita = null, itb = null;
			cp.AssertWarn(CCPhysicsShapeInfo.Map.TryGetValue(a, out ita) && CCPhysicsShapeInfo.Map.TryGetValue(b, out itb));
			if (a != null || b != null)
				return false;

			CCPhysicsContact contact = new CCPhysicsContact(ita.getShape(), itb.getShape());
			arb.data = contact;
			contact._contactInfo = arb;

			return world.CollisionBeginCallback(contact);
		}
Пример #11
0
        protected void OnEvent(CCEventCustom eventC)
        {
            CCPhysicsContact contact = (CCPhysicsContact)eventC.UserData;

            // PhysicsContact) contact = dynamic_cast<PhysicsContact*>(event);


            if (contact == null)
            {
                return;
            }

            switch (contact.GetEventCode())
            {
            case EventCode.BEGIN:
            {
                bool ret = true;

                if (onContactBegin != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    contact.GenerateContactData();
                    ret = onContactBegin(contact);
                }

                contact.SetResult(ret);
                break;
            }

            case EventCode.PRESOLVE:
            {
                bool ret = true;

                if (onContactPreSolve != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    CCPhysicsContactPreSolve solve = new CCPhysicsContactPreSolve(contact._contactInfo);
                    contact.GenerateContactData();

                    ret = onContactPreSolve(contact, solve);
                }

                contact.SetResult(ret);
                break;
            }

            case EventCode.POSTSOLVE:
            {
                if (onContactPostSolve != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    CCPhysicsContactPostSolve solve = new CCPhysicsContactPostSolve(contact._contactInfo);
                    onContactPostSolve(contact, solve);
                }
                break;
            }

            case EventCode.SEPERATE:
            {
                if (onContactSeperate != null &&
                    HitTest(contact.GetShapeA(), contact.GetShapeB()))
                {
                    onContactSeperate(contact);
                }
                break;
            }

            default:
                break;
            }
        }
Пример #12
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);
        }
Пример #13
0
		public CCPhysicsContactInfo(CCPhysicsContact contact)
		{
			_contact = contact;
		}
 public CCPhysicsContactInfo(CCPhysicsContact contact)
 {
     _contact = contact;
 }