コード例 #1
0
ファイル: PBody.cs プロジェクト: zx8326123/LGame
 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();
 }
コード例 #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--;
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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--;
 }
コード例 #6
0
ファイル: PBody.cs プロジェクト: zx8326123/LGame
 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();
 }
コード例 #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++;
 }
コード例 #8
0
ファイル: PPhysManager.cs プロジェクト: 207h2Flogintvg/LGame
		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;
		}
コード例 #9
0
ファイル: PPhysManager.cs プロジェクト: 207h2Flogintvg/LGame
		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;
		}