Skip to main content
gamedev.net
🔒 Locked

brush collision problem

Started by Kid A Aug 6, 2002 at 12:05 AM 0 replies 350+ views
Original Post
Kid A
Kid A
Hi I've nearly got brush based collisions going, but have hit one last problem. I sometimes get ledges where two brushes meet, and depending on the direction of travel they give a little invisible wall effect. Other than this it is going nicely. For each brush I expand each plane by an offset amount (usually 16.0f) then check the movement line for collision with the expanded plane. If there is a collision i get the crossing point and see if it is inside the brush (behind all other expanded planes). If it is i slide along this plane and recurse, allowing for a bit of epsilon. I devised this myself so it's probably way off:
  
const Vec3 MapVolumes::collide(const Vec3 & startPos_, const Vec3 & endPos_)
{
    unsigned short i;
    unsigned char j, k;

    const Line3d line(startPos_, endPos_);
    if (line.getLength() < EPSILON) return startPos_;

    Vec3 intersection;
    bool onFront;

    for (i = 0; i < m_volumeCount; ++i)
    {
        for (j = 0; j < m_volumes[i].planeCount(); ++j)
        {
            m_volumes[i].plane(j).d() -= offset;
            if (m_volumes[i].plane(j).intersect(line, intersection))
            {
                for (k = 0; k < m_volumes[i].planeCount(); ++k)
                {
                    if (k == j) continue;
                    m_volumes[i].plane(k).d() -= offset;
                    onFront = (_volumes[i].plane(k).classify(intersection) == Pane3d::CP_FRONT);
                    m_volumes[i].plane(k).d() += offset;
                    if (onFront) break;
                }

                if (k == m_volumes[i].planeCount())
                {
                    const float factor = 5.0f;
                    m_volumes[i].plane(j).d() -= EPSILON * factor;
                    Vec3 v = m_volumes[i].plane(j).project(endPos_);
                    m_volumes[i].plane(j).d() += offset + (EPSILON * factor);
                    if ((v - endPos_).magnitude() < EPSILON)
                        continue;
                    return collide(startPos_, v);
                }
            }
            m_volumes[i].plane(j).d() += offset;
        }
    }
    return endPos_;
}
  
Any help would be appreciated, thanks. Also how do you add AABB into this system? Richard [edited by - Kid A on August 6, 2002 7:03:18 AM]
Kid A
Kid A
Help?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.