As a response to issue [#28483] "Enable/Disable Rigid Body actuator do nothing" repor...
authorMitchell Stokes <mogurijin@gmail.com>
Mon, 9 Jul 2012 04:57:21 +0000 (04:57 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Mon, 9 Jul 2012 04:57:21 +0000 (04:57 +0000)
doc/python_api/rst/bge.types.rst
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h

index bd6ee3614d3f83970f7cb7cd46e65132c2428f81..31ae45b9bf0340bcad23ec5e0798d301052eb809 100644 (file)
@@ -1335,18 +1335,10 @@ Game Types (bge.types)
 
       Rigid body physics allows the object to roll on collisions.
 
-      .. note::
-         
-         This is not working with bullet physics yet.
-
    .. method:: disableRigidBody()
 
       Disables rigid body physics for this object.
 
-      .. note::
-
-         This is not working with bullet physics yet. The angular is removed but rigid body physics can still rotate it later.
-
    .. method:: setParent(parent, compound=True, ghost=True)
 
       Sets this object's parent.
index abc2460a5ba564f1196f031b94a54b2b95fdd21f..b974886f60a8293a9bb051ebce2f3ccb3eda2528 100644 (file)
@@ -232,6 +232,7 @@ MT_Vector3  KX_BulletPhysicsController::getReactionForce()
 }
 void   KX_BulletPhysicsController::setRigidBody(bool rigid)
 {
+       CcdPhysicsController::setRigidBody(rigid);
 }
 
 /* This function dynamically adds the collision shape of another controller to
index 227ca39281f6672c09f174a4065900ab83521aa1..f1038c044998d8dd420e4aaa26d2cfff9e41b7b7 100644 (file)
@@ -118,6 +118,12 @@ void       KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
        ci.m_MotionState = motionstate;
        ci.m_gravity = btVector3(0,0,0);
+       ci.m_linearFactor = btVector3(objprop->m_lockXaxis? 0 : 1,
+                                                                       objprop->m_lockYaxis? 0 : 1,
+                                                                       objprop->m_lockZaxis? 0 : 1);
+       ci.m_angularFactor = btVector3(objprop->m_lockXRotaxis? 0 : 1,
+                                                                       objprop->m_lockYRotaxis? 0 : 1,
+                                                                       objprop->m_lockZRotaxis? 0 : 1);
        ci.m_localInertiaTensor =btVector3(0,0,0);
        ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
        ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min;
@@ -441,16 +447,8 @@ void       KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                {
                        if (objprop->m_angular_rigidbody)
                        {
-                               btVector3 linearFactor(
-                                       objprop->m_lockXaxis? 0 : 1,
-                                       objprop->m_lockYaxis? 0 : 1,
-                                       objprop->m_lockZaxis? 0 : 1);
-                               btVector3 angularFactor(
-                                       objprop->m_lockXRotaxis? 0 : 1,
-                                       objprop->m_lockYRotaxis? 0 : 1,
-                                       objprop->m_lockZRotaxis? 0 : 1);
-                               rbody->setLinearFactor(linearFactor);
-                               rbody->setAngularFactor(angularFactor);
+                               rbody->setLinearFactor(ci.m_linearFactor);
+                               rbody->setAngularFactor(ci.m_angularFactor);
                        }
 
                        if (rbody && objprop->m_disableSleeping)
index c7ba17e7f971e0f9cd8470c7313dcc0f0aeedcdb..e63724fffc6f8c60cc94009caad2b169ab5ceae6 100644 (file)
@@ -1294,17 +1294,16 @@ void            CcdPhysicsController::getReactionForce(float& forceX,float& forceY,float&
                // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
 void           CcdPhysicsController::setRigidBody(bool rigid)
 {
-       if (!rigid)
+       btRigidBody* body = GetRigidBody();
+       if (body)
        {
-               btRigidBody* body = GetRigidBody();
-               if (body)
-               {
-                       //fake it for now
-                       btVector3 inertia = body->getInvInertiaDiagLocal();
-                       inertia[1] = 0.f;
-                       body->setInvInertiaDiagLocal(inertia);
-                       body->updateInertiaTensor();
+               m_cci.m_bRigid = rigid;
+               if (!rigid) {
+                       body->setAngularFactor(0.f);
+                       body->setAngularVelocity(btVector3(0.f, 0.f, 0.f));
                }
+               else
+                       body->setAngularFactor(m_cci.m_angularFactor);
        }
 }
 
index 869211ffd311457ee48542022cae90b02f321aaf..94dc796df23b7455dbd85cdcc85ff1fe6776669d 100644 (file)
@@ -229,6 +229,8 @@ struct CcdConstructionInfo
            :m_localInertiaTensor(1.f, 1.f, 1.f),
                m_gravity(0,0,0),
                m_scaling(1.f,1.f,1.f),
+               m_linearFactor(0.f, 0.f, 0.f),
+               m_angularFactor(0.f, 0.f, 0.f),
                m_mass(0.f),
                m_clamp_vel_min(-1.f),
                m_clamp_vel_max(-1.f),
@@ -292,6 +294,8 @@ struct CcdConstructionInfo
        btVector3       m_localInertiaTensor;
        btVector3       m_gravity;
        btVector3       m_scaling;
+       btVector3       m_linearFactor;
+       btVector3       m_angularFactor;
        btScalar        m_mass;
        btScalar        m_clamp_vel_min;  
        btScalar        m_clamp_vel_max;