Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting Vertex Positions

Started by treeway Jul 13, 2006 at 1:08 PM 3 replies 800+ views
Original Post
treeway
treeway
Hi Im working on making a rigid terrain using the Tokamak physics SDK. I want to read in the verticies from a DirectX Mesh and load them into the Tokamak terain vertices. Ive got most of it working but heres the problem: I have defined a custom vertex format containing only the position of each vertex in my 3d model:

struct CUSTOMVERTEX
{
	float x,y,z;   // The untransformed position for the vertex.
};

#define TERRAIN_VERTEX (D3DFVF_XYZ)

then i wrote a method to access the mesh loaded in:

void PhysicsTerrain::BuildTerrainMesh()
{

	base->D3dDevice->SetFVF(TERRAIN_VERTEX);

	// The array of vertices
	neV3* triVertices;
	// The array of triangles
	neTriangle* triData;

	int i, j;

	// Access the parent Mesh (already loaded)
	ID3DXMesh* parentMesh = m_Mesh->getParentMesh()->m_Mesh;   

        // Set the number of vertices into the triMesh
	triMesh.vertexCount = parentMesh->GetNumVertices();
	triMesh.triangleCount = parentMesh->GetNumFaces();


	CUSTOMVERTEX *pVertex = NULL;

	if(FAILED(parentMesh->LockVertexBuffer(D3DLOCK_READONLY, (BYTEVOID**)&pVertex)))
	{
		base->messageBox(NULL,"Failed to Lock Vertex Buffer","Physics Terrain");
		return;
	}

	triVertices = new neV3[triMesh.vertexCount];

	for(i = 0; i < triMesh.vertexCount; i ++)
	{
		triVertices.Set(pVertex->x,pVertex->y,pVertex->z);
		sprintf(base->buffer,"X %f, Y %f, Z %f \n Vertex: %d",pVertex->x,pVertex->y,pVertex->z,sizeof(pVertex));
		base->messageBox(NULL,base->buffer,"Vertex Data");
		pVertex ++;
	}
	parentMesh->UnlockVertexBuffer();


	// Set the vertices into the triMesh
	triMesh.vertices = triVertices;

.......... index buffer stuff (working) ......

	// Tell the simulator about our mesh
	base->physicsManager->PhysicsSimulator->SetTerrainMesh(&triMesh);
}
the problem is that although im specifying that it use my custom vertex format it is loading the texture coordinates and normals from each vertex. How do i read ONLY the position from the vertex?
don
don
Call ID3DXBaseMesh::GetNumBytesPerVertex and jump by that amount each iteration through your loop so that you're fetching the start of the vertex (where the positional data is stored):

Instead of this:

pVertex++;

Do this:

pVertex = (CUSTOMVERTEX*)((BYTE*)pVertex + parentMesh->GetNumBytesPerVertex());

treeway
treeway
Thanks don :)

worked perfectly with dc 9.0 but the only problem is that dx 8.1 doesnt have the getGetNumBytesPerVertex() funtion and my engine is meant to be compatible with both (for xbox). Anyone know another way to get the number of bytes per vertex? from the getFVF or something?
don
don
Pass the FVF to D3DXGetFVFVertexSize.
treeway
treeway
wicked working perfectly

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.