Possible bug in GImpact

Post Reply
Whooom
Posts: 2
Joined: Wed May 27, 2015 4:20 pm

Possible bug in GImpact

Post by Whooom »

I found that when working with concave shapes using G-Impact I would, at times, get bogus collisions. When I traced these down, what I found was that the function btPrimitiveTriangle::overlap_test_conservative was giving me nonsense results in the case where one triangle was "below" the plane of the other triangle. What I see is that the distance check was testing for all positive (all the same sign) results and declaring a miss. However, in the concave case this isn't really good enough I think.

So, I changed the function from:

Code: Select all

bool btPrimitiveTriangle::overlap_test_conservative(const btPrimitiveTriangle& other)
{
    btScalar total_margin = m_margin + other.m_margin;
    // classify points on other triangle
    btScalar dis0 = bt_distance_point_plane(m_plane,other.m_vertices[0]) - total_margin;

    btScalar dis1 = bt_distance_point_plane(m_plane,other.m_vertices[1]) - total_margin;

    btScalar dis2 = bt_distance_point_plane(m_plane,other.m_vertices[2]) - total_margin;

    if (dis0>0.0f&&dis1>0.0f&&dis2>0.0f) return false;

    // classify points on this triangle
    dis0 = bt_distance_point_plane(other.m_plane,m_vertices[0]) - total_margin;

    dis1 = bt_distance_point_plane(other.m_plane,m_vertices[1]) - total_margin;

    dis2 = bt_distance_point_plane(other.m_plane,m_vertices[2]) - total_margin;

    if (dis0>0.0f&&dis1>0.0f&&dis2>0.0f) return false;

    return true;
}
to:

Code: Select all

bool btPrimitiveTriangle::overlap_test_conservative(const btPrimitiveTriangle& other)
{
    btScalar total_margin = m_margin + other.m_margin;
    // classify points on other triangle
    btScalar dis0 = bt_distance_point_plane(m_plane,other.m_vertices[0]);

    btScalar dis1 = bt_distance_point_plane(m_plane,other.m_vertices[1]);

    btScalar dis2 = bt_distance_point_plane(m_plane,other.m_vertices[2]);

    if (dis0>total_margin&&dis1>total_margin&&dis2>total_margin) return false;
    if (dis0<-total_margin&&dis1<-total_margin&&dis2<-total_margin) return false;

    // classify points on this triangle
    dis0 = bt_distance_point_plane(other.m_plane,m_vertices[0]);

    dis1 = bt_distance_point_plane(other.m_plane,m_vertices[1]);

    dis2 = bt_distance_point_plane(other.m_plane,m_vertices[2]);

    if (dis0>total_margin&&dis1>total_margin&&dis2>total_margin) return false;
    if (dis0<-total_margin&&dis1<-total_margin&&dis2<-total_margin) return false;

    return true;
}
However, I'm not totally certain that this is correct, though I seem to get much better results after this change. Am I missing something? Or is this a better test?

Thanks!
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Possible bug in GImpact

Post by benelot »

Give this a go in a pull request or at least an issue on the github repository, there you usually get better answers related to implementation issues of bullet.
Post Reply