Getting crossing points in Marching Squares

Topics: Developer Forum
Nov 22, 2012 at 10:00 PM

I've just started using Marching Squares for my destructable environment, and its really cool (good work!).

Now I want to render my ground tiles to represent the floor. I want to draw (spritebatch) to make up the "physics objec". The easiest way I can see to do this would be to get a grid of positions that covers the terrain. Basically, in the first image here( I would like to be able to get a list of Vector2's for where each line crosses(where they make a +) and then I will draw a tile at each of those positions. I understand that that will produce jagged edges, but that is exactly what I want.

Using the testbed sample I've been able to get these positions by looping through each line it would draw and then drawing the tile at the start vector of the line (ignore the end vector).

But it seems like a very convoluted way. Os there a better way?


P.s. Yes, I do need to use individual tiles.

Nov 25, 2012 at 2:52 AM

Can you draw a simple sketch of what your trying to achieve? Your description is kind of hard to understand.

Nov 26, 2012 at 6:37 PM
Edited Nov 26, 2012 at 6:38 PM

Sure, sorry about the bad description.

I want to be able to get the Vector2's of each of those yellow dots which is where they cross.

Nov 27, 2012 at 1:33 AM

Ok, the only way to get those points is to use -

List<Vertices> DetectSquares(AABB domain, float cellWidth, float cellHeight, sbyte[,] f, int lerpCount, bool combine)

with combine set to false. This will give you a set of squares as shown in your picture. It would be up to you to make sure and combine colinear points to get just one vertex per crossing. 

I would suggest coming up with a method of finding the correct tile using some kind of mask for whatever array your using for 'f'. Of course a lot depends on how you set up your tiles (size) and how large your cell size is.