Sign in to follow this  

Finding vertices from D3DXIntersect

Recommended Posts

Okay, so, I'm making a level editor that requires me to place spawn points on a mesh. The targeting code and all that works, but I keep getting REALLY bad values for the point's location. Intersect is checking for hits, and then I get the face index. I'm wondering how I can use that to get the triangle's coordinates. This is what the code looks like now: IDirect3DVertexBuffer9 *pBuffer; pMesh->GetVertexBuffer(&pBuffer); DWORD dwNumBytesPerVertex = pMesh->GetNumBytesPerVertex(); unsigned char *ucBuffer = new unsigned char[3 * dwNumBytesPerVertex]; pBuffer->Lock(dwFaceIndex * 3 * dwNumBytesPerVertex, 3 * dwNumBytesPerVertex, (void **)&ucBuffer, D3DLOCK_READONLY); From there, I've tried to read the data from the buffer into D3DXVECTOR3/float[3] arrays to no avail. Any help?

Share this post

Link to post
Share on other sites
It depends on how your mesh vertices and indices are setup.

Assuming you're using an indexed mesh which does not use 3 unique vertices per face, you're using the face index to access the vertex data, rather than to retrieve the indices for the vertices you want.

Here's a routine from one of my apps.

v1, v2, v3 are 3 structures (not float[3]!) in this case.


WORD *idxBuffer;
WORD iv1, iv2, iv3;

pTerrainMesh[i]->LockIndexBuffer(D3DLOCK_READONLY | D3DLOCK_NOOVERWRITE,(LPVOID*)&idxBuffer);
if( hr != D3D_OK ) { hit = FALSE; goto bad_return; }
iv1 = *(WORD*)(idxBuffer + faceIndex*3 + 0);
iv2 = *(WORD*)(idxBuffer + faceIndex*3 + 1);
iv3 = *(WORD*)(idxBuffer + faceIndex*3 + 2);
hr = pTerrainMesh[i]->LockVertexBuffer(D3DLOCK_READONLY | D3DLOCK_NOOVERWRITE, (PVOID*)&pVertex);
if( FAILED(hr) ) goto bad_return;
v1 = pVertex[iv1];
v2 = pVertex[iv2];
v3 = pVertex[iv3];

Share this post

Link to post
Share on other sites

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