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


Corner Sucks in my Sphere!

Recommended Posts

For the majority, this code works flawlessy for detecting sphere against bounding box collision. Only problem is if the moving mesh with the bounding sphere slides to any corner of the bounding box of the mesh being tested against, will sometimes suck the mesh in, and only be reversible by exiting out the corner. Any one have a solution or advice, would be greatly apprieciated!!!
bool const cModel::CheckBoxIntersect( D3DXVECTOR3 const& vLoc, D3DXVECTOR3 const* const& vBoundBox, char const cDirection )
	D3DXVECTOR2 vDelta( m_vLoc.x + (cDirection == ''1'' ? m_vVel.x : -m_vVel.x), m_vLoc.z + (cDirection == ''1'' ? m_vVel.y : -m_vVel.y) );
  	D3DXVECTOR2 vDiff( vDelta.x - vLoc.x, vDelta.y - vLoc.z );	// relative position of sphere centre to the box centre

	D3DXVECTOR2 vExt( vBoundBox[1].x - vBoundBox[0].x, vBoundBox[1].z - vBoundBox[0].z ); // size of the box along X, Z direction.

 	// see if sphere coords are within the box coords

	float fDx = vExt.x - fabs(vDiff.x) + m_fFrustum;	// distance of sphere centre to one of the X-Face of the box

	float fDz = vExt.y - fabs(vDiff.y) + m_fFrustum;	// distance of sphere centre to one of the Z-Face of the box

	bool bOutx  =  (fDx < 0.0f);		// sphere centre between the two X-Faces of the box

	bool bOutz  =  (fDz < 0.0f);		// sphere centre between the two Z-Faces of the box

	bool bIn    = !(bOutx|bOutz);		// sphere centre inside all the faces of the box

	if (bIn)
		float fMinDist = fDx;

		if ( fDz < fMinDist )
			m_vVel.y = 0.0f;
			m_vVel.x = 0.0f;

		return true;
	return false;
[edited by - Carandiru on April 21, 2004 3:48:29 AM]

Share this post

Link to post
Share on other sites