High quality poligon

Oct 27, 2011 at 5:12 PM
Edited Oct 27, 2011 at 5:43 PM

Hello poeple.
I am now working on simple 2D project.
To store level's terrain I am using texture.
My game level(only terrain, without other stuff) looks like this: http://gyazo.com/aa155403a628b276b0e1a091aa285e2e

The real texture's size is 480x2048.

To create level's floor polygon I am using something like this:

      //load texture that will represent the physics body
      Texture2D polygonTexture = Content.Load<Texture2D>("Assets/Levels/Level1");

      //Create an array to hold the data from the texture
      uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];

      //Transfer the texture data to the array

      //Find the vertices that makes up the outline of the shape in the texture
      List<Vertices> verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, 0.00001f,1, false, false);

      //For now we need to scale the vertices (result is in pixels, we use meters)
      Vector2 scale = new Vector2(1.0f / PixelsPerMetter, 1.0f / PixelsPerMetter);
      for(int i=0;i<verts.Count;i++)
      verts[i].Scale(ref scale);

      //Since it is a concave polygon, we need to partition it into several smaller convex polygons
      List<List<Vertices>> _list = new List<List<Vertices>>();
      for (int i = 0; i < verts.Count; i++)

      float tsize = 64.0f;
      Body b = BodyFactory.CreateRectangle(PhysicsWorld, tsize / PixelsPerMetter, tsize / PixelsPerMetter, 1.0f);
      b.Position = Vector2.Zero;
      b.BodyType = BodyType.Static;

      for (int i = 0; i < _list.Count; i++)
        for (int j = 0; j < _list[i].Count; j++)
          Shape sh = new PolygonShape(_list[i][j], 1.0f);
          Fixture fix = b.CreateFixture(sh);


This is a very simple representation, only to clarify what I want.
As the result, I have something like this floor: http://gyazo.com/fa746e415b2ed1e86ec296237bf3a54f


But it does not exatctly what I want.
I played one game on my WP7, so I maked a photo of the screen to show my floor in ideal variant: http://gyazo.com/4532c6d732999b7cd5f1b95ce6c01908

Does anyone know how to do  my level's floor more "round". Not like a polygon but like a curve. Or in other words high-quality polygon.
And how to store curve-like level?
A great thanks for any suggestions and other help.

Oct 28, 2011 at 12:11 AM

You can increase the resolution of your image and that might work or...

You can introduce a pre-process step to your pipeline. If I wanted to store your image as a curve I would find the top y value for every 10th pixel in the x axis in your image. That would give you all your points for a curve or in Farseer a Path. Then you can create arbitrary definition polygons or even just chains or edge chains.

Oct 28, 2011 at 4:30 AM

Thanks for ypur answer. I wiil try do it as you say(find the top y value for every 10th pixel in the x axis in my image).
But is there any curves in Farseer? I found a Curve class in engine. Can it solve my problem? There is no documentation about it =(
And what is the Path class for?