I'm using D3DXIntersect to get face index in mesh and that is working nice.
I don't know how to get normal for that face or normals for vertices that are forming that face. Actualy... only normal for first vertex would be enough.
I'm not realy liking that function after all. It seems to return a list of all the triangles that were intersected by the ray, wich means that it doesn't return as soon is it hits the first triangle, so it is not good for what I need.
I've changed my line/triangle intersection function with D3DXIntersectTri() thought.
You'll need to look it up based on whatever is stored in the pFaceIndex output.
Lock the index buffer and look up the [pFaceIndex * 3] index (or +0,+1,+2 for each vertex), you then need to use the index to look up the actual vertex - lock the vertex buffer and extract the properties.
It's not too hard to throw that together, but it does get complex when dealing with arbitrary meshes. Handling the 32bit case is okay, but for arbitrary vertices you either need to traverse the vertex declaration (see ID3DXBaseMesh::GetDeclaration()) or clone it to a known format (see ID3DXBaseMesh::CloneMesh[FVF]()).
If you do this sort of work on a regular basis (e.g. in the core loop) then it might be worth storing a CPU-addressable copy of the vertex data. Unless the mesh is pretty huge you shouldn't really waste that much RAM and it'll make the code simpler and faster (locking is rarely a quick operation). If you consider this, try using D3DXIntersectTri() instead of D3DXIntersect().
I'm always learning in this forum. There is a function on the D3DX API to check mesh/ray intersection and I've implemented it my self ! I see that I have to go thru all the D3DX api before implementing anything...
D3DXIntersect and getting face normal
Jason Payne
I've changed my line/triangle intersection function with D3DXIntersectTri() thought.
Brian Richards
Thanks!
T0MM0
Lock the index buffer and look up the [pFaceIndex * 3] index (or +0,+1,+2 for each vertex), you then need to use the index to look up the actual vertex - lock the vertex buffer and extract the properties.
It's not too hard to throw that together, but it does get complex when dealing with arbitrary meshes. Handling the 32bit case is okay, but for arbitrary vertices you either need to traverse the vertex declaration (see ID3DXBaseMesh::GetDeclaration()) or clone it to a known format (see ID3DXBaseMesh::CloneMesh[FVF]()).
If you do this sort of work on a regular basis (e.g. in the core loop) then it might be worth storing a CPU-addressable copy of the vertex data. Unless the mesh is pretty huge you shouldn't really waste that much RAM and it'll make the code simpler and faster (locking is rarely a quick operation). If you consider this, try using D3DXIntersectTri() instead of D3DXIntersect().
hth
Jack
bill4012
There is a function on the D3DX API to check mesh/ray intersection and I've implemented it my self !
I see that I have to go thru all the D3DX api before implementing anything...