mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 23:54:35 +00:00
Bullet physics applyImpulse() fix
Bullet physics requires a local origin be passed into it's applyImpulse() rather than a world origin.
This commit is contained in:
parent
65099897f4
commit
cff2ab046a
1 changed files with 8 additions and 2 deletions
|
|
@ -335,16 +335,22 @@ void BtBody::applyImpulse( const Point3F &origin, const Point3F &force )
|
||||||
AssertFatal( mActor, "BtBody::applyImpulse - The actor is null!" );
|
AssertFatal( mActor, "BtBody::applyImpulse - The actor is null!" );
|
||||||
AssertFatal( isDynamic(), "BtBody::applyImpulse - This call is only for dynamics!" );
|
AssertFatal( isDynamic(), "BtBody::applyImpulse - This call is only for dynamics!" );
|
||||||
|
|
||||||
|
// Convert the world position to local
|
||||||
|
MatrixF trans = btCast<MatrixF>( mActor->getCenterOfMassTransform() );
|
||||||
|
trans.inverse();
|
||||||
|
Point3F localOrigin( origin );
|
||||||
|
trans.mulP( localOrigin );
|
||||||
|
|
||||||
if ( mCenterOfMass )
|
if ( mCenterOfMass )
|
||||||
{
|
{
|
||||||
Point3F relOrigin( origin );
|
Point3F relOrigin( localOrigin );
|
||||||
mCenterOfMass->mulP( relOrigin );
|
mCenterOfMass->mulP( relOrigin );
|
||||||
Point3F relForce( force );
|
Point3F relForce( force );
|
||||||
mCenterOfMass->mulV( relForce );
|
mCenterOfMass->mulV( relForce );
|
||||||
mActor->applyImpulse( btCast<btVector3>( relForce ), btCast<btVector3>( relOrigin ) );
|
mActor->applyImpulse( btCast<btVector3>( relForce ), btCast<btVector3>( relOrigin ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mActor->applyImpulse( btCast<btVector3>( force ), btCast<btVector3>( origin ) );
|
mActor->applyImpulse( btCast<btVector3>( force ), btCast<btVector3>( localOrigin ) );
|
||||||
|
|
||||||
if ( !mActor->isActive() )
|
if ( !mActor->isActive() )
|
||||||
mActor->activate();
|
mActor->activate();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue