Archived

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

MattCarpenter

Finding out what triangle you are over

Recommended Posts

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites