Jump to content
  • Advertisement
Sign in to follow this  

Finding vertices from D3DXIntersect

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

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->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->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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!