I'm trying to retrive vertex data from a mesh but can't get the vertex indices right. Here's the code I'm using:
UINT16 i0, i1, i2;
unsigned long TerrainFaceIndex;
D3DXIntersect( IntersPl.PlBottom.m_pMesh, &rayObjOrigin, &rayObjDirection, &HitBottom, &TerrainFaceIndex, &IntersPl.baryBottom.X, &IntersPl.baryBottom.Y, NULL, NULL, NULL);
Log("TerainFaceIndex %3.3ld \n", TerrainFaceIndex );
LPDIRECT3DINDEXBUFFER9 pIBx;
LPDIRECT3DVERTEXBUFFER9 pVBx;
IntersPl.PlBottom.m_pMesh->GetIndexBuffer(&pIBx);
IntersPl.PlBottom.m_pMesh->GetVertexBuffer(&pVBx);
WORD* pIndicesMs;
rslt=IntersPl.PlBottom.m_pMesh->LockIndexBuffer(D3DLOCK_READONLY, reinterpret_cast< VOID** >( &pIndicesMs ) );
if(FAILED(rslt)) { LogDX("Failed to Lock the Mesh IndexBuffer 'loading2.jpg' \n",rslt); }
i0 = pIndicesMs[TerrainFaceIndex * 3 + 0 ];
i1 = pIndicesMs[TerrainFaceIndex * 3 + 1 ];
i2 = pIndicesMs[TerrainFaceIndex * 3 + 2 ];
IntersPl.PlBottom.m_pMesh->UnlockIndexBuffer( );
Log("Face Index 1 %3.3d \n", i0);
Log("Face Index 2 %3.3d \n", i1);
Log("Face Index 3 %3.3d \n", i2);
The output in the Log file:
TerainFaceIndex 27778
Face Index 1 39041
Face Index 2 000
Face Index 3 39042
TerainFaceIndex 27525
Face Index 1 000
Face Index 2 7064
Face Index 3 000
TerainFaceIndex 27525
Face Index 1 000
Face Index 2 7064
Face Index 3 000
TerainFaceIndex 27522
Face Index 1 7063
Face Index 2 000
Face Index 3 6934
TerainFaceIndex 27522
Face Index 1 7063
Face Index 2 000
Face Index 3 6934
What am I doing wrong?