Hi everybody,
This is for the more advanced people! I know that the DirectX9 D3DXIntersect function has the ability to gives the exact coordinates of the intersecting ray-to-polygon, and can give the distance from the ray’s starting point to the intersection point.
Now my question is, how do I retrieve that information of the exact coordinates of the ray’s intersecting point?
I think the information if I’m not mistaken is found in the LPD3DXBUFFER * ppAllHits, but I’m not sure as to how to setup the buffer, nor access the information.
Please help… Thanks!
____________________________________________
Code:
// DirectX9 D3DXIntersect function:
// Determines if a ray intersects with a mesh.
HRESULT D3DXIntersect(
LPD3DXBASEMESHpMesh,
CONST D3DXVECTOR3 * pRayPos,
CONST D3DXVECTOR3 * pRayDir,
BOOL *pHit,
DWORD * pFaceIndex,
FLOAT * pU,
FLOAT * pV,
FLOAT * pDist,
LPD3DXBUFFER * ppAllHits,
DWORD * pCountOfHits);
____________________________________________
My variables and code:
Note: My code works great. I just need help with getting the exact coordinates of my ray’s intersection with the mesh.____________________________________________
Code:
float XBegin, float YBegin, float ZBegin; // <-- Starting Position of Ray
float XEnd, float YEnd, float ZEnd; // <-- Ending Position of Ray
sMesh *LevelMesh;
BOOL Hit;
float u, v, Dist;
float XDiff, YDiff, ZDiff, Radius;
DWORD FaceIndex;
D3DXVECTOR3 vecDir;
// looking for collision intersection
while(LevelMesh != NULL) {
D3DXIntersect(LevelMesh->m_Mesh, \
&D3DXVECTOR3(XBegin,YBegin,ZBegin), &vecDir, \
&Hit, &FaceIndex, &u, &v, &Dist, NULL, NULL);
if(Hit == TRUE) {
if(Dist < Radius)
return TRUE; // polygons hit
}
return FALSE; // No polygons hit
}