Finding out what triangle you are over
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
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
-Arek the Absolute
In other words, he''s asking for some info on how the triangles are implemented
http://roninmagus.hopto.org
http://roninmagus.hopto.org
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?
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?
Is your terrain an evenly spaced grid of points, drawn with triangles? Are they in arbitrary positions? We need more information.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement