# Loop through a loaded .x file's vertices

I need to compute the "gravity center" of a mesh, some kind of barycenter, and then find the farest vertices to compute a bounding sphere.

Here is what I have for the moment:

D3DXVECTOR3 result(0,0,0);
int num = mesh -> GetNumVertices();
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
mesh -> GetVertexBuffer((*vertexBuffer));
void* rawData;
vertexBuffer -> Lock(0, mesh->GetNumBytesPerVertex() * mesh->GetNumVertices(), &rawData, D3DLOCK_READONLY);
D3DVERTEXELEMENT9 decl;//[MAXD3DDECLLENGTH];
UINT numElements;
mesh -> GetDeclaration();
mesh -> GetFVF();


Apparently I need to cast the rawdata pointer, but I don't know what to do next...

• I assume this is pseudocode? Because you're missing parameters and/or not saving off useful return values here.
– user1430
Mar 25 '11 at 19:25
• This seems to be C++ code, but yes, some functions miss parameters... Mar 25 '11 at 19:39

You can save off all this positional data into a container (like a std::vector) and process it after the fact, or you can run your algorithm as you do the extraction, if appropriate.