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

getting triangles from D3DXMesh

Started by MadProgrammer Jan 27, 2004 at 5:20 PM 1 replies 600+ views
Original Post
MadProgrammer
MadProgrammer
i know this has got to have been discussed before, but searching the forums doesnt work for me, so i post this: i''m working on collision detection for a game. i need to get the triangles out of a d3dxmesh so i can check collision on them. any tips? tutorials? previous posts? anything? also, once i get the triangle out of the mesh, will they have normals on them, and if so, will the normals be pointing outwards or inwards? matt
RenderTarget
RenderTarget
You''ll have to get the index and vertex buffers from the mesh, and use those to get triangles. The IB is set up as a triangle list, so every three indices specifies a triangle.

The vertices might have normals, or might not. Whatever is in the .x file, or however the mesh was generated. If it doesn''t have normals, you could clone the mesh and use D3DXGenerateNormals(), but there''s no guarantee on the facing.

If the mesh renders correctly on screen, then any normals it has will be faced outwards.

I like pie.
[sub]My spoon is too big.[/sub]
ms291052
ms291052
I have my vertices store in my MESH class, as well as the indices. Keep in mind that if you don''t have these stored you can use Mesh->LockVertexBuffer and Mesh->LockIndexBuffer to get pointers to the same data.
struct Vertex
{
D3DXVECTOR3 pos;
D3DXVECTOR3 normal;
D3DXVECTOR2 TexCoords
}

Vertex v0 = Mesh->m_Vertices[Mesh->m_Indices[face*3]].pos;
Vertex v1 = Mesh->m_Vertices[Mesh->m_Indices[face*3 + 1]].pos;
Vertex v2 = Mesh->m_Vertices[Mesh->m_Indices[face*3 + 2]].pos;


Whether the vertices have normals is dependant on your FVF (which you hopefully know) but to make sure you could clone/Generate as stated above.

Topic Locked

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

Sign in to reply to this topic.