Jump to content
  • Advertisement
Sign in to follow this  
Finalspace

How to create line segments from tile map outlines

This topic is 1319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,

 

i successfully implemented the "Moore Neighborhood" algorythmn to calculate the contours of a tile map, which gives me every tile-outline in clockwise direction. Now i want to create line segments out of it - from edge to edge, but have trouble to figure a algorythmn to solve this. A tile may create/continue two lines in parallel, change directions...

 

This is what i have:

 

TilemapOutlineContour_.png

The black number with the arrow beneath indicates the starting tile including the direction to the next tile.

The colored lines indicates the "tile outline" detected by the algorythmn - i call this "chain" and this goes around clockwise until a tile already visited is found.

 

A chain have just a list of tile coords in vec2 format, something like this:

 

chain {

  tiles: [Vec2, Vec2, Vec2,...]

};

 

This is what i somehow want:

 

TilemapLines.png

 

Any idea?

Edited by Finalspace

Share this post


Link to post
Share on other sites
Advertisement

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

 

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

 

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

Share this post


Link to post
Share on other sites

I'm not sure how the "Moore Neighborhood" algorithm helps you here.

 

I just implemented something similar to what you want. It basically takes a tilemap and generates a contour line for each independent "collection" of tiles (I'm using this to generate a 3d model based off the tile map).

 

It sounds like you want something slightly different though. What's the logic behind your choices of starting numbers in the above diagram? What's the logic behind joining two or more different colored contours?

 

The algorythmn is just a way to identify the outline tiles but nothing more. All the colored lines in my second picture are defined by every tile a line for 4 directions, but only when there are no neighbors in that direction.

 

But my overall target is to generate Box2D chain shapes (joined line segments) based on a tile map (solid/not solid). Using boxes for every tile is a bad idea - cause of internal edge isses.

Edited by Finalspace

Share this post


Link to post
Share on other sites
Have you tried taking your chaining information and walking along the edges until you complete the shape?

Start from the first tile and find a corner that doesn't share a corner with any other. Then move clockwise from one edge to another. Making sure you don't incorporate shared edges?

Then you can connect any contiguous lines that share an axis.

From my phone. Or I'd try to show a picture or something.

Share this post


Link to post
Share on other sites

Ok i implemented a much better algorythmn which detects all the outlines perfectly... but i still havent figured out a way to traverse the created edges and create the chain-edges / line segments yet.

 

There are two things which needs to be done i thing to get this thing to work.

 

First of, the connected edges should be fixed, so that that shared vertices get removed.

Secondly, built a algoryhtmn that traverse the tile in the directions and create line segments out of it.

 

What i have created is:

 

- A list of edges. A edge is pair of two indices to the actual vertices + the actual tile position + the edge index (is it a left, right, top, ot bottom edge)

- A list of vertices without any duplicates.

 

Does someone have an idea?

 

Here is a image from all the tile edges drawing its vertices (blue) just connected with a red line and displaying each tile position for every edge center.

 

TilemapContourWithTilecoords.png

Greetings Final.

Share this post


Link to post
Share on other sites

I did it, it works - Now i just need to remove the vertices between the corners and i am done!

The best thing was it was just two more steps in my state-based contour tracing system... :-)

Edited by Finalspace

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!