|
|
"Kenneth" <kdw### [at] gmailcom> wrote:
[snip]
> Btw, I don't know if it's noticable in these renders, but I made no attempt
> (yet) to 'correctly' place the greebles on the building roofs; they are just
> randomly placed, and most likely intersect each other. I have to admit that I
> still don't know the algorithm or technique for placing randomly-located objects
> that don't overlap, each object having its own space. It is a long-standing
> mystery to me. I know it has been discussed in the newsgroups from time to time.
You can store objects in an array, and check each new one against existing
positions and bounds, for example in dodgy pseudocode:
Declare array of N objects
Loop for N
Make new object
Loop until new object is ok
Make location
Loop over existing objects
Check new location + bounds against existing object location + bounds
If collision, new object not ok
If no collisions were found, new object is ok
Store new object in array
Using spheres for bounds testing is easiest.
Alternatively, you can subdivide your region of interest, then pick a single
random location in each sub-region. This has the advantage of not requiring
extensive looping and testing, although subdivision might be non-trivial. For
rectangles it's not too bad.
If your objects are all roughly the same sort of size, you can lay a grid down,
perturb the grid positions by some distance smaller than the grid spacing, then
place objects at the perturbed grid positions. Using only a subset of the grid
positions makes it look more random.
There are surely other possibilities!
Bill
Post a reply to this message
|
|