Advertisement Jump to content
Sign in to follow this  

Triangle Selector

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

How to make my heightmap return the point x,z on the terrain based on mouse clicking point ?. i want to try D3DXIntersectTri, but i don't know how to get back the vertexbuffer of every triangle of the heightmap.... help me please...... :)

Share this post

Link to post
Share on other sites
Have you thought about using D3DXIntersect instead? With that function, it will do a ray intersect with a full mesh, not just a single triangle. You just pass in your terrain and the picking ray, and you'll get a face index, a set of barycentric coords and a distance if there's a collision.

From there, you can use the XYZ of the face vertexes along with the barycentric coords it gives you to find the XYZ where the mouse click was, or just normalize your picking ray and mulitply it times the distance to find a less accurate XYZ.

Under the Gun Online

Share this post

Link to post
Share on other sites
hmm... Interesting..
can u show me example to use or where can i find that (don't sdk)?
most importantly to find XYZ...
Thanks for sharing.....:)

Share this post

Link to post
Share on other sites
Here's the source for a utility mesh interect that I'm using. I don't have an example of converting screen coords to world space coords, but you can find that on the net pretty easily.

I'm passing in an object (contains a pointer to a mesh) a ray start location, a ray direction (normalized) and pointers for output: a face index, a distance, and a XYZ vector that gets filled in with the intersection location. I don't think it's going to be as precise as generating the location from the barycentric coords, but for what I'm doing it doesn't matter as much.

bool CManagerInput::RayMeshIntersect( CWorldObject* pObject,
D3DXVECTOR3 *vec3RayOrigin,
D3DXVECTOR3 *vec3RayDest,
DWORD *dwIndex,
float *fDistOut,
D3DXVECTOR3 *vec3WorldSpaceIntersect )
if ( pObject->m_pMesh != NULL )
// there's a mesh, convert ray to model space
D3DXVECTOR3 vNear,vDir;
D3DXMatrixInverse( &invMat,NULL,&pObject->m_matWorld );

// test for intersection
BOOL bHit;
//DWORD dwIndex;
float u,v;
float dist;

// is there an intersection?
if (bHit)
*vec3WorldSpaceIntersect = vNear + ( vDir * dist );
*fDistOut = dist;
return true;

return false;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!