Jump to content
  • Advertisement
Sign in to follow this  
JPSerna

Finding vertices from D3DXIntersect

This topic is 3789 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
Advertisement
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.


struct TERRAINVERTEX {
D3DXVECTOR3 v, n;
D3DXVECTOR2 t;
};

TERRAINVERTEX v1, v2, v3;
TERRAINVERTEX *pVertex;
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);
pTerrainMesh->UnlockIndexBuffer();
hr = pTerrainMesh->LockVertexBuffer(D3DLOCK_READONLY | D3DLOCK_NOOVERWRITE, (PVOID*)&pVertex);
if( FAILED(hr) ) goto bad_return;
v1 = pVertex[iv1];
v2 = pVertex[iv2];
v3 = pVertex[iv3];
pTerrainMesh->UnlockVertexBuffer();

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!