public CCPhysicsShapeEdgePolygon(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1) { _type = PhysicsType.EDGEPOLYGEN; int i = 0; var vecs = PhysicsHelper.CCPointsTocpVects(vec); for (; i < count; ++i) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody(), vecs[i], vecs[(i + 1) % count], border); if (shape == null) { break; } 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, 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; SetMaterial(material); }
//protected cpVect _offset; #endregion #region PUBLIC METHODS public CCPhysicsShapeBox(CCSize size, CCPhysicsMaterial material, float radius) { cpVect wh = PhysicsHelper.size2cpv(size); _type = PhysicsType.BOX; cpVect[] vec = { new cpVect(-wh.x / 2.0f, -wh.y / 2.0f), new cpVect(-wh.x / 2.0f, wh.y / 2.0f), new cpVect(wh.x / 2.0f, wh.y / 2.0f), new cpVect(wh.x / 2.0f, -wh.y / 2.0f) }; cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody(), 4, vec, radius); _info.Add(shape); //_offset = offset; _area = CalculateArea(); _mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area; _moment = CalculateDefaultMoment(); SetMaterial(material); }
public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset) { _type = PhysicsType.CIRCLE; cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.SharedBody(), radius, PhysicsHelper.CCPointToCpVect(offset)); _info.Add(shape); _area = CalculateArea(); _mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area; _moment = CalculateDefaultMoment(); SetMaterial(material); }
public void Init(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius) { _type = PhysicsType.POLYGEN; cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody(), count, PhysicsHelper.CCPointsTocpVects(vecs), radius); _info.Add(shape); _area = CalculateArea(); _mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area; _moment = CalculateDefaultMoment(); SetMaterial(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; SetMaterial(material); }