Exemple #1
0
            public static Edge SupportEdgeForPoly(cpPolyShape poly, cpVect n)
            {
                ulong count = (ulong)poly.Count;

                ulong i1 = cpCollision.PolySupportPointIndex(poly.Count, poly.planes, n);

                // TODO get rid of mod eventually, very expensive on ARM
                ulong i0 = (ulong)((i1 - 1 + count) % count);
                ulong i2 = (ulong)((i1 + 1) % count);

                cpSplittingPlane[] planes = poly.planes;
                ulong hashid = poly.hashid;

                if (cpVect.cpvdot(n, planes[i1].n) > cpVect.cpvdot(n, planes[i2].n))
                {
                    Edge edge = new Edge(

                        new EdgePoint(planes[i0].v0, cp.CP_HASH_PAIR(hashid, i0)),
                        new EdgePoint(planes[i1].v0, cp.CP_HASH_PAIR(hashid, i1)),

                        poly.r, poly.planes[i1].n);

                    return(edge);
                }
                else
                {
                    Edge edge = new Edge(

                        new EdgePoint(planes[i1].v0, cp.CP_HASH_PAIR(hashid, i1)),
                        new EdgePoint(planes[i2].v0, cp.CP_HASH_PAIR(hashid, i2)),
                        poly.r, poly.planes[i2].n);

                    return(edge);
                }
            }
Exemple #2
0
        public void Draw(cpPolyShape poly, cpColor color)
        {
            cpColor fill = new cpColor(color);

            fill.a = cp.cpflerp(color.a, 1.0f, 0.5f);
            DrawPolygon(poly.GetVertices(), poly.Count, fill, 0.5f, color);
        }
Exemple #3
0
        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))
                {
                    Draw(circle.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    Draw(circle, color);
                }
            }
            break;

            case cpShapeType.Segment:
            {
                cpSegmentShape seg = (cpSegmentShape)shape;
                if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    Draw(seg.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    Draw(seg, color);
                }
            }
            break;

            case cpShapeType.Polygon:
            {
                cpPolyShape poly = (cpPolyShape)shape;
                if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    Draw(poly.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    Draw(poly, color);
                }
            }
            break;

            default:
                cp.AssertHard(false, "Bad assertion in DrawShape()");
                break;
            }
        }
		public void Draw(cpPolyShape poly, cpColor color)
		{
			cpColor fill = new cpColor(color);
			fill.a = cp.cpflerp(color.a, 1.0f, 0.5f);
			DrawPolygon(poly.GetVertices(), poly.Count, fill, 0.5f, color);
		}
		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;

		}
		//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();

			Material = material;

		}
Exemple #7
0
		public void Init(cpVect[] vecs, int count, CCPhysicsMaterial material, float radius)
		{
			_type = PhysicsType.POLYGEN;

			cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), count, vecs, radius);


			_info.add(shape);

			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			SetMaterial(material);

		}
Exemple #8
0
            public static SupportPoint PolySupportPoint(cpPolyShape poly, cpVect n)
            {
                ulong i = PolySupportPointIndex(poly.Count, poly.planes, n);

                return(new SupportPoint(poly.planes[i].v0, i));
            }