View Full Version : 3D Terrain manipulation

03-24-2003, 01:12 AM
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???

03-24-2003, 11:53 PM

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.


Julien Cayzac
03-25-2003, 02:07 AM
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.


03-25-2003, 10:16 AM
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).

03-26-2003, 01:04 AM
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!

03-26-2003, 03:23 AM