I am wondering if it is possible to create a way to select multiple object using a selection box? For example in strategy games you can hold and drag your mouse to draw a selection box. And everything inside the box is selected. Would it be possible to draw a box on the mouse and then for each point in the box perform a ray cast? Or is that too processing intensive?
If there is any examples of this could you please post a link?
Maybe @mifth can answer this. You can do this in his world editor.
I would venture to guess a camera aligned bounding box that you draw the x/z extents with your mouse would be a decent way to start experimenting. In the case of an RTS you could extend z until it hits terrain.
I have solved it in 2-d way. Used collissions only to find out where corners of selection are on the terrain, got x/y coordinates from these points (I have z-up world, it can be x/z for you) and then iterate through unit list to see which ones have x/y coordinates fitting inside such square.
@TastyLemons said:
I meant to say: Strategy Selection Box. I dont know how to edit...
@t0neg0d said:
Maybe @mifth can answer this. You can do this in his world editor.
I would venture to guess a camera aligned bounding box that you draw the x/z extents with your mouse would be a decent way to start experimenting. In the case of an RTS you could extend z until it hits terrain.
All you need to speed up the process - parse all selectable entities.
But in my world editor selection works pretty fast. I can easily make selection within 500 entities.
for a 2D thing, i think that a tesselation (+global grid ? to initiate the algorithm) would be even faster. You could have a way to pick one selected unit, then go to the “border” of the tesselation, then get the border of the tesselation (follow the path of unit with this property : “a unit not already picked (of course^^) with at least one neighbour which is not in the square”.
If you have billions of units, and you select millions of them, you’ll have more or less thousands of operations to do (you only select the border, 1000*1000 = 1000000, a square of millions of units has an average border of thousands).
Let’s be serious here. It is a game, it won’t have billions of selectable units. Simple algorithms work best. This time is better spent on creating some fancy shader rather than overoptimizing for non-realistic data set sizes.
It is almost like using Oracle database to hold Map<Boolean,Integer>…
@bubuche said:
for a 2D thing, i think that a tesselation (+global grid ? to initiate the algorithm) would be even faster. You could have a way to pick one selected unit, then go to the "border" of the tesselation, then get the border of the tesselation (follow the path of unit with this property : "a unit not already picked (of course^^) with at least one neighbour which is not in the square".
If you have billions of units, and you select millions of them, you’ll have more or less thousands of operations to do (you only select the border, 1000*1000 = 1000000, a square of millions of units has an average border of thousands).
I think most games have maximum 300 selectable objects. Even starcraft.