diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-01-15 01:33:39 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-01-15 01:33:39 +0300 |
commit | 509ca83ef1d10fab4903981714cfab3719280e04 (patch) | |
tree | 0b065c5d22bb511a148db43ba260e98195f5c155 /source/gameengine/Ketsji/KX_BulletPhysicsController.cpp | |
parent | 00c12e09066c551e3ae8ee6da3cb85fb3bcf90f8 (diff) |
BGE patch 18065: gameobj mass writeable + setmass actuator. This patch allows to change the mass of a dynamic or rigid body object during the game. Two methods are available: in a Python script by setting the mass attribute of the game object; by logic brick with the Edit Object->Dynamics->Set Mass actuator. The mass can only be set on dynamic objects and must be a positive floating point value.
Diffstat (limited to 'source/gameengine/Ketsji/KX_BulletPhysicsController.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_BulletPhysicsController.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index a67f4a54b3f..534c48661b7 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -303,6 +303,25 @@ void KX_BulletPhysicsController::RemoveCompoundChild(KX_IPhysicsController* c GetPhysicsEnvironment()->enableCcdPhysicsController(childCtrl); } +void KX_BulletPhysicsController::SetMass(MT_Scalar newmass) +{ + btRigidBody *body = GetRigidBody(); + if (body && body->getActivationState() != DISABLE_SIMULATION && + newmass>MT_EPSILON && GetMass()>MT_EPSILON) + { + btVector3 grav = body->getGravity(); + btVector3 accel = grav / GetMass(); + + btBroadphaseProxy* handle = body->getBroadphaseHandle(); + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + newmass, + body->getCollisionFlags(), + handle->m_collisionFilterGroup, + handle->m_collisionFilterMask); + body->setGravity(accel); + } +} + void KX_BulletPhysicsController::SuspendDynamics(bool ghost) { btRigidBody *body = GetRigidBody(); @@ -333,7 +352,7 @@ void KX_BulletPhysicsController::RestoreDynamics() m_savedCollisionFlags, m_savedCollisionFilterGroup, m_savedCollisionFilterMask); - GetRigidBody()->forceActivationState(m_savedActivationState); + body->forceActivationState(m_savedActivationState); } } |