From 509ca83ef1d10fab4903981714cfab3719280e04 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 14 Jan 2009 22:33:39 +0000 Subject: 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. --- .../Ketsji/KX_BulletPhysicsController.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_BulletPhysicsController.cpp') 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); } } -- cgit v1.2.3