Sign in to follow this  

Obtaining mesh.x coordinates with C++

Recommended Posts

Hi, im fairly new to programming and even direct x in general. I have built a simple 3D racing game before and came up with a collision detection method. However this method was quite poor. Surely there is a way to extract the coordinates of a mesh.x file in direct x into an array or something. These coordinates could then be used to create a much better collision detection system. Any help would be great!

Share this post

Link to post
Share on other sites
I belive you could grab them by iterating through the index buffer and vertex buffer of the mesh and storing them in some sort of triangle(polygon) object, incorporated with a linked list or array. You can get the index and vertex buffers of the mesh the following way.

The code isn't full code but it gives you the idea.

g_pMesh->GetVertexBuffer( &pVB );
g_pMesh->GetIndexBuffer( &pIB );

pVB->Lock( 0, 0, (void**)&pVertices, 0 );
pIB->Lock( 0,0, (void**)&pIndices, 0 );
polygon[i].point1 = pVertices[pIndices[i*3]].p;
polygon[i].point2 = pVertices[pIndices[i*3+1]].p;
polygon[i].point3 = pVertices[pIndices[i*3+2]].p;

I hope that helps. [grin]

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