Skip to main content
gamedev.net
🔒 Locked

Terrain Picking

Started by Tauqeer May 28, 2006 at 12:01 AM 3 replies 800+ views
Original Post
Tauqeer
Tauqeer
i am trying to get the terrain coordinates on a mouse click but i dont know how to do it. i have already calculted the Picking Ray and my terrain is just a 2D grid for now. please help me to solve it.
Zakwayda
Zakwayda
There are different ways of doing this, most of which will break down to a narrow phase and a broad phase. The broad phase involves identifying the candidate triangles, and the narrow phase involves finding the exact point of intersection.

If these topics are new to you, you might just start with a brute-force broad phase so that you can focus on getting your triangle picking function working. If your terrain is large it may be painfully slow, so you might try experimenting using a smaller data set.

There are lots of references on triangle raytracing online, although many ignore certain numerical pitfalls which can result in missed intersections when a ray fall between two triangles.

Feel free to ask if you need further details on any of these topics.
ph33r
ph33r
jyk, he mentioned that he just has a 2d grid, so there is no need for the broad phase if he plans on keeping the terrain always a 2d grid. Though, Tauqeer, if you do plan to eventually make this into a height map representation then you'll need to re-evaluate how you'll want to solve this.

For finding out which cell a ray intersects in a 2d grid what you can do is first calculate a ray to plane intersection. Then, if it intersects the plane, calculate point inside AABB. If it is inside the AABB, then take the offest into the AABB and hash that into a 2d array coordinate.

If you have any questions on any of these steps then ask and I'll go into further detail.

- Dave


Zakwayda
Zakwayda
Quote:
Original post by ph33r
jyk, he mentioned that he just has a 2d grid, so there is no need for the broad phase if he plans on keeping the terrain always a 2d grid.
I read 'just a 2d grid' as 'just a heightmap aligned to a 2d grid'. If it really is just a 'flat' grid of cells, then of course no broad phase is necessary (or rather, the broad phase is trivial).
Tauqeer
Tauqeer
thanks for the replies, i am using a flat 2D grid and i am not going to change it for this project. i will study and work on techniques you described and if i found and problems i will ask.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.