Sign in to follow this  

[MDX] Getting exact intersect position between ray and mesh

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

This topic is 4304 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this