예제 #1
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))
                {
                    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;
            }
        }
예제 #2
0
 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));
     }
 }
예제 #3
0
            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);
            }
예제 #4
0
		private void Draw(cpSegmentShape seg, cpColor color)
		{
			DrawFatSegment(seg.ta, seg.tb, seg.r, color);
		}
예제 #5
0
 private void Draw(cpSegmentShape seg, cpColor color)
 {
     DrawFatSegment(seg.ta, seg.tb, seg.r, color);
 }
예제 #6
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.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;
		}
예제 #7
0
        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;
		}
예제 #8
0
		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;
		}
예제 #9
0
		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);
		}
예제 #10
0
		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);
		}
예제 #11
0
		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);
		}