gluProject and picking

Started by
3 comments, last by Zakwayda 18 years ago
If I have a tiled map that's raised with a height feild (mountains and stuff) - basiclly a mesh if you know what I mean, how do I use gluProject/UnProject to tell which tile the mouse is on? Or are there better ways to do it? I thought of drawing the map again with the tiles colored in different colors and then do color picking, but that seemed a little slow. Any ideas? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
I believe there is an example in the red book and is quite simple to follow. The one I did was an older version but this'll probably be better...

http://www.rush3d.com/reference/opengl-redbook-1.1/chapter12.html
Here's another example for you:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=32
I know about opengl's selection, but to use it I would have to render all of the 1024X1024 tiles seperatly and then see which one was picked - but with opengl's selection you can only draw 64, and even if you could draw more, it would take a ton of time and would wreck the framerate. I think that I need another method. This should be a pretty basic thing for every 3D tiled game, how is it done?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Quote:Original post by daniel_i_l
I know about opengl's selection, but to use it I would have to render all of the 1024X1024 tiles seperatly and then see which one was picked - but with opengl's selection you can only draw 64, and even if you could draw more, it would take a ton of time and would wreck the framerate. I think that I need another method. This should be a pretty basic thing for every 3D tiled game, how is it done?
Thanks.
This is also in answer to your other post on picking.

I'd recommend approaching this problem geometrically rather than using feedback mode or other framebuffer tricks. The first step is to construct a picking ray. You can do this by using gluUnproject() to find the worldspace coordinates corresponding to the mouse position at the near and far planes. You can find more details on this step here.

How to use the pick ray to select geometry in your simulation is a bigger topic, but in almost all cases it can be accelerated and/or optimized so that it will be practical even if you have thousands of objects in your scene.

It's hard to be more specific without knowing more about your simulation. You mentioned a heightfield, but also tiles. Based on that, possible solutions might include a (3D) quadtree, or 3D-DDA.

This topic is closed to new replies.

Advertisement