Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

how to find tile-textures for terrain transitions

This topic is 3904 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

hello, i was looking at this article http://www.gamedev.net/reference/articles/article934.asp to implement terrain transistions. but what i did not understand is, how exactly do you find out which tile-texture you need. i know that the edges are stored in 4 bits and that the corners are stored in 4 bits. but that still sums up to 256 ddifferent possible combinations. should i really do a 256 long if () else if () else if () .... else () ? probably not! so what is the way to find out which texture i need for which bitmask of corners and edges?

Share this post


Link to post
Share on other sites
Advertisement
If you look at their pictures and read carefully you can use something similar to the following to figure out which transitions to use (I find hex easier with binary math):
// direction values
west=0x01;
north=0x02;
east=0x04;
south=0x08;
northwest=0x10;
northeast=0x20;
southeast=0x40;
southwest=0x80;

Using transition as your bit mask,

You would only need 4 ifs for the sides,
if need side then transition |= direction_value

And 4 for the corners
if need corner then transition |= direction_value

If we had east and southwest the hex would look something like 0x84.
If we had all 4 sides and no corners, the hex would look like 0x0f.

If your transition tiles are in an array sides[15] and corners[15] then you choose the tiles to draw by using a binary AND of 0x0f for the sides or 0xf0 along with a right shift for the corners on the final transition you received.

This system works very well if you use something like paint to generate a gray scale height map and allow this algorithm to fill in the transitions. A quick and easy way to generate large maps that aren't random with little effort and then fine tune them in your map editor.

Sorry if this isn't making sense, I am tired and really should have gone to bed and answered in the morning.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!