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

Using marching squares method in Farseer

Topics: User Forum
Sep 13, 2013 at 10:29 AM
Hi all,

I've come to the part of my project where I'm trying to generate a landscape from a png file. I started writing my own marching squares methods to produce vertices to pass to an array of Body objects to represent my world.

Then I came across the MarchingSquares.DetectSquares part of Farseer. I'm stuck on what arguments I need to pass into this method, in particular:-
AABB domain - is this the start/end xy of the AABB of the vertices that will be produced?
sbyte - is this the array of data that needs to be read from the landscape texture, and should I already have filtered the texture data against a threshold to produce an binary array?

Hope you can help.


Oct 8, 2013 at 2:55 AM
The Marching Squares class is somewhat low level and it might be easier to use Terrain class instead. It shows how to use Marching Squares.

That being said,

DetectSquares method takes an AABB of where in your point cloud space you want to detect polygons. CellWidth and height represent the physical size of each point in the point cloud. F is the point cloud, it's a 2D array of signed bytes. Positive is solid and negative is hollow if I remember correctly. LerpCount is how many divisions should be made to try and get the smoothest output, higher then half of the cell size is useless. Combine simply lets the method know if you want it to combine as many squares as possible into larger polygons. These polygons will be concave and will have to be decomposed before being used by the physics engine.

I hope this answers your question.
Oct 8, 2013 at 9:08 AM
Hi Matt,

Many thanks for the reply. I eventually made my own texture->marching squares but the problem I had was that I'd missed the fact that the point cloud dimensions had to be (texture.width-1,texture.height-1).

If I use the Terrain class is there an easy way to get polygons back out from the _bodyMap to render them?

I'm stuck on the concept of what an AABB is in the context of 'the area of the terrain' - can you advise me on this?