• Advertisement


This topic is now archived and is closed to further replies.

LPD3DXMESH Collision Detection

This topic is 5470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
bool CEGIMesh::Collide( D3DXVECTOR3 *pVStartPoint, D3DXVECTOR3 *pVEndPoint )
	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;
	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;
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

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
wouldn''t Direction need to be -Direction in one of the D3DXIntersect calls?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

  • Advertisement