added 'disable sleeping' option for rigidbodies. + bugfix of out of sync wheels for...
authorErwin Coumans <blender@erwincoumans.com>
Wed, 22 Feb 2006 06:58:05 +0000 (06:58 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Wed, 22 Feb 2006 06:58:05 +0000 (06:58 +0000)
extern/bullet/Bullet/CollisionDispatch/CollisionDispatcher.cpp
extern/bullet/Bullet/NarrowPhaseCollision/CollisionObject.h
extern/bullet/BulletDynamics/Vehicle/RaycastVehicle.cpp
source/blender/src/buttons_logic.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

index a12051455fa8ac9223fab1361f37a31b2b56a3b1..cd2da11652297ffcf82c1b8abfa84ea1e8d86667 100644 (file)
@@ -119,6 +119,11 @@ void CollisionDispatcher::BuildAndProcessIslands(int numBodies, IslandCallback*
                                {
                                        allSleeping = false;
                                }
+                               if ((((CollisionObject*)manifold->GetBody0()) && ((CollisionObject*)manifold->GetBody0())->GetActivationState()== DISABLE_DEACTIVATION) ||
+                                       (((CollisionObject*)manifold->GetBody1()) && ((CollisionObject*)manifold->GetBody1())->GetActivationState() == DISABLE_DEACTIVATION))
+                               {
+                                       allSleeping = false;
+                               }
 
                                islandmanifold.push_back(manifold);
                        }
index c83d73938eef75ff63baa55238315574b9bbf0d9..4df10832dea67164b5cfce9bee30f110adae586d 100644 (file)
@@ -7,6 +7,7 @@
 #define ACTIVE_TAG 1
 #define ISLAND_SLEEPING 2
 #define WANTS_DEACTIVATION 3
+#define DISABLE_DEACTIVATION 4
 
 struct BroadphaseProxy;
 class  CollisionShape;
index 096ccfd85d2261ffb9de82e9c7f7b09a9dd589a3..a4bd06128335ad21aa747fbda6e04925acba1dc2 100755 (executable)
@@ -92,7 +92,9 @@ const SimdTransform&  RaycastVehicle::GetWheelTransformWS( int wheelIndex ) const
 
 void   RaycastVehicle::UpdateWheelTransform( int wheelIndex )
 {
+       
        WheelInfo& wheel = m_wheelInfo[ wheelIndex ];
+       UpdateWheelTransformsWS(wheel);
        SimdVector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
        const SimdVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
        SimdVector3 fwd = up.cross(right);
index d4f4d182b8fc78cc8d139f051c31d79e9a3fb292..9840f254020c69488ce56492165787d3ff976c6a 100644 (file)
@@ -2378,20 +2378,24 @@ void buttons_enji(uiBlock *block, Object *ob)
 void buttons_ketsji(uiBlock *block, Object *ob)
 {
        uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
-                         10,205,75,19, &ob->gameflag, 0, 0, 0, 0,
+                         10,205,55,19, &ob->gameflag, 0, 0, 0, 0,
                          "Objects that are evaluated by the engine ");
        if(ob->gameflag & OB_ACTOR) {   
-               uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 85,205,65,19, 
+               uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 65,205,55,19, 
                                  &ob->gameflag, 0, 0, 0, 0, 
                                  "Objects that don't restitute collisions (like a ghost)");
-               uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 150,205,65,19, 
+               uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 120,205,70,19, 
                                  &ob->gameflag, 0, 0, 0, 0, 
                                  "Motion defined by laws of physics");
        
                if(ob->gameflag & OB_DYNAMIC) {
-                       uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 215,205,135,19, 
+                       uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 180,205,70,19, 
                                          &ob->gameflag, 0, 0, 0, 0, 
                                          "Enable rolling physics");
+                       uiDefButBitI(block, TOG, OB_COLLISION_RESPONSE, B_REDR, "No sleeping", 250,205,100,19, 
+                                         &ob->gameflag, 0, 0, 0, 0, 
+                                         "Disable auto (de)activation");
+
                        uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh", 10,185,50,19, 
                                          &ob->gameflag, 0, 0, 0, 0, 
                                          "Use Fh settings in Materials");
index f07cb80d1bfe99f1a2e498a79965956aa21a0b8a..b21eb74333475b9fb151b32a4ee9dc096f8d1085 100644 (file)
@@ -1231,10 +1231,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
                objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
                objprop.m_ghost = (blenderobject->gameflag & OB_GHOST) != 0;
+               objprop.m_disableSleeping = (blenderobject->gameflag & OB_COLLISION_RESPONSE) != 0;//abuse the OB_COLLISION_RESPONSE flag
        } else {
                objprop.m_dyna = false;
                objprop.m_angular_rigidbody = false;
                objprop.m_ghost = false;
+               objprop.m_disableSleeping = false;
        }
        //mmm, for now, taks this for the size of the dynamicobject
        // Blender uses inertia for radius of dynamic object
index b1922e247d149d6c19443e7c76c37559ee2c8348..a976a6b13b1b840f3a0d9a367c055e6a9a9b7ce2 100644 (file)
@@ -85,6 +85,7 @@ struct KX_ObjectProperties
        bool    m_isactor;
        bool    m_concave;
        bool    m_isdeformable;
+       bool    m_disableSleeping;
        KX_BoundBoxClass        m_boundclass;
        union {
                KX_BoxBounds    box;
index 73b49150414d4e77633291f2e6909d0792e6971e..8f3a6a2470c870f6cc34eb9ae9743641f38a19aa 100644 (file)
@@ -1033,6 +1033,10 @@ void     KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
        gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
        physicscontroller->setNewClientInfo(gameobj->getClientInfo());          
+
+       if (objprop->m_disableSleeping)
+               physicscontroller->GetRigidBody()->SetActivationState(DISABLE_DEACTIVATION);
+       
        bool isActor = objprop->m_isactor;
        gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC);
        // store materialname in auxinfo, needed for touchsensors
index 2f8f4a4e2ab67272ec6939ec5c8ab57dd6147fc2..fdb30faa5cf7ab7bd16097511b9635f987934603 100644 (file)
@@ -374,9 +374,8 @@ void                CcdPhysicsController::setNewClientInfo(void* clientinfo)
 
 void   CcdPhysicsController::UpdateDeactivation(float timeStep)
 {
-       if ( (m_body->GetActivationState() == 2))
+       if ( (m_body->GetActivationState() == ISLAND_SLEEPING) || (m_body->GetActivationState() == DISABLE_DEACTIVATION))
                return;
-       
 
        if ((m_body->getLinearVelocity().length2() < gLinearSleepingTreshold*gLinearSleepingTreshold) &&
                (m_body->getAngularVelocity().length2() < gAngularSleepingTreshold*gAngularSleepingTreshold))
@@ -393,6 +392,9 @@ void        CcdPhysicsController::UpdateDeactivation(float timeStep)
 bool CcdPhysicsController::wantsSleeping()
 {
 
+       if (m_body->GetActivationState() == DISABLE_DEACTIVATION)
+               return false;
+
        //disable deactivation
        if (gDisableDeactivation || (gDeactivationTime == 0.f))
                return false;
index b39591fc62790dbd582d0ab23e5cf9494568ebbd..7bc2eb73cbcc621073ccbbc1073cf8fe62a29acd 100644 (file)
@@ -115,6 +115,7 @@ public:
                {
                        WheelInfo& info = m_vehicle->GetWheelInfo(i);
                        PHY_IMotionState* motionState = (PHY_IMotionState*)info.m_clientInfo ;
+                       m_vehicle->UpdateWheelTransform(i);
                        SimdTransform trans = m_vehicle->GetWheelTransformWS(i);
                        SimdQuaternion orn = trans.getRotation();
                        const SimdVector3& pos = trans.getOrigin();
@@ -668,6 +669,10 @@ bool       CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                                                        {
                                                                break;
                                                        }
+                                               case DISABLE_DEACTIVATION:
+                                                       {
+                                                               color.setValue(1,0,1);
+                                                       };
                                                        
                                                };
 
@@ -751,7 +756,8 @@ bool        CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                                                body->SetActivationState( WANTS_DEACTIVATION );
                                } else
                                {
-                                       body->SetActivationState( ACTIVE_TAG );
+                                       if (body->GetActivationState() != DISABLE_DEACTIVATION)
+                                               body->SetActivationState( ACTIVE_TAG );
                                }
 
                                if (useIslands)
@@ -785,12 +791,7 @@ bool       CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                for (int i=0;i<numVehicles;i++)
                {
                        WrapperVehicle* wrapperVehicle = m_wrapperVehicles[i];
-                       
-                       for (int j=0;j<wrapperVehicle->GetVehicle()->GetNumWheels();j++)
-                       {
-                               wrapperVehicle->GetVehicle()->UpdateWheelTransform(j);
-                       }
-                       
+               
                        wrapperVehicle->SyncWheels();
                }
 #endif //NEW_BULLET_VEHICLE_SUPPORT