Jump to content
  • Advertisement
Sign in to follow this  
Darkus

[MDX] Getting exact intersect position between ray and mesh

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

Hi, I am trying to find exact intersect position between ray and mesh. I can get triangle thru which ray goes and its coordinates and U and V value of intersect info. What I would like to get is X, Y and Z of the point where ray hits the mesh related to mesh object. Thanks for all your help.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I saw that already but as any good newbie I'm to lame to understand how can I get coordinates from it. If anyone can share any sample would be greatly appreciated.

Thanks.

Share this post


Link to post
Share on other sites
float w = 1.0f - (U + V);
float Xpos = (U * X[0] + V * X[1] + w * X[2]);
float Ypos = (U * Y[0] + V * Y[1] + w * Y[2]);
float Zpos = (U * Z[0] + V * Z[1] + w * Z[2]);

where X, Y, & Z are the three points of the triangle.

hth.
n.

Share this post


Link to post
Share on other sites
Here is the DX way:

D3DXVECTOR3 A1, A2, A3;

hr = D3DXIntersect(mIWorkMesh, &orig, &dir, &hit,
&FaceHit, &u, &v, &dist, &AllHits, &numHits);

V( mIWorkMesh->LockIndexBuffer(D3DLOCK_READONLY, (LPVOID*)&IB) );
V( mIWorkMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pB) );

VP = reinterpret_cast<VertexP*>(pB + IB[FaceHit].a * mVertexDesc.mStride[0]);
A1 = VP->pos;
VP = reinterpret_cast<VertexP*>(pB + IB[FaceHit].b * mVertexDesc.mStride[0]);
A2 = VP->pos;
VP = reinterpret_cast<VertexP*>(pB + IB[FaceHit].c * mVertexDesc.mStride[0]);
A3 = VP->pos;

V( mIWorkMesh->UnlockIndexBuffer() );
V( mIWorkMesh->UnlockVertexBuffer() );

D3DXVECTOR3 P1;

D3DXVec3BaryCentric(&P1, &A1, &A2, &A3, u, v);


P1 has the location of the intersection in the mesh's local space. Just transform it by your world matrix for the mesh if you need world space coordinates.



Share this post


Link to post
Share on other sites
Thanks for help. Can somebody explain how to get triangle vectors from mesh object in MDX?

I guess I'm missing only this part from success :-)

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!