Jump to content
  • Advertisement
Sign in to follow this  
wizardpc

Help .. really quick question about intersect

This topic is 4813 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

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


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


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


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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!