Jump to content
  • Advertisement
Sign in to follow this  
Bru

3 is bigger than 9/3

This topic is 3440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hi,

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

regards

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!