PDA

View Full Version : using mouse coordinates to select an object in 3d



dodgyposse
09-06-2000, 05:16 AM
Ok, I am writing a 3d space game, and one of the things I would like to do, is use the mouse to select my ships.

I am now using an orthographic projection
to display the mouse pointer, and a perspective projection for my 3d models.

How can determine whether the mouse is over
a spaceship?

dd

09-06-2000, 06:25 AM
I don't know much in OpenGL, but there is selection buffer - try some info on it.
If what you need is not to check if some object was selected (clicked), but you need a "projected" coords of your mouse pointer then there are things like glProject glUnproject for coord determination.

Check this stuff - it may bring results.

09-06-2000, 12:30 PM
The selection buffer will work, it enables you to name a group of polygons which opengl will then check to see if they were hit acording to the coordinates you give it. I could explain lots here but there was a thread a few weeks ago which is on the exact same thing, look back on the forum for the topic "A great game hit a bottomless pit "
it's one of the ones with the flaming folder.

Schlogenburg
09-06-2000, 03:35 PM
Yes that was my topic there. I've seen this question asked so many times so often, and they all say selection buffer, but that's not good enough, because you can't click and drag with it.

I think it's about time somebody writes a small library to do this.

Alot of people would be happy with that.

Morf
09-07-2000, 04:10 AM
Ive managed to get it happily dragging the selection regions.
I may have this wrong, cos I have one more thing to sort out!
Im getting a hit back for every poly on screen, and not the ones under the mouse.
Im soo new to OpenGL, but there is hope there!!

dodgyposse
09-07-2000, 04:15 AM
Wahey!!!!

I got the selection buffer thingy working!
Absolutely brilliant, and the frame rate isn't even touched, as I only evaluate the selection buffer when the mouse is clicked!

it works really well.....
Thanks everyone.
dd

dodgyposse
09-07-2000, 04:20 AM
This drag and drop operation, ok.

As I understand it, you want to drag a rectangle out across the screen and upon releasing the key, you want every 3d object
inside the rectangle, to be selected????

The way the selection buffer works, you define a viewport onto which you are drawing,but it is positioned at the mouse coordinates, and is only a few pixels wide.

You draw your objects, and any named object which is draw into this very small viewport,
is added to a list, for your perusal later.

ok, why not use the dragged rectangle to define your viewport size?

The opengl Superbible has an example of this.
That's what I used and it worked great!

dd

Mace
09-12-2000, 04:41 AM
Why is this mouse coords in 3 space always posted in the beginners section? Its damn hard http://www.opengl.org/discussion_boards/ubb/smile.gif

Anyway, could someone post some source for doing it like this:
Get a directional vector from the mouse x, y coords and make it a ray in 3d space thats pointing into the screen. Then, you just check to see if the models intersect that ray.