PDA

View Full Version : 3D Terrain manipulation



zotto
03-24-2003, 02: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???

JustHanging
03-25-2003, 12:53 AM
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

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

HIH.
Julien.

jwatte
03-25-2003, 11: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).

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

JustHanging
03-26-2003, 04:23 AM
glReadPixels