Ejemplo n.º 1
0
        protected void AddPoly(Body body2Body, V2DShape polygon)
        {
            Shape shape;

            if (polygon.IsCircle)
            {
                CircleShape circDef = new CircleShape();
                circDef._radius = polygon.Radius / (V2DScreen.WorldScale * State.Scale.X);
                Vector2 lp = new Vector2(polygon.CenterX / V2DScreen.WorldScale, polygon.CenterY / V2DScreen.WorldScale);
                circDef._p = lp;
                shape      = circDef;
            }
            else
            {
                float[]      pts     = polygon.Data;
                PolygonShape polyDef = new PolygonShape();
                shape = polyDef;
                int       len = (int)(pts.Length / 2);
                Vector2[] v2s = new Vector2[len];

                for (int i = 0; i < len; i++)
                {
                    float px = pts[i * 2];
                    float py = pts[i * 2 + 1];

                    v2s[i] = new Vector2(
                        px / V2DScreen.WorldScale * State.Scale.X,
                        py / V2DScreen.WorldScale * State.Scale.Y);
                }
                polyDef.Set(v2s, len);
            }

            FixtureDef fd = new FixtureDef();

            fd.shape = shape;

            if (instanceName.IndexOf("s_") == 0)
            {
                isStatic   = true;
                fd.density = 0.0f;
            }
            else
            {
                fd.density = density;
            }
            fd.friction    = friction;
            fd.restitution = restitution;

            if (groupIndex != 0)
            {
                fd.filter.groupIndex = groupIndex;
            }

            if (attributeProperties != null)
            {
                attributeProperties.ApplyAttribtues(fd);
            }

            body.CreateFixture(fd);
        }
Ejemplo n.º 2
0
        protected void AddPoly(Body body2Body, V2DShape polygon)
        {
            Shape shape;
            if (polygon.IsCircle)
            {
                CircleShape circDef = new CircleShape();
                circDef._radius = polygon.Radius / (V2DScreen.WorldScale * State.Scale.X);
                Vector2 lp = new Vector2(polygon.CenterX / V2DScreen.WorldScale, polygon.CenterY / V2DScreen.WorldScale);
                circDef._p = lp;
                shape = circDef;
            }
            else
            {
                float[] pts = polygon.Data;
                PolygonShape polyDef = new PolygonShape();
                shape = polyDef;
                int len= (int)(pts.Length / 2);
                Vector2[] v2s = new Vector2[len];

                for (int i = 0; i < len; i++)
                {
                    float px = pts[i * 2];
                    float py = pts[i * 2 + 1];

                    v2s[i] = new Vector2(
                        px / V2DScreen.WorldScale * State.Scale.X,
                        py / V2DScreen.WorldScale * State.Scale.Y);
                }
                polyDef.Set(v2s, len);
            }

            FixtureDef fd = new FixtureDef();
            fd.shape = shape;

            if (instanceName.IndexOf("s_") == 0)
            {
                isStatic = true;
                fd.density = 0.0f;
            }
            else
            {
                fd.density = density;
            }
            fd.friction = friction;
            fd.restitution = restitution;

            if (groupIndex != 0)
            {
                fd.filter.groupIndex = groupIndex;
            }

            if (attributeProperties != null)
            {
                attributeProperties.ApplyAttribtues(fd);
            }

            body.CreateFixture(fd);
        }
Ejemplo n.º 3
0
 public override V2DShape GetV2DShape()
 {
     V2DShape result = new V2DShape();
     float[] pts = new float[Points.Count * 2];
     for (int i = 0; i < Points.Count; i++)
     {
         pts[i * 2] = Points[i].X;
         pts[i * 2 + 1] = Points[i].Y;
     }
     result.Data = pts;
     result.EnsureClockwise();
     //List<Vector2> pts = new List<Vector2>();
     //for (int i = 0; i < Points.Count; i++)
     //{
     //    pts.Add(new Vector2(Points[i].X, Points[i].Y));
     //}
     //result.Data = pts.ToArray();
     result.IsCircle = false;
     return result;
 }