Jump to content
  • Advertisement
Sign in to follow this  
Calin

Sweep selection using OpenGL

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am making a RTS game using OpenGL. So far using the NeHe lessons i succeded to implement in my little project a moving camera, mouse scroling and mouse selection. The problem I have is that i can`t figure how to implement sweep selection, i can select only one unit at a time. I went through NeHe`s lesson on selection (lesson 32)and OpenGL Red Book (online version) but could not find a solution. Can anyone help me? P.S. Sorry for my english.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

you can do it two ways.

First one:
Project a Box into your world and do collsion detection on it.

Second one:
Render your scene with names turned on for the current Box the mouse has drawn.

The first one is much faster than the second one.

Share this post


Link to post
Share on other sites
If you read and understasnd how the selection buffer works, it will all become clear.

Put it this way: you don't *have* to have a tiny frustum for the selection draw, it can be any size you want. Also, the names returned by the gl are in depth order.

Share this post


Link to post
Share on other sites
That was my second one.
But that is slow, because you have to do an extra render path.
Box - Sphere collison or Box - Box is much faster.

And you will need some kind of collison detection any way ...

Share this post


Link to post
Share on other sites
I know that the "selecting box" can be as big as u want. What I can`t understand is how do you resize the "selecting box" (frustum) while you are draging the mouse.

Share this post


Link to post
Share on other sites
You save your starting point and where you are now.
That each frame (or every second or thrid) you call your frustrum,
with one corner the starting and the other corner the current mouse position.

Share this post


Link to post
Share on other sites
This is not going to be easy. I will have to figure out how to implement your sugestion dragongame (I am a beginner in programming). Anyways thank`s for youre input guys.

Share this post


Link to post
Share on other sites
On mouse down, store the mouse position, on mouse up, calculate the center of the selection box, and pass the width and height params to opengl. Remember, selection usually occurs on mouse up, not in real-time as you drag the mouse.

Share this post


Link to post
Share on other sites
Quote:
Original post by mfawcett
On mouse down, store the mouse position, on mouse up, calculate the center of the selection box, and pass the width and height params to opengl. Remember, selection usually occurs on mouse up, not in real-time as you drag the mouse.


Actually, you can make a flag that gets toggled to on when the mouse button is pressed and off when it is depressed and have the value of x,y stored upon the initial click. Then, inside your mouse-move event, you have a check for if the flag is toggled on. If it is, then you make your selection box's dimensions be from the initial x,y value to your current x,y value and you can do selection as you are dragging the selection box.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!