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


CD problem with Solid BSP tree

Recommended Posts

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;

		node = m_root;

			m_ptHit = v1;
			m_planeHit = node->m_pParent->m_divPlane;
			return 1;
			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);
			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