hyades.physics.Shape.CenterAtZero C# (CSharp) Method

CenterAtZero() public method

public CenterAtZero ( ) : void
return void
        public void CenterAtZero()
        {
            float x = 0;
            float y = 0;

            for (int i = 0; i < count; i++)
            {
                x += points[i].X;
                y += points[i].Y;
            }

            x = x / count;
            y = y / count;

            for (int i = 0; i < count; i++)
            {
                points[i].X -= x;
                points[i].Y -= y;
            }
        }

Usage Example

Example #1
0
        public void BuildWall(Plane p)
        {
            ShapeBuilder shapebuilder = new ShapeBuilder(model);

            Matrix transform = GetTransform();
            Vector2[] points = shapebuilder.GetShape(ref transform, p);

            shape = new Shape(points, false);
            offset = shape.GetCenter() - new Vector2(position.X, position.Y);
            shape.CenterAtZero();

            body = new Body(shape, float.MaxValue);
            body.position.X = position.X + offset.X;
            body.position.Y = position.Y + offset.Y;
            body.is_static = true;
            body.Update(0);
        }