Archived

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

ZiM

CD problem with Solid BSP tree

Recommended Posts

ZiM    146
I have a solid BSP tree and I'm using the dynamic plane shifting collision detection technique presented by Stan Melax. When I test a sphere against the tree (just shift all planes by r) I get collisions at some places where I shouldn't. Multiple coplanar planes on same branch seem to be the cause, as they case problems with the overlapping line segments. Do I have to merge all polygon's planes that are indentical (coplanar) into one prior to building the tree (eg. have each polygon store a pointer to a plane and the plane stores the the flag telling whether it's been used as a divider or not)? Is this 'plane merging' commonly used with BSP trees or is it just me? In case it's of any help at all, here's code I'm using for HitCheckBSP. ClipLineInside and ClipLineOutside return the part of the given line segment clipped behind and to front of the plane, respectively.
int SolidBSPTree::HitCheckBSP(Vector v1, Vector v2, BSPNode *node)
{
	int    bHit = 0;
	Plane  shiftPlane;
	Vector w0, w1;

	if(!node)
		node = m_root;

	if(node->m_isLeaf)
	{
		if(node->m_solid)
		{
			m_ptHit = v1;
			m_planeHit = node->m_pParent->m_divPlane;
			return 1;
		}
		else
			return 0;
	}

	// Shift out

	shiftPlane = node->m_divPlane;
	shiftPlane.d -= 4;

	if(ClipLineInside(shiftPlane, v1, v2, w0, w1))
	{
		bHit = HitCheckBSP(w0, w1, node->m_pBackChild);
		
		if(bHit)
			v2 = m_ptHit;
	}

	// Shift in

	shiftPlane = node->m_divPlane;
	shiftPlane.d += 4;

	if(ClipLineOutside(shiftPlane, v1, v2, w0, w1))
		bHit |= HitCheckBSP(w0, w1, node->m_pFrontChild);

	return bHit;
}

[edited by - ZiM on August 15, 2003 7:59:28 AM]

Share this post


Link to post
Share on other sites