public override bool HitTest(CCPhysicsShape shapeA, CCPhysicsShape shapeB) { if (shapeA.GetGroup() == _group || shapeB.GetGroup() == _group) { return(true); } return(false); }
/* * @brief add a shape to body * @param shape the shape to be added * @param addMassAndMoment if this is true, the shape's mass and moment will be added to body. the default is true */ public virtual CCPhysicsShape AddShape(CCPhysicsShape shape, bool addMassAndMoment = true) { if (shape == null) { return(null); } // add shape to body if (!_shapes.Exists((s) => s == shape)) { shape.SetBody(this); // calculate the area, mass, and desity // area must update before mass, because the density changes depend on it. if (addMassAndMoment) { _area += shape.GetArea(); AddMass(shape.GetMass()); AddMoment(shape.GetMoment()); } if (_world != null) { _world.AddShape(shape); } _shapes.Add(shape); if (_group != cp.NO_GROUP && shape.GetGroup() == cp.NO_GROUP) { shape.SetGroup(_group); } } return(shape); }
/* * @brief add a shape to body * @param shape the shape to be added * @param addMassAndMoment if this is true, the shape's mass and moment will be added to body. the default is true */ public virtual CCPhysicsShape AddShape(CCPhysicsShape shape, bool addMassAndMoment = true) { if (shape == null) return null; // add shape to body if (!_shapes.Exists((s) => s == shape)) { shape.SetBody(this); // calculate the area, mass, and desity // area must update before mass, because the density changes depend on it. if (addMassAndMoment) { _area += shape.GetArea(); AddMass(shape.GetMass()); AddMoment(shape.GetMoment()); } if (_world != null) { _world.AddShape(shape); } _shapes.Add(shape); if (_group != cp.NO_GROUP && shape.GetGroup() == cp.NO_GROUP) { shape.SetGroup(_group); } } return shape; }
public override bool HitTest(CCPhysicsShape shapeA, CCPhysicsShape shapeB) { if (shapeA.GetGroup() == _group || shapeB.GetGroup() == _group) { return true; } return false; }
//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); }