# Help .. really quick question about intersect

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

## Recommended Posts

i have a terrain in a mesh. i transform the mouse click correctly and use the D3DXIntersect() function. i have it setup as D3DXIntersect(pMesh, &vecMeshRay,&vecMeshDir, &hit, &Face, &u, &k, &Dist, NULL, NULL); the u and k are pointers to the barycentric hit coordinates, U and V. my question is how do i then take that information and determain where to move a mesh. for example. i have a terrain i click on it, i want to put a ball at the spot i clicked on the terrain. I know ive got to be able to use the barycentric coordinates somehow to determin the posistion my terrain is a .x file. im using c++ compiler and direct x any help is greatly appreciated

##### Share on other sites
I don't know anything about D3D, but I'm just going to venture a guess based on the function parameters you posted. I would think that 'face' would be the index of the face that the ray intersected. U and V are the barycentric coordinates, as you noted, with W = 1-U-V. Assuming you can use the value of 'face' to find the vertices v0, v1, v2 of the triangle that was hit, then:

hitPoint = U*v0 + V*v1 + W*v2

Also, if 'dist' is the parametric point of intersection for the ray:

hitPoint = rayOrigin + dist * rayDirection

Anyway, that's just a guess - maybe someone else can confirm it.

##### Share on other sites
i know this is a pretty dumb question but how do i do this in code?

hitPoint = rayOrigin + dist * rayDirection?

from my code snipet i can't just do

D3DXVECTOR3 hitpoint = vecRay + Dist * vecDir

##### Share on other sites
Quote:
 i know this is a pretty dumb question but how do i do this in code?
As far as I can tell, the second and third arguments are the ray origin and direction, respectively. So given your variable names, it would be:

D3DXVECTOR3 hitpoint = vecMeshRay + Dist * vecMeshDir;

Those names are a little confusing to me, though - I'd use something like 'vecRayOrigin' and 'vecRayDir' instead.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015430
×