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; Material = material; }
public static float CalculateMoment(float mass, CCPoint[] vecs, int count, CCPoint offset) { float moment = mass == cp.Infinity ? cp.Infinity : cp.MomentForPoly(mass, count, PhysicsHelper.CCPointsTocpVects(vecs), PhysicsHelper.CCPointToCpVect(offset), 0.0f); return(moment); }
/** move the points to the center */ public static void RecenterPoints(CCPoint[] points, int count, CCPoint center) { var cpPoints = PhysicsHelper.CCPointsTocpVects(points); cp.RecenterPoly(count, cpPoints); points = PhysicsHelper.cpVectsTpCCPoints(cpPoints); if (center != CCPoint.Zero) { for (int i = 0; i < points.Length; ++i) { points[i] += center; } } }
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(); Material = material; }
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.getSharedBody(), vecs[i], vecs[i + 1], border); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); _info.add(shape); } _mass = cp.Infinity; _moment = cp.Infinity; SetMaterial(material); }
/** get center of the polyon points */ public static CCPoint GetPolygonCenter(CCPoint[] points, int count) { return(PhysicsHelper.cpVectToCCPoint(cp.CentroidForPoly(count, PhysicsHelper.CCPointsTocpVects(points)))); }