This project has moved and is read-only. For the latest updates, please go here.

Problem converting Silverlight app from FS 2.1 to 3.1

Topics: Developer Forum
Nov 19, 2010 at 8:49 PM

Hi All,

I'm trying to move over to Farseer 3.1 but I have some problems.

After converting to Farseer 3.1 my polygons are acting very strange.

After I create my polygon and i push it with force or rotates it something goes wrong.

For instance if I ApplyTorque it does not only start to rotate but it also starts to move.

Does Farseer 3.1 work differently with polygons than 2.1?

This is the code that I'm using to create the polygon (can find why it should behave strange?):

 //Scale image
            ScaleTransform st = new ScaleTransform();
            st.ScaleX = scaleX;
            st.ScaleY = scaleY;

            //Create an array to hold the data from the texture
            uint[] data = new uint[(int)(image.ActualWidth * st.ScaleX) * (int)(image.ActualHeight *st.ScaleY)];

            WriteableBitmap wb = new WriteableBitmap((int)(image.ActualWidth * st.ScaleX), (int)(image.ActualHeight * st.ScaleY));

            wb.Render(image, st);

            for (int i = 0; i < data.Length; i++)
                data[i] = unchecked((uint)wb.Pixels[i]);

            //Vertices verts=PolygonTools.CreateCircle(10, 10);
            Vertices verts = PolygonTools.CreatePolygon(data, (int)(image.ActualWidth * st.ScaleX), (int)(image.ActualHeight * st.ScaleY),true);

            //verts = BooleanTools.Simplify(verts);

            //Make sure that the origin of the texture is the centroid (real center of geometry)
            polygonOrigin = verts.GetCentroid();
            //Use the body factory to create the physics body
            body = BodyFactory.CreateBody(world);
            body.Position = InitPosition;
            body.IsStatic = isStatic;

                body.BodyType = BodyType.Static;
                body.BodyType = BodyType.Dynamic;

            body.SleepingAllowed = true;
            body.Mass = 1000;

            shape = new PolygonShape(verts);

            Fixture fixture=body.CreateFixture(shape);

Nov 19, 2010 at 9:37 PM

Ok I think I found a solution.

I have to use something like this:

Vector2 vertsTranslate = new Vector2((float)-image.ActualWidth / 2, (float)-image.ActualHeight / 2);
verts.Translate(ref vertsTranslate);