예제 #1
0
        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;
        }
예제 #2
0
        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);
        }
예제 #3
0
        /** 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;
                }
            }
        }
예제 #4
0
        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;
        }
예제 #5
0
        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);
        }
예제 #6
0
 /** get center of the polyon points */
 public static CCPoint GetPolygonCenter(CCPoint[] points, int count)
 {
     return(PhysicsHelper.cpVectToCCPoint(cp.CentroidForPoly(count, PhysicsHelper.CCPointsTocpVects(points))));
 }