@Postie:
First, I use bullet physics raycasting to check for intersection, then I use D3DXIntersect() to get the intersected triangle, rayFrom and rayTo are D3DXVECTOR3 that I use with bullet physics raycasting.
I changed the code to something like this:
LPD3DXMESH pMesh = GetMesh();
pMesh->CloneMeshFVF( D3DXMESH_MANAGED, pMesh->GetFVF(), d3ddev, &pMesh );
WORD* pIndices;
D3DVERTEX* pVertices;
pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pVertices);
pMesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&pIndices);
BOOL pHit;
DWORD pFaceIndex;
FLOAT pU, pV, pDist;
HRESULT hr = D3DXIntersect(pMesh, &rayFrom, &rayTo, &pHit, &pFaceIndex, &pU, &pV, &pDist, NULL, NULL);
assert(hr == S_OK);
if (pHit)
{
D3DXVECTOR3 v0 = pVertices[pIndices[3 * pFaceIndex + 0]].p;
D3DXVECTOR3 v1 = pVertices[pIndices[3 * pFaceIndex + 1]].p;
D3DXVECTOR3 v2 = pVertices[pIndices[3 * pFaceIndex + 2]].p;
}
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
Anything wrong with the above code?