Working on a seeding function for terrains, which overcomes some disadvantages of the ent_seed function (level.c):

void hmp_seed (Hmp* hmp, BMAP* prMap, float avgDist, float minDist, BOOL relax, EVENT ev);

It takes a heightfield, a probability map, an average distance, a minimal distance and generates a distribution (1st pass).

If relax is = true, all generated positions will be iterated in descending order of field probability (so that items with high field probability have more influence over lower probability items in terms of position stability) and too near items are pushed away, if the minimum distance is violated (2nd pass). If the previously generated random item probabilty then violates the (predefined) field probability, the item will be deleted; otherwise it gets updated (height and field probability).

Then, in the 3rd pass, pairs are searched for, that still violate the minimum distance, and are deleted as well.

After finishing this, for each item a callback will be called and the heightfield, the XYZ coordinates (in heightfield space) and the field probability at that location are passed. This gives me the opportunity to decide by myself what to do for each generated item:

void myFunc (Hmp* hmp, VECTOR* hXYZ, float pr)
	VECTOR* pos = hmp_vectoent(hmp, hXYZ, terrain, NULL, true);
	if (pos != NULL)
		ENTITY* e = ent_create(CUBE_MDL, pos, NULL);
		e->scale_x = e->scale_y = e->scale_z = pr;

In the function above I generate a cube on the terrain, whereas the scale of the cube represents the field probability at that very location.

It looks like this; the picture in the upper left corner shows the probability (black = 0%, white = 100%); parameters were average distance = 24 and minimum distance = 12:

(click to enlarge)

Last edited by HeelX; 01/20/12 10:47.