3 is bigger than 9/3

Started by
18 comments, last by Bru 15 years, 1 month ago
hey there, i would like to discuss about a strange problem i am having with the directX api. i have a mesh. now i got the vertex list from its vertex buffer. tryed to use Mesh->GetNumFaces() in the loop that creates the vertex list, and use Mesh->GetNumVertices()/3 in another loop that checks collision with 3 vertices at a time. ofc my whole collision system seem to be buggy, but after hours of debugging i found out that one of the things that may cause it is that GetNumFaces brings a bigger result by about 100 than GetNumberVertices/3, which seems damn odd to me. correct me if i am wrong, a face is a triangle? a triangle has 3 vertices? 3 vertices are one triangle? then how comes the results are not equal?
Advertisement
You could have a triangle strip or fan, which wouldn't be 3 vertices per triangle - although I think I heard that ID3DXMesh only uses triangle lists (I don't use ID3DXMesh).

The likely cause is that the index buffer references multiple vertices. You'll want to get the index buffer too, and see how many indices are in it.
Hi,

usually one vertex is shared or referenced by multiple adjacent triangles. getNumIndices()/3 is what you are looking for.

regards
------------------------------------I always enjoy being rated up by you ...
The mesh might be indexed which reduces the number of vertices.
my blog contains ramblings and what I am up to programming wise.
Quote:Original post by Evil Steve
You could have a triangle strip or fan, which wouldn't be 3 vertices per triangle - although I think I heard that ID3DXMesh only uses triangle lists (I don't use ID3DXMesh).

The likely cause is that the index buffer references multiple vertices. You'll want to get the index buffer too, and see how many indices are in it.


oh i see, this makes sense. this might also be the reason why my collision function seems to a bit while checking collision.
thanks :) i'll rate you as helpfull
I haven't worked with the DX mesh, but I think that it's possible that the mesh gets optimized, this means that the number of vertices is not numberOfFaces*3.
ID3DXMesh only uses indexed triangle lists. This means that in all but the most pathological case, you will have less than 3 vertices per triangle.
Quote:Original post by Waterwalker
Hi,

usually one vertex is shared or referenced by multiple adjacent triangles. getNumIndices()/3 is what you are looking for.

regards


unfortunately there's no such method in ID3DXMesh
Quote:Original post by Bru
Quote:Original post by Waterwalker
Hi,

usually one vertex is shared or referenced by multiple adjacent triangles. getNumIndices()/3 is what you are looking for.

regards


unfortunately there's no such method in ID3DXMesh
You can always use GetIndexBuffer() - although I suspect there's a cleaner way:
UINT GetNumIndicesInMesh(ID3DXBaseMesh* pMesh){   // Get the index buffer   LPDIRECT3DINDEXBUFFER9 pIB;   HRESULT hResult = pMesh->GetIndexBuffer(&pIB);   if(FAILED(hResult))      return 0;   // Get the buffer description   D3DINDEXBUFFER_DESC desc;   hResult = pIB->GetDesc(&desc);   pIB->Release();   if(FAILED(hResult))      return 0;   if(desc.Format == D3DFMT_INDEX16)      return desc.Size / 2;   else if(desc.Format == D3DFMT_INDEX32)      return desc.Size / 4;   // Unknown format   return 0;}


EDIT: Actually, if ID3DXMesh only uses indexed triangle lists, then the number of indices is implicitly the number of faces times 3. Although you could use the above code to verify that if you really want.
Quote:Original post by Evil Steve
Quote:Original post by Bru
Quote:Original post by Waterwalker
Hi,

usually one vertex is shared or referenced by multiple adjacent triangles. getNumIndices()/3 is what you are looking for.

regards


unfortunately there's no such method in ID3DXMesh
You can always use GetIndexBuffer() - although I suspect there's a cleaner way:
*** Source Snippet Removed ***

EDIT: Actually, if ID3DXMesh only uses indexed triangle lists, then the number of indices is implicitly the number of faces times 3. Although you could use the above code to verify that if you really want.


thanks i'll try that :)
i hope its ok if i'll use this thread for another question, better ask it here than open another thread and be getting my user rating raped even more.
the thing is i have my collision function that recives vertex as D3DXVCTOR3*.
now i pass it a vertex list(which seems to be completly fine when i checked it) in a loop, and sometimes it seems like the third parameter which is the third vertex arrives as ???? instead of a number, and this kills my calculations.
now i didnt bring any code since its a bit alot, but if i'll know what might cause the parameter to sometimes become ???? i might be able to fix it.
so what might screw it?

This topic is closed to new replies.

Advertisement