PDA

View Full Version : Developing a algorithm to sort 2D arrays



Whitt
21-06-2008, 08:14 AM
CPU : P4 3.0Ghz
Compiler Delphi 7
Graphics : GLscene

Hello again,

I have made some progress with my project. It now generates a city with different sorts of buildings with textures.

http://i30.tinypic.com/ehja0w.jpg

However I need some help developing a algorithm to improve it. At the moment there is a 3D array which is the planning array. When it is developing the buildings it uses the height in the array as the size of buildings. The problem is calculating the coordinates for use when I render it.

At the moment it scans the x direction and y and places into two arrays the cumulative next free line or column respectively. This is ok for the city scape as the spacing becomes tighter towards the centre but items which are placed far out of the city but towards the middle y of start spacing randomly. The problem I am expecting is that if have smaller towns around the city the spacing between buildings is going to be dependant on the city.

http://i32.tinypic.com/33ucvug.jpg

http://i25.tinypic.com/es8937.jpg
What I would like is to develop a algorithm that fits the buildings around each other as opposed to leaving large gaps between each building. I have tried a couple of ideas but simply cannot figure out the code for it to work. If you could help me with some pseudocode I would be very grateful.

Thanks

Whitt