# 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[4];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(3, 0, 0);
vertices[2] = new Vector3f(0, 3, 0);
vertices[3] = new Vector3f(3, 3, 0);

``````        Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0, 0);
texCoord[1] = new Vector2f(1, 0);
texCoord[2] = new Vector2f(0, 1);
texCoord[3] = 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)