ID3DXMESH incorrectly reports number of vertices

Started by
3 comments, last by UnknownPlayer 21 years ago
I''m using the following code to generate a sphere to use as my world sphere and then flip all of its normals so that the faces are visible inside the sphere but not out. The problem though is that the number of vertices the mesh is reporting to me seems incorrect - there''s a whole lot of uninitialized values in the higher numbers, but the lower ones are correct. This seems to indicate to me that too many vertices are being reported and I''m exceeding my array bounds.
  
void CWorld::CreateWorldSphere()
{
	bWorldInit = true;

	// Create a basic sphere to play around with

	LPD3DXMESH Sphere;
	HRESULT hr = D3DXCreateSphere(App()->d3ddevice, WORLD_SPHERE_RADIUS, WORLD_SLICES, WORLD_STACKS,
		&Sphere, null);

	// Did we succeed?

	if (FAILED(hr))
	{
		lprintf("Failed to create a world sphere in CWorld for some reason. You probably noticed this.");
		bWorldInit = false;
		return;
	}

	// Copy the mesh to the world with the correct FVF settings

	hr = Sphere->CloneMeshFVF(D3DXMESH_MANAGED, FVFvertWorldVertex, App()->d3ddevice, &WorldSphere);

	if (FAILED(hr))
	{
		lprintf("Failed CloneMeshFVF on the original sphere in CWorld - world setup failed");
		bWorldInit = false;
		return;
	}

	// Invert all the normals of the mesh so that the sphere will point inwards towards the player

	vertWorldVertex* pVertices;		// Pointer to the data in the vertex buffer

	WorldSphere->LockVertexBuffer(null, (BYTE**)&pVertices);

	DWORD dwNumVertices = WorldSphere->GetNumVertices();

	for (int i=0; i < dwNumVertices; i++)
	{
		pVertices->Normal *= -1.0f;
		pVertices++;
	}

	WorldSphere->UnlockVertexBuffer();
}
  
Does anyone know why this is happening or how to fix it? ##UnknownPlayer##
##UnknownPlayer##
Advertisement
What is your FVFvertWorldVertex and vertWorldVertex? I don''t know if flipping the normals is enough. I should also reverse the vertex order 1, 2, 3 to 1, 3, 2 so that backface culling works again.

- Mete
This is the vertex declaration and its associated FVF flags:


    struct vertWorldVertex{	D3DXVECTOR3 Pos;	D3DXVECTOR3 Normal;	D3DXVECTOR2 TextureCoord;};#define FVFvertWorldVertex (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX0|D3DFVF_TEXCOORDSIZE2(0))    


At any rate, I can figure out the problems with changing the orientation of the faces that get generated, what I want to know is why I'm getting vertex sizes that are apparently out of range of the mesh VB.

##UnknownPlayer##

[edited by - UnknownPlayer on April 1, 2003 5:32:50 AM]
##UnknownPlayer##
i don''t think your vertex struct and your FVF match up. you have a texture coord in the vertex struct but your specifying no texture coords in the FVF (TEX0).

try either specifying the FVF as D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 or taking the texture coord out of the vertex struct.
Hmm - I think that was in fact, the problem!
##UnknownPlayer##

This topic is closed to new replies.

Advertisement