# Strategy 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 I would get the center of each object, call cam.getScreenCoordinates() on them, and check if they are within the rectangle. Although there’s probably some other ways

1 Like

Thank you thats a better solution. SO how would i go about drawing the square? Any tutorials?

I would just use a Quad mesh with a material that makes it look like a selection box and put it on the guiNode.

the x/y position of the quad would be where the mouse started to drag, the width and the height of the quad would be the current mouse coordinates.

1 Like

I have created the quad like so:

public void createSelector() {
Mesh mesh = new Mesh();
Vector3f[] vertices = new Vector3f;
vertices = new Vector3f(0, 0, 0);
vertices = new Vector3f(3, 0, 0);
vertices = new Vector3f(0, 3, 0);
vertices = new Vector3f(3, 3, 0);

``````        Vector2f[] texCoord = new Vector2f;
texCoord = new Vector2f(0, 0);
texCoord = new Vector2f(1, 0);
texCoord = new Vector2f(0, 1);
texCoord = new Vector2f(1, 1);

int[] indexes = {2, 0, 1, 1, 3, 2};
}
``````

So how do i make it initialize that the mouse pos and how do i add it to the gui node?
Im really new to all this im sorry use inputManager.getCursorPosition() to get the current x/y coordinates of the mouser (do this inside of on ActionListener that listens for the mouse left button to be pushed)

before someone less nice than me answers it seems you need a bit more understanding of References in java. You can pass it as an argument to a method of your other class, or use a static getter, or what ever 