[MDX] Getting exact intersect position between ray and mesh

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

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 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 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 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 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 :-)

1. 1
2. 2
Rutin
29
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• Forum Statistics

• Total Topics
633647
• Total Posts
3013108
×