public void DrawShape(cpShape shape) { cpBody body = shape.body; cpColor color = cp.GetShapeColor(shape); // ColorForBody(body); switch (shape.shapeType) { case cpShapeType.Circle: { cpCircleShape circle = (cpCircleShape)shape; if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(circle.bb); } if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(circle, color); } } break; case cpShapeType.Segment: { cpSegmentShape seg = (cpSegmentShape)shape; if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(seg.bb); } if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(seg, color); } } break; case cpShapeType.Polygon: { cpPolyShape poly = (cpPolyShape)shape; if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(poly.bb); } if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All)) { drawDelegate.Draw(poly, color); } } break; default: cp.AssertHard(false, "Bad assertion in DrawShape()"); break; } }
public static SupportPoint SegmentSupportPoint(cpSegmentShape seg, cpVect n) { if (cpVect.cpvdot(seg.ta, n) > cpVect.cpvdot(seg.tb, n)) { return(new SupportPoint(seg.ta, 0)); } else { return(new SupportPoint(seg.tb, 1)); } }
public static Edge SupportEdgeForSegment(cpSegmentShape seg, cpVect n) { ulong hashid = seg.hashid; Edge edge; if (cpVect.cpvdot(seg.tn, n) > 0.0f) { edge = new Edge( new EdgePoint(seg.ta, cp.CP_HASH_PAIR(seg.hashid, 0)), new EdgePoint(seg.tb, cp.CP_HASH_PAIR(seg.hashid, 1)), seg.r, seg.tn); } else { edge = new Edge( new EdgePoint(seg.tb, cp.CP_HASH_PAIR(seg.hashid, 1)), new EdgePoint(seg.ta, cp.CP_HASH_PAIR(seg.hashid, 0)), seg.r, cpVect.cpvneg(seg.tn) ); } return(edge); }
private void Draw(cpSegmentShape seg, cpColor color) { DrawFatSegment(seg.ta, seg.tb, seg.r, color); }
public CCPhysicsShapeEdgeChain(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1) { _type = PhysicsType.EDGECHAIN; var vecs = PhysicsHelper.CCPointsTocpVects(vec); int i = 0; for (; i < count; ++i) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vecs[i], vecs[i + 1], border); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); _info.Add(shape); } _mass = cp.Infinity; _moment = cp.Infinity; Material = material; }
public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, CCPoint offset, float border = 1) { _type = PhysicsType.EDGEBOX; List<cpVect> vec = new List<cpVect>() { new cpVect(-size.Width/2+offset.X, -size.Height/2+offset.Y), new cpVect(+size.Width/2+offset.X, -size.Height/2+offset.Y), new cpVect(+size.Width/2+offset.X, +size.Height/2+offset.Y), new cpVect(-size.Width/2+offset.X, +size.Height/2+offset.Y) }; int i = 0; for (; i < 4; ++i) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vec[i], vec[(i + 1) % 4], border); _info.Add(shape); } _offset = offset; _mass = CCPhysicsBody.MASS_DEFAULT; _moment = CCPhysicsBody.MOMENT_DEFAULT; Material = material; }
public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, PhysicsHelper.CCPointToCpVect(a), PhysicsHelper.CCPointToCpVect(b), border); _type = PhysicsType.EDGESEGMENT; _info.Add(shape); _mass = cp.Infinity; _moment = cp.Infinity; Material = material; }
public CCPhysicsShapeEdgeChain(cpVect[] vec, int count, CCPhysicsMaterial material, float border = 1) { _type = PhysicsType.EDGECHAIN; int i = 0; for (; i < count; ++i) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[i + 1], border); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); _info.add(shape); } _mass = cp.Infinity; _moment = cp.Infinity; SetMaterial(material); }
public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, float border /* = 1 */, cpVect offset) { _type = PhysicsType.EDGEBOX; List<cpVect> vec = new List<cpVect>() { new cpVect(-size.Width/2+offset.x, -size.Height/2+offset.y), new cpVect(+size.Width/2+offset.x, -size.Height/2+offset.y), new cpVect(+size.Width/2+offset.x, +size.Height/2+offset.y), new cpVect(-size.Width/2+offset.x, +size.Height/2+offset.y) }; int i = 0; for (; i < 4; ++i) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[(i + 1) % 4], border); _info.add(shape); } _offset = offset; _mass = CCPhysicsBody.MASS_DEFAULT; _moment = CCPhysicsBody.MOMENT_DEFAULT; SetMaterial(material); }
public CCPhysicsShapeEdgeSegment(cpVect a, cpVect b, CCPhysicsMaterial material, float border = 1) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), a, b, border); _type = PhysicsType.EDGESEGMENT; _info.add(shape); _mass = cp.Infinity; _moment = cp.Infinity; SetMaterial(material); }