#### Archived

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

# Quake 2 BSP Collision detection

This topic is 6030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve been working on an algorithm to find the distance to a wall in any direction, mostly to check how close to the floor a person is.

// DO NOT USE!!! BUGGY

/////////////////////////////////////////////////////////////////////////////////////

float cBspTree::cNode::DistanceToWall (cVector point1, cVector point2)
/////////////////////////////////////////////////////////////////////////////////////

{
ePointLoc	p1, p2;
cVector		split;
float		distance = 0;

// Test the positioning of each point

p1 = m_plane.TestPoint (point1);
p2 = m_plane.TestPoint (point2);

// Test if both points are in front or coplanar

if (((p1 == PT_FRONT) || (p1 == PT_COPLANAR)) &&
((p2 == PT_FRONT) || (p2 == PT_COPLANAR)))
{
// If the front node is a leaf, return the distance

if (m_frontNode == NULL)
{
// Is the leaf solid?

if (m_frontLeaf->GetCluster () == BSP_OUTOFCLUSTER)
return 0;
else
return ((point1 - point2).GetLength ());

}
// Front node is a node

return m_frontNode->DistanceToWall (point1, point2);
}

// Test if both points are in back

if (((p1 == PT_BACK) || (p1 == PT_COPLANAR)) &&
((p2 == PT_BACK) || (p2 == PT_COPLANAR)))
{
// If the back node is a leaf, return the distance

if (m_backNode == NULL)
{
// Is the leaf solid?

if (m_backLeaf->GetCluster () == BSP_OUTOFCLUSTER)
return 0;
else
return ((point1 - point2).GetLength ());

}
// Back node is a node

return m_backNode->DistanceToWall (point1, point2);
}

// Points split across the plane

split = m_plane.GetIntersection (point1, point2);

// First point is in front

if (((p1 == PT_FRONT) || (p1 == PT_COPLANAR)) &&
((p2 == PT_BACK)  || (p2 == PT_COPLANAR)))
{
// If the front node is a leaf, get the distance

if (m_frontNode == NULL)
{
// Is the leaf solid?

if (m_frontLeaf->GetCluster () == BSP_OUTOFCLUSTER)
return 0;
else
distance += (point1 - split).GetLength ();
}
else
distance += m_frontNode->DistanceToWall (point1, split);

if (distance == 0.f)
return 0.f;

// If the back node is a leaf, get the distance

if (m_backNode == NULL)
{
// Is the leaf not solid?

if (m_backLeaf->GetCluster () != BSP_OUTOFCLUSTER)
distance += (point2 - split).GetLength();
}
else
distance += m_backNode->DistanceToWall (split, point2);

if (distance == 0.f)
return 0.f;
}

// First point is in back

if (((p1 == PT_BACK)   || (p1 == PT_COPLANAR)) &&
((p2 == PT_FRONT)  || (p2 == PT_COPLANAR)))
{
// If the back node is a leaf, get the distance

if (m_backNode == NULL)
{
// Is the leaf solid?

if (m_backLeaf->GetCluster () == BSP_OUTOFCLUSTER)
return 0;
else
distance += (point1 - split).GetLength ();
}
else
distance += m_backNode->DistanceToWall (point1, split);

if (distance == 0.f)
return 0.f;

// If the front node is a leaf, get the distance

if (m_frontNode == NULL)
{
// Is the leaf not solid?

if (m_frontLeaf->GetCluster () != BSP_OUTOFCLUSTER)
distance += (point2 - split).GetLength();
}
else
distance += m_frontNode->DistanceToWall (split, point2);

if (distance == 0.f)
return 0.f;
}

// Return the distance

return distance;
}

On solid ground, it works great, but on overhangs, it seems to be getting the distance to the bottom most floor. I''m sure it has something to do with the recursion, but I can''t seem to find out what it is. --------------------------------------------------------------------------------------- Before I couldn''t spell engineer, now I are one.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009491
• ### Who's Online (See full list)

There are no registered users currently online

×