bool CEGIMesh::Collide( D3DXVECTOR3 *pVStartPoint, D3DXVECTOR3 *pVEndPoint )
{
HRESULT r;
D3DXVECTOR3 Direction;
float DistTraveled;
D3DXVec3Subtract( &Direction, pVStartPoint, pVEndPoint );
DistTraveled = D3DXVec3Length( &Direction );
if ( DistTraveled == 0 ) return false;
BOOL Hit;
DWORD FaceIndex1, FaceIndex2;
float U, V, DistToCollision;
LPD3DXBUFFER pAllHits;
DWORD nHits1, nHits2;
r = D3DXIntersect( m_pMesh, pVStartPoint, &Direction, &Hit, &FaceIndex1, &U, &V, &DistToCollision, &pAllHits, &nHits1 );
if ( !Hit ) return false;
r = D3DXIntersect( m_pMesh, pVEndPoint, &Direction, &Hit, &FaceIndex2, &U, &V, &DistToCollision, &pAllHits, &nHits2 );
if ( nHits1 != nHits2 ) return true;
return false;
}
LPD3DXMESH Collision Detection
I''ve written this function in order to determine if a line segment has passed into or through a mesh. For some reason it is only returning true if pVStartPoint is trapped inside a mesh and pVEndPoint is outside the mesh.
The function checks if a ray from pVStartPoint passes through as many faces as a ray from pVEndPoint. If not than a face lies directly between them.
If anyone could help I''d be very grateful.
Thanks in advance
Its amazing how a good night''s rest can help find the problem. In a matter of minutes this morning I found the answer.
Your right. Direction is backwards, but in both the D3DXIntersect calls.
D3DXVec3Subtract( &Direction, pVStartPoint, pVEndPoint );
should be
D3DXVec3Subtract( &Direction, pVEndPoint, pVStartPoint );
Thanks for your help.
Your right. Direction is backwards, but in both the D3DXIntersect calls.
D3DXVec3Subtract( &Direction, pVStartPoint, pVEndPoint );
should be
D3DXVec3Subtract( &Direction, pVEndPoint, pVStartPoint );
Thanks for your help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement