|
|
|
|
|
by jiggy2011
4807 days ago
|
|
In that case, it's probably most space efficient to place each new window next to an already visible window or at an edge of the screen. So keep a list of possible candidate positions. Each of these positions represents either an edge of the screen or a position directly above/below/to the left/to the right of an existing window. You will need to calculate different offsets for each of these circumstances to generate candidate positions. You easily eliminate ones that fall outside of the screen. Each time you attempt to add a window you iterate the list of candidate positions.
If a candidate position can fit a window (just use brute force 2D AABB collision detection against all windows, or a quadtree/spatial hash to optimise) then place the window there. If it cannot fit remove the position from the candidate list. Once you have added the window, calculate all the candidate positions (for each side) and add these to the list of possible positions for later windows. Well it's late and that's the best I can manage..
I know somebody will point out a flaw here :) |
|