Jump to content
  • Advertisement
Sign in to follow this  
cyric74

Algorithm Help

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

Not sure if it's just because I'm up too late, or if I really need help; I'm having a bit of trouble building an effecient algorithm to properly draw my isometric tiles in order. I've made a little chart to help explain: The tiles are in a simple 2D array, rotated 45 degrees clockwise, and can have any bounds for the tips of the diamond. For this example, I'm trying to find an algorithm that will make the draw order: 0,0 0,1 1,0 0,2 1,1 2,0 1,2 2,1 2,2 Thanks for any suggestions, or a link in the right direction! Cyric

Share this post


Link to post
Share on other sites
Advertisement
I can see two solutions:

- data-based algorithm:


positions = { (0,0), (0,1), (1,0), (0,2), (1,1), (2,0), (1,2), (2,1), (2,2) }
foreach(pos in positions) render( pos );


- depth-based algorithm:


renderLine (depth) =
start = 0;
end = depth;
for(i = start to end) render( i, depth - i );

for(i = min to max) renderLine( i );


Adjust start, end, min and max so you only render tiles on the screen.

Share this post


Link to post
Share on other sites
Here goes -


#define YTop 0
#define YBottom 2
#define XLeft 0
#define XRight 2

int i, y, x;

// The diagonals starting on the left edge
for (i = YTop; i <= YBottom; i++)
{
for (y = i, x = 0; y >= 0; y--, x++)
{
DrawTile(x, y);
}
}

// The diagonals starting on the bottom edge (except for the left one drawn earlier)
for (i = XLeft+1; i <= XRight; i++)
{
for (x = i, y = YBottom; x <= XRight; y--, x++)
{
DrawTile(x, y);
}
}

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!