Texture to Polygon is flipped in 3.3

Topics: User Forum
Mar 22, 2011 at 2:19 AM

I just recently upgraded my project from 3.2 to 3.3 and now my polygons from vertices are flipped vertically.  I followed the example in the Samples project and I don't seem to know what I'm doing wrong.  I could just flip everything while it's still a .png file but that seems like a bad hack.  Here's my code:


            uint[] data = new uint[chassisTex.Width * chassisTex.Height];

            Vertices textureVertices = PolygonTools.CreatePolygon(data, chassisTex.Width, true);
            Vector2 centroid = -textureVertices.GetCentroid();
            textureVertices.Translate(ref centroid);
            Origin = -centroid;

            textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 4f);

            List<Vertices> list = BayazitDecomposer.ConvexPartition(textureVertices);

            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * SCALE;
            foreach(Vertices vertices in list)
                vertices.Scale(ref vertScale);

            Chassis = BodyFactory.CreateCompoundPolygon(theWorld, list, 1f, BodyType.Dynamic);


Is anyone else running into this problem?

Mar 22, 2011 at 3:33 PM

Yes the rendering code changed and now the positive y-axis points downwards. The reasoning behind that was to align it more to the spritebatch coordinate system to make the rendering code easier to understand for beginners. You just need to adjust vertScale in your case i.e. multiply the y component by -1.

Again I would not recommend using our drawing code for anything but prototyping, as it might change a lot from version to version based on the feedback we get from users. Farseer's coordinate system is still the same and will probably stay that way for a loooooong time, so if you come up with your own rendering code this might save you a lot of trouble in the long run.

The samples are just provided as a starting point for beginners and more important to show off Farseer's features.

Mar 23, 2011 at 12:19 AM

Thanks Elsch,

I had already tried multiplying the vertScale by -1 but it seems to flip the X coordinates too.  This ends up the same as if I just rotated the body 180 degrees, and it doesn't work out the way I had hoped.  I'm trying to get a dirt bike texture as a body in Farseer, and with the new version 3.3 I always end up with the front of the bike facing left when it used to face right.  I know I'm describing this rather poorly but what I'm trying to get across is that rotating it will not fix my problem.

I'm not using the debugview class for my finished product output, but I do use it to get a better picture of what's going on in the physics engine.  I can hide that the body is flipped from the user easily enough, but the collision points will not appear correct nor will the weight of the bike be represented accurately.

All in all it's a small issue as I can just flip my PNGs in Gimp before loading them, but then I would have to keep another unflipped copy for drawing the sprite.



Mar 23, 2011 at 1:05 AM

I've gotten around the problem for now by adding a FlipY() method to the Vertices class that FPE 3.3 provides that flips the Y value on the individual Vector2 elements.