What method should I use for 3D picking several objects at once?

Hi, I made a function for selecting/picking one 3D object but what method could I use to select several.
Like in 3D real time strategy games.

For one object I’m using a Ray and a BoundingSphere and that function is working like a charm.

pickRay.Intersects(sphere).... etc.

But what if I’m holding down the mouse button to create a square selecting several objects within that square?
Could I still use Ray/Rays for this? Or what would be a better approach?

Regards, Morgan

Thanks in advance

I think you could do frustum/pyramid intersection, which should be pretty common since it’s used for culling as well. You get rays for two opposite edges (e.g. bottom left and top right) when the mouse is first pressed and finally released – or perform the check in real time whenever the mouse is moved – and find which objects intersect that volume extending out from the camera.

2 Likes

I guess the first step is to project the corners of this selection box on the near plane to see what a camera would see through that window. Construct a camera (View,Projection) and then a BoundingFrustum(view*proj).

Or get 4 rays and from there create the bounding planes, which you can then use to create a BoundingFrustum or simply test if an object is within the 4 planes.

1 Like

Thanks for the guided tour…
I’ll definitely try this out, sounds great.

Kind regards, Morgan