Jump to content
  • Advertisement
Sign in to follow this  

Am i accessing the index/vertex buffer correctly?

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

Well, what i am doing is basically checking the area under the camera to see what polygon it is over with the following code:
BOOL bHit;
DWORD dwFace;
float fBary1, fBary2, fDist;
D3DXIntersect(m_pMesh, &pRayPos, &pRayDir, &bHit, &dwFace, &fBary1, &fBary2, &fDist, NULL, NULL);
struct intersect intersectO;
//	fvf = m_pMesh->GetFVF();
BYTE *vertices;
BYTE *offsets;

	m_pMesh->LockIndexBuffer( 0,  &offsets  );
	m_pMesh->LockVertexBuffer(D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK, &vertices);

unsigned int stride = D3DXGetFVFVertexSize(m_pMesh->GetFVF());

// Seek to the first vertex of the given face
vertices += (unsigned char)((stride) * ((offsets[3 * dwFace - 2])));
intersectO.v1 = *reinterpret_cast<D3DXVECTOR3*>(vertices);

vertices += (unsigned char)((stride) * ((offsets[3 * dwFace - 1])));
intersectO.v2 = *reinterpret_cast<D3DXVECTOR3*>(vertices);

vertices += (unsigned char)((stride) * ((offsets[3 * dwFace - 0])));
intersectO.v3 = *reinterpret_cast<D3DXVECTOR3*>(vertices);
intersectO.face = dwFace;
Vtest = intersectO;


I then take the resulting vertex information and render that polygon again... i set it so the rest of the level renders in wireframe and the polygon im standing on to render filled, but it doesnt seem to be working right, i was working with the numbers gotten from the index buffer and it still seems to be accessing the wronge verticies... any ideas?

Share this post

Link to post
Share on other sites
Try this instead for getting the actual vertices.

intersect0.v1 = *reinterpret_cast<D3DXVECTOR3*>(vertices + stride*offsets[3*dwFace+0]);
intersect0.v2 = *reinterpret_cast<D3DXVECTOR3*>(vertices + stride*offsets[3*dwFace+1]);
intersect0.v3 = *reinterpret_cast<D3DXVECTOR3*>(vertices + stride*offsets[3*dwFace+2]);

I think the problem was that you were changing the "vertices" pointer. The index buffer tells you where in your vertex buffer to look. There's no need to change the "vertices" pointer.


Share this post

Link to post
Share on other sites
What is your simulation or game about? Checking if the camera is above each polygon is not very efficient at all. I assume that you are using simple checks already to eliminate this check - bounding spheres or planes etc

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!