Skip to main content
GameDev.net gamedev.net
🔒 Locked

Algorithm Help

Started by cyric74 Oct 11, 2005 at 3:12 AM 3 replies 1k views
Original Post
cyric74
cyric74
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
ToohrVyk
ToohrVyk
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.
DadleFish
DadleFish
Here goes -

#define YTop    0#define YBottom 2#define XLeft   0#define XRight  2int 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);    }}
Dubito, Cogito ergo sum.
kSquared
kSquared
I'm moving this to the Isometric Land forum. Isometric algorithms are practically their bread and butter.
- k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ<
cyric74
cyric74
Worked perfectly, thanks a ton guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.