Jump to content
  • Advertisement
Uttam Kushwah

box selection in bullet

Recommended Posts

i am trying to make a basic rts with 100 vs 100 character, but as in rts we need box selection for picking multiple units, and if we

are in perspective projection we need to define the frustum against the camera where it is defined by the cursor position.

 

now my question is i am somehow able to get eight vertices in the 3d world that defines frustum against which collision should be checked

but i don't know how to put that eight vertices in the bullet physics engine,

should i use the btConvexHullShape, then how am i supposed to fit this eight vertices as a triangular mesh.

or 

is there a thing called btFrustumShape or more like it.

or

there is a fully another way to do this thing.

 

i implemented the single click selection via ray casting with bullet.

one thing more i am un-projecting the mouse coordinates with depth 1.0f and 0.0f first when it is clicked and released which gives

topleft and bottomright coordinates of the 2d rectangle(selection box).

thanks in advance.

excuse me for poor syntax😁.

Share this post


Link to post
Share on other sites
Advertisement

Hi Uttam,

Let me make sure I understand your question: You want to do a click and drag to select multiple units from a RTS game?

Here's what I would do:
1. On the initial click save the GUI position of the click
2. On the click release do the following:
    - Make a ray cast from the initial click to the terrain the RTS units are stand on.  It sounds like you are already doing this with single unit select, so just copy that code.  Save the point of collision with the terrain
    - Make a second ray cast from the release click to the terrain.  Save the second point of collision with the terrain
3.  Now you have 2 locations where the player clicked and released the click.  You can use these two points to create a selection rectangle.
4.  Do a foreach loop through each unit.  If the unit is inside of the selection rectangle: they get selected.

Hope that helps

Share this post


Link to post
Share on other sites

Thank you jbarrios i never thought that thing in this way,  so now I can simply make a box on the units rather than a frustum coming from the camera in accordance to that rectangle. And test collision with that box to select object. That is a nice one. 

Thank you once again. 

I Will try it and post again as it works,   and that will work for sure. 

Edited by Uttam Kushwah
Skipped some words

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!