Rubber Band selection Author Message
Brainache
Member

 Post: #1 Rubber Band selection Hey folks.. I'm trying to implement rubber band selection like in all RTS games... and a little stumped in converting the 2d band to a 3d Box for selection of the actual objects... I've tried several ways to convert the 2d screen Rect into a 3d box with varying degrees of success... but none that work as expected... Has anyone tackled this or can anyone point me in a good direction? Thanks!
10-27-2011 01:52 PM
fatcoder
Member

 Post: #2 RE: Rubber Band selection Take a look at tutorial "09 - Detecting objects under cursor" in the Physics folder. To draw the rectangle on screen, just store the 2D screen coordinate when the player presses the mouse button, then store a second coordinate as the player moves the mouse. Draw a rect between these two points. As for the 3D selection, just store the 3D hit coordinate both when the player presses the mouse button and then releases it. You can then test the bounding box created between these two points with the bounding box of the objects in the area.
10-27-2011 03:25 PM
Brainache
Member

 Post: #3 RE: Rubber Band selection Thats exactly what I've done... However, when you create a 3d box shape from the mousedown and mouseup 2d position vectors... the resulting 3d box ( while close ) is not the same as the 2d rectangle box. ie: Vec p1 = ScreenToPos(mouseDown); Vec p2 = ScreenToPos(mouseUp); Box b = Box(p1,p2); b.draw(); the resulting box is not the same as the 2d rect... I've tried a few other ways of making the 3d box from the 2d rect, by swapping positions around, trying to create the 3d box manually - with no real success. I could just loop through objects, convert their positions to screen positions, and compare those to the 2d rect.. but I'd like to find a true solution... thanks in advance for any suggestions...
10-27-2011 06:35 PM
fatcoder
Member

 Post: #4 RE: Rubber Band selection Don't try and create a rect in world space from points in screen space. It is far easier to store the actual 3D hit points where the ray test hits the terrain. Then create a rect in world space from the two world space points. You'll need to filter your ray test to only hit the terrain.
10-28-2011 01:02 AM
Brainache
Member

 Post: #5 RE: Rubber Band selection ah - gotya... good idea! thanks
10-28-2011 01:04 PM
 « Next Oldest | Next Newest »