more fixes of potential bugs in Physics collision handling

This commit is contained in:
Dander7BD 2014-02-04 16:10:18 +01:00
parent 9622d37d3f
commit 1952ff9aba
1 changed files with 24 additions and 8 deletions

View File

@ -26,10 +26,13 @@ namespace
ICustomBody::State protoState; proto->GetState( protoState ); ICustomBody::State protoState; proto->GetState( protoState );
ICustomBody::State deuterState; deuter->GetState( deuterState ); ICustomBody::State deuterState; deuter->GetState( deuterState );
// calc from perspective of deuter // calc from perspective of deuter.
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal ); Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed
if( normal.Dot(normal) > 0.0f )
if( normal.Dot(normal) == 0.0f ) {
deuter->GetNormalAt( worldPointOfContact, normal );
}
else
{ // special case: deuter is completly contained within proto or they have overlapping centers. { // special case: deuter is completly contained within proto or they have overlapping centers.
normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f ); normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f );
@ -87,9 +90,22 @@ namespace
// calc from perspective of proto // calc from perspective of proto
proto->GetNormalAt( worldPointOfContact, normal );
protoG_Magnitude = protoG.Dot( normal ), normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f );
deuterG_Magnitude = deuterG.Dot( normal ); if( normal.Dot(normal) > 0.0f )
{
proto->GetNormalAt( worldPointOfContact, normal );
protoG_Magnitude = protoG.Dot( normal );
deuterG_Magnitude = deuterG.Dot( normal );
}
else
{ // special case: proto is completly contained within deuter.
// borrowing the negated normal of deuter.
deuter->GetNormalAt( worldPointOfContact, normal );
normal = -normal;
protoG_Magnitude = -protoG_Magnitude;
deuterG_Magnitude = -deuterG_Magnitude;
}
// bounce // bounce
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),