Archived

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

CamelFly

Brush collision problems

Recommended Posts

After spending some time analyzing, calculating and simple trial and error i seem to have exhausted my resources on this one. I have a working bsp engine running but i cant make the collision work properly. Sure it works fine with a size of the particle colling set to 0 but when i offset the planes of the brush by some number all goes haywire and nothing works at all, which seems funny to me since it _should_ work. Anyway, heres the code i''ve tried. Can you see anything inappropriate in it? ( Also check the NOTE: in the code for further explanation )
  
inline bool CBrush::CheckCollision( const D3DXVECTOR3& vPos1, const D3DXVECTOR3& vPos2,
		float& rfInterpol, D3DXPLANE*& rpPlane, const float fSize /* = 0.0f */ ) const
{
	float	fBestT = 2.0f;
	int		iBestIndex = -1;

	D3DXVECTOR3 vToPos2 = vPos2 - vPos1;

	// Dot to all the planes, finding two points that intersect inside the 

	// bounding volume

	for ( int i = 0; i < m_nPlanes; ++i )
	{
		const float fDot2 =	vToPos2.x * m_apPlanes[ i ]->a + 
							vToPos2.y * m_apPlanes[ i ]->b + 
							vToPos2.z * m_apPlanes[ i ]->c;

		// Check for plane parallellity

		if ( fDot2 != 0.0f )
		{
			const float t = ( -1.0f * ( 
				vPos1.x * m_apPlanes[ i ]->a + 
				vPos1.y * m_apPlanes[ i ]->b + 
				vPos1.z * m_apPlanes[ i ]->c +
						  m_apPlanes[ i ]->d ) ) / fDot2;
// NOTE: Here ive tried offsetting using m_apPlanes[ i ]->d + fSize but that dont work. Neither does subtracting fSize from d

			// Check for intersection legality

			if ( t >= 0.0f && t <= 1.0f )
			{
				DEBUGOUTPUT_Printf( "t: %f  ts: %f", t, ts );

				if ( t < fBestT && IsInside( vPos1 + vToPos2 * t, 0.01f ) )
				{
					fBestT = t;
					iBestIndex = i;
				}
			}
		}
	}

	// Return properly

	if ( iBestIndex >= 0 )
	{
		rfInterpol = fBestT;
		rpPlane = m_apPlanes[ iBestIndex ];
		return true;
	}
	else
	{
		rfInterpol = 1.0f;
		rpPlane = NULL;
		return false;
	}
}
  
[Insert cool signature here]

Share this post


Link to post
Share on other sites