Shape cast support for box movers (#180)
Co-authored-by: ζeh Matt <5415177+ZehMatt@users.noreply.github.com>
This commit is contained in:
parent
16f7f4cf4c
commit
f8c4fe83df
3 changed files with 261 additions and 0 deletions
|
|
@ -1087,6 +1087,36 @@ b3CastOutput b3ShapeCast( const b3ShapeCastPairInput* input )
|
|||
{
|
||||
target = distanceOutput.distance - linearSlop;
|
||||
}
|
||||
else if ( input->canEncroach && distanceOutput.distance > 0.0f )
|
||||
{
|
||||
// This is for box movers and can't normally be reached by capsule
|
||||
// movers or regular shape casts.
|
||||
|
||||
// Near-target start without overlap: advance by first order while
|
||||
// retaining a rest separation. Sweeps that cannot consume the free
|
||||
// gap (receding, tangential, grazing) miss.
|
||||
float retained = 0.5f * linearSlop;
|
||||
float needed = distanceOutput.distance - retained;
|
||||
float approach = -b3Dot( delta2, distanceOutput.normal );
|
||||
if ( approach <= b3MaxFloat( needed, 0.0f ) )
|
||||
{
|
||||
// Moving away, no hit.
|
||||
return output;
|
||||
}
|
||||
|
||||
float fraction = needed > 0.0f ? needed / approach : 0.0f;
|
||||
if ( fraction >= input->maxFraction )
|
||||
{
|
||||
// Still no hit because the max fraction is small.
|
||||
return output;
|
||||
}
|
||||
|
||||
output.fraction = fraction;
|
||||
output.point = b3MulAdd( distanceOutput.pointA, input->proxyA.radius, distanceOutput.normal );
|
||||
output.normal = distanceOutput.normal;
|
||||
output.hit = true;
|
||||
return output;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initial overlap
|
||||
|
|
|
|||
Loading…
Reference in a new issue