3D Terrain manipulation

Hi folks,
I’ve created a 3D terrain using triangles. Now I want to mark these triangles with my mouse to manipulate the height of the terrain on any position I want. (like in SimCity 2000 … long time ago)
How can I identify on which x/y position in 3D the mouse is and which triangle is marked.
First I thought about using the “picking” method, but I guess I have to many triangles for this.
Is any other solution out there???

Hi,

Read the depth buffer value from the pixel that has been clicked and use gluUnproject to get the 3d position. Then it should be easy to find nearby vertice and move them.

-Ilkka

If your terrain is based on an heightmap, you can iterate thru a simple Bresenham line-drawing algorithm until height(x,y) is greater or equal to ray’s current height.

For large terrains, making this method hierarchical is also a plus.

HIH.
Julien.

Do a google for “collission detection”

You want a ray-triangle test, at the bottom, with some kind of hierarchical system to speed it up (testing EACH triangle would be slow).

JustHanging:
thanx for your solution. Works great!!! Just have one small Problem: How do I get the Z-Buffer of a pixel? (maybe glGet…)
SDL only gives me x and y!

glReadPixels