PDA

View Full Version : Picking: return right value



cutting_crew
12-08-2003, 05:10 AM
..ok so i have read up on some picking this weekend, and i understand it much better. here is my question ...from all the tuts i have seen each object drawn has an ID, which goes into glPushName(ID) etc etc. well in my case i have one object but made up of a triangle strip.

what i have drawn is heightmap. i have had posts about this project i am working on and things are going well with it. i want to be able to pick anywhere on the heightmap and for openGL to return the height value of the heightmap:

Question 1: in my glPushName(ID) call do i assign an ID number for every triangle? (i have 297 points in all so about 99 triangles.)

Question 2: what if the mouse pointer is not on an actual vertex value, i.e.(an x,y,z coord that was stored in my array when i was drawing the heightmap). Yes, i could just guess and say VertexA - VertexB on that certain line segment, but that would not be accurate and just a guess. so what would your suggestion be? i hope i have made this question clear enough.

please respond if you think you can help and all suggestions appreciated! thanks in advance!

foobar
12-08-2003, 05:31 AM
If you assign an id to each triangle you will probably not be able to distinguish varying height within that triangle without further calculation.

You might like to try rendering the scene into the back buffer using different colours to 'label' the height of the terrain per-pixel then all you need to do is read back the color of the back buffer at your mouse position to calculate the height of the map. This way a 24-bit frame buffer gives you 24-bit resolution on your height values.

edit: thought i should pint out you only need to assign the correct colors per vertex since linear color interpolation will create approx. correct per-pixel heights.

[This message has been edited by foobar (edited 12-08-2003).]