I'm trying to get the intersected face vertices and not sure if I should use D3DXInterect() or D3DXIntersectTri().
If I have to use D3DXIntersectTri(), I don't know how I should pass LPD3DXMESH like I do in D3DXInterect().
I'm trying to get the intersected face vertices and not sure if I should use D3DXInterect() or D3DXIntersectTri().
If I have to use D3DXIntersectTri(), I don't know how I should pass LPD3DXMESH like I do in D3DXInterect().
With D3DXIntersectTri() you pass in a face(3 vertices) so you already know what the intersected face is.
Unless you want to call this function for every face on the mesh you probably want to stick with D3DXInterect() and read the DWORD *pFaceIndex, parameter.
I'm not sure how should I use D3DXIntersectTri()
I tried:
D3DXIntersectTri(&v1, &v2, &v3, &rayOrigin, &rayDirection, NULL, NULL, NULL);
But it doesn't work.
Basically, I am trying to get the intersected face vertices to create bullet holes.
I found out that I should be doing something like this:
D3DXVECTOR3 *vertices;
mesh->LockVertexBuffer(D3DLOCK_READONLY, (void **)&vertices);
for(int j = 0; j < mesh->GetNumFaces(); j++)
{
p1 = vertices[j];
p2 = vertices[j+1];
p3 = vertices[j+2];
if (D3DXIntersectTri(&p1, &p2, &p3, &rayOrigin, &rayDirection, NULL, NULL, NULL))
{
// p1, p2, p3 are the intersected face vertices
}
}
Let me know if this is correct.
Seems right, but you want to read the UV values to know where on the texture you want to place the holes, if that is the method you use.
This function returns the resulting point by using the following equation: V1 + U(V2 - V1) + V(V3 - V1).
The function is not advanced it just figures out if a ray intersect with the triangle with a few equations and returns the result.
To place the bullet hole, I think I need:
- The intersection point
- The intersected face (v1, v2 and v3)
How I will use the equation V1 + U(V2 - V1) + V(V3 - V1) ?