cyclone-physics
cyclone-physics copied to clipboard
Box vs Box SAT Check
For calculating the projection of Box on to an axis, I tried this method that I found in cyclone/src/collide_fine.cpp
static inline real transformToAxis(
const CollisionBox &box,
const Vector3 &axis
)
{
return
box.halfSize.x * real_abs(axis * box.getAxis(0)) +
box.halfSize.y * real_abs(axis * box.getAxis(1)) +
box.halfSize.z * real_abs(axis * box.getAxis(2));
}
But it is not giving me correct results.
I made a small modification by taking absolute values of axis and box axis, and that gives me correct results.
Can some one please verify this? I am not sure if I am doing something wrong elsewhere in my code.
I recommend you to read the Real-Time Collision Detection Book, the collision detection of cyclone code is based on the book.
you will find the related information on the AABB, OBB intersection tests.
This may be related to this isssue.
The only problem I'm seeing (so far) with the BOX SAT is that it fails when the axes being compared are exactly parallel.
The comparison happens here:
https://github.com/idmillington/cyclone-physics/blob/master/src/collide_fine.cpp#L111-L119 and https://github.com/idmillington/cyclone-physics/blob/master/src/collide_fine.cpp#L80-L84
If the two boxes are oriented on the same plane (e.g. the ground), their X, Y and Z-axis will be parallel and the resulting cross product will be 0.
I've worked around this changing the overlap comparison from <
to <=
return (distance <= oneProject + twoProject);
This covers the case where distance
is exactly 0 due to axis
being a 0-vector. Obviously with this modification the SAT now succeeds in the rare case where the axis projections are exactly adjacent and not overlapping, but I find this to be an acceptable compromise for my own engine. YMMV.
Finally, note that the box intersection test is commented out in the contact generation code: https://github.com/idmillington/cyclone-physics/blob/master/src/collide_fine.cpp#L415
Not sure why.