RPG selection box?

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?

Thank you very Much for your Time :slight_smile:

I meant to say: Strategy Selection Box. I dont know how to edit…

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.

Yes you can. It’s pretty simple to implement. You even don’t need any ray casts. Just parse the position of objects/entities.
Here are 2 classes which do all selection of my world editor:
http://code.google.com/p/simple-world-editor/source/browse/#hg%2Ftrunk%2FSimpleWorldEditor%2Fsrc%2Fcom%2Fswe%2Fselection

Sources: http://code.google.com/p/simple-world-editor/source/checkout
Binaries: https://drive.google.com/#folders/0B-0uFh8DG9inSWdQY29MT3d2a2s
Forum: http://hub.jmonkeyengine.org/forum/topic/simple-world-editor/

drawRectangle() - draws the rectangle area to select.
rectangleSelectEntities() - selects all entities which are in the rectangle area.

1 Like

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>…

1 Like
@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.

2 Likes

this is what I want.
but other classes are needed? these methods depend on many classes.
I get confused

I guess no. Just adapt these methods to your project.
There are not so much classes. Just dig in the code. This is a simple editor.