Jump to content
  • Advertisement

Archived

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

broncosoftcr

Collision Detection and Redrawing specific Mesh Faces

This topic is 5281 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

Hello, I''m trying to use D3DXIntersect to do some of my collision detection, specifically the collision between the player and the level their in. Below is the code I have right now:
void CCollisionMgr::CheckForCollision(float *pfPos, float *pfVel, float *fpRotate, bool *pbMov)
{
	BOOL bHit;
	float fU(0), fV(0), fDist(0);
	float fXDiff, fYDiff, fZDiff, fSize;
	DWORD dwFaceIndex;
	D3DXVECTOR3 vecDir;

	fXDiff = pfVel[0];//pfPos[0]+pfVel[0];
	fYDiff = pfVel[1];//pfPos[1]+pfVel[1];
	fZDiff = pfVel[2];//pfPos[2]+pfVel[2];

        //Rotate the direction vector so it matches the 
        //direction player is actually heading
	vecDir = D3DXVECTOR3(fXDiff, fYDiff, fZDiff);
	D3DXMATRIX smRotation;
	D3DXMatrixRotationYawPitchRoll(&smRotation, fpRotate[1], fpRotate[0], fpRotate[2]);//m_fYRot, m_fXRot, m_fZRot);
	D3DXVec3TransformCoord(&vecDir, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &smRotation);
	D3DXVec3Normalize(&vecDir, &D3DXVECTOR3(fXDiff, fYDiff, fZDiff));

	//Intersection test
	std::list::iterator itr;
	for(itr=m_vLevelObjects.begin(); itr!=m_vLevelObjects.end(); ++itr){
		D3DXIntersect((*itr)->GetMesh()->GetMesh(), &D3DXVECTOR3(pfPos[0], pfPos[1], pfPos[2]),
			&vecDir, &bHit, &dwFaceIndex, &fU, &fV, &fDist, 0, 0);
	}

	
	if (bHit==TRUE)
	{
		fSize = (float)sqrt(fXDiff*fXDiff+fYDiff*fYDiff+fZDiff*fZDiff);
		

		if (fDist>fSize)
		{
			bHit=FALSE;
		}
		else{
	              //Collision
		}
	}
        //Otherwise nothing hit
	if (bHit==TRUE)
	{
		pbMov[0]=true;
		pbMov[1]=true;
		pbMov[2]=true;
	}
	else
	{
		pbMov[0]=false;
		pbMov[1]=false;
		pbMov[2]=false;
	}
	return;
}
 
As it stands, this consistently says that the players path does intersect the mesh, but it always gives a distance to the intersection as being right around 660 (this never changes). So my first question would be does anyone know why this isn''t working at all? Secondly, I figure it might help to debug it if I could rerender whatever face the player is supposdly intersecting but I''m not sure how to use the face index generated from D3DXInteresect to access the face and then rerender it. Thanks for the help. - Chris

Share this post


Link to post
Share on other sites
Advertisement
For those of you checking this, if you know of a better method or know of a tutorial on doing collision detection with a mesh, that'd be great. Thanks again.

-Chris

[edited by - broncosoftcr on June 1, 2004 11:42:14 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!