#### Archived

This topic is now archived and is closed to further replies.

# Finding out what triangle you are over

This topic is 5954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, How can I find out what triangle I am over? I have an array of vertices that make up terrain, and I need to find out the 9 verteces of the triangle I am over. Thanks

##### Share on other sites
Um... a triangle only has 3 vertices?

typo

##### Share on other sites
typo. i was stpuidly counting each of the componets of a vertex (x,y,z)

##### Share on other sites
Sorry, but I can''t give you a solution. And, taking a stab in the dark here, I really doubt anyone else can either. There''s a simple problem. Let''s picture this field of completely random polygons, placed randomly and of random dimensions. How can I tell which one the player''s over? You can''t. Not unless there''s SOME pattern to how they''re arranged, or something to go off of. Let''s take it back a step, to the ol'' 2d RPG days. Yes, you can tell which tile a character is over, by dividing the character position by the dimensions of the tiles. However, if all the information about the terrain you have is the information you''ve given us, I regret to inform you that there is no way to get an accurate result. Post more!

-Arek the Absolute

##### Share on other sites
In other words, he''s asking for some info on how the triangles are implemented

http://roninmagus.hopto.org

##### Share on other sites
Maybe you should consult the pick example in the DX8 msdk.

If you don''t want to study mouse picking, just look at the last part of the pick code, which presents a intersection algo (already writtten, "COPY PASTE" which takes a origin point, ray and tri and tests intersection. Just apply it to all your tris, or the potential set of tris.

Maybe this is what you want?

##### Share on other sites
Is your terrain an evenly spaced grid of points, drawn with triangles? Are they in arbitrary positions? We need more information.

##### Share on other sites
Use a ray-triangle intersection test. A search in google you will get you many. For the triangle you have your mouse over use gluUnProject to get the world space coordinates, create a ray with this and your current eye position. Check your triangles for a intersection. If many triangles intersect then pick the appropriate one.

If you have an object and you want to test the triangle you are on, use a sphere-triangle intersection which is basically a ray-triangle intersection anyways. For each possible triangle grab its normal vector and negate it. Use that with the origin of the sphere and create a ray. Check this ray with all the possible triangles for a intersection.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633319
• Total Posts
3011342
• ### Who's Online (See full list)

There are no registered users currently online

×