Example #1
0
 public PBody(float angle, bool fixate, PShape[] ss)
 {
     pos        = new Vector2f();
     vel        = new Vector2f();
     correctVel = new Vector2f();
     mAng       = new PTransformer();
     aabb       = new AABB();
     ang        = angle;
     numShapes  = ss.Length;
     shapes     = new PShape[1024];
     for (int i_0 = 0; i_0 < numShapes; i_0++)
     {
         shapes[i_0]         = ss[i_0];
         shapes[i_0]._parent = this;
         if (shapes[i_0]._type == PShapeType.CONCAVE_SHAPE)
         {
             PConcavePolygonShape cp = (PConcavePolygonShape)shapes[i_0];
             for (int j = 0; j < cp.numConvexes; j++)
             {
                 cp.convexes[j]._parent = this;
             }
         }
     }
     fix = fixate;
     CalcMassData();
 }
Example #2
0
 private void RemoveBody(int index)
 {
     for (int i = 0; i < bodies[index].numShapes; i++)
     {
         PShape s = bodies[index].shapes[i];
         if (s._type == PShapeType.CONCAVE_SHAPE)
         {
             PConcavePolygonShape c = (PConcavePolygonShape)s;
             for (int j = 0; j < c.numConvexes; j++)
             {
                 c.convexes[j]._rem = true;
             }
         }
         else
         {
             s._rem = true;
         }
     }
     if (index != numBodies - 1)
     {
         System.Array.Copy((bodies), index + 1, (bodies), index, numBodies
                           - index - 1);
     }
     numBodies--;
 }
Example #3
0
        public PBody Polygon(bool fix, float[] xs, float[] ys, int num,
                             float angle, float density)
        {
            if (num < 3)
            {
                return(null);
            }
            if (xs.Length != num)
            {
                xs = CollectionUtils.CopyOf(xs, num);
            }
            if (ys.Length != num)
            {
                ys = CollectionUtils.CopyOf(ys, num);
            }
            for (int i = 0; i < num; i++)
            {
                xs[i] /= scale;
                ys[i] /= scale;
            }
            PConcavePolygonShape shape = new PConcavePolygonShape(xs, ys, density);
            PBody body = new PBody(angle, fix, new PShape[] { shape });

            return(body);
        }
Example #4
0
        public PBody Polygon(bool fix, Polygon p, float angle, float density)
        {
            PPolygon             tmp   = p.GetPPolygon(this.scale);
            PConcavePolygonShape shape = new PConcavePolygonShape(tmp.xs, tmp.ys,
                                                                  density);
            PBody body = new PBody(angle, fix, new PShape[] { shape });

            return(body);
        }
Example #5
0
 private void RemoveShape(int index)
 {
     if (shapes[index]._type == PShapeType.CONCAVE_SHAPE)
     {
         PConcavePolygonShape c = (PConcavePolygonShape)shapes[index];
         for (int i = 0; i < c.numConvexes; i++)
         {
             c.convexes[i]._rem = true;
         }
     }
     shapes[index]._sapAABB.Remove();
     if (index != numShapes - 1)
     {
         System.Array.Copy((shapes), index + 1, (shapes), index, numShapes
                           - index - 1);
     }
     numShapes--;
 }
Example #6
0
 public void AddShape(PShape s)
 {
     if (w != null)
     {
         w.AddShape(s);
     }
     shapes[numShapes] = s;
     s._localPos.SubLocal(pos);
     s._parent = this;
     if (s._type == PShapeType.CONCAVE_SHAPE)
     {
         PConcavePolygonShape cp = (PConcavePolygonShape)s;
         for (int i_0 = 0; i_0 < cp.numConvexes; i_0++)
         {
             cp.convexes[i_0]._parent = this;
         }
     }
     numShapes++;
     CalcMassData();
 }
Example #7
0
 internal void AddShape(PShape s)
 {
     if (s._type == PShapeType.CONCAVE_SHAPE)
     {
         PConcavePolygonShape c = (PConcavePolygonShape)s;
         for (int i = 0; i < c.numConvexes; i++)
         {
             AddShape(((PShape)(c.convexes[i])));
         }
         return;
     }
     if (numShapes + 1 >= shapes.Length)
     {
         shapes = (PShape[])CollectionUtils.CopyOf(shapes,
                                                   shapes.Length * 2);
     }
     shapes[numShapes] = s;
     s._sapAABB.Set(sap, s, s._aabb);
     numShapes++;
 }
Example #8
0
		public PBody Polygon(bool fix, Polygon p, float angle, float density) {
			PPolygon tmp = p.GetPPolygon(this.scale);
			PConcavePolygonShape shape = new PConcavePolygonShape(tmp.xs, tmp.ys,
					density);
			PBody body = new PBody(angle, fix, new PShape[] { shape });
			return body;
		}
Example #9
0
		public PBody Polygon(bool fix, float[] xs, float[] ys, int num,
				float angle, float density) {
			if (num < 3) {
				return null;
			}
			if (xs.Length != num) {
				xs = CollectionUtils.CopyOf(xs, num);
			}
			if (ys.Length != num) {
				ys = CollectionUtils.CopyOf(ys, num);
			}
			for (int i = 0; i < num; i++) {
				xs[i] /= scale;
				ys[i] /= scale;
			}
			PConcavePolygonShape shape = new PConcavePolygonShape(xs, ys, density);
			PBody body = new PBody(angle, fix, new PShape[] { shape });
			return body;
		}