Add support to lock individual axis during rigid body simulation, for translation...
authorErwin Coumans <blender@erwincoumans.com>
Mon, 9 Mar 2009 07:12:16 +0000 (07:12 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Mon, 9 Mar 2009 07:12:16 +0000 (07:12 +0000)
todo: create some example/demo.blend.

source/blender/makesdna/DNA_object_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp

index b885bbf084e626c20453de45c1f7b32942e194a2..b17896aec708deea6ce55d3c3d32c01387b4f2ac 100644 (file)
@@ -440,6 +440,12 @@ extern Object workob;
 
 /* ob->gameflag2 */
 #define OB_NEVER_DO_ACTIVITY_CULLING   1
+#define OB_LOCK_RIGID_BODY_X_AXIS      4
+#define OB_LOCK_RIGID_BODY_Y_AXIS      8
+#define OB_LOCK_RIGID_BODY_Z_AXIS      16
+#define OB_LOCK_RIGID_BODY_X_ROT_AXIS  32
+#define OB_LOCK_RIGID_BODY_Y_ROT_AXIS  64
+#define OB_LOCK_RIGID_BODY_Z_ROT_AXIS  128
 
 #define OB_LIFE                        (OB_PROP|OB_DYNAMIC|OB_ACTOR|OB_MAINACTOR|OB_CHILD)
 
index 775175ba3328a2e775974f5d38ad303a8d18ab5c..10718c74a4be08607ca5f53a7d95cdc308bd0030 100644 (file)
@@ -3058,12 +3058,14 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
 
        block= uiNewBlock(&curarea->uiblocks, "advanced_bullet_options", UI_EMBOSS, UI_HELV, curarea->win);
        /* use this for a fake extra empy space around the buttons */
-       uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
+       
 
        if (ob->gameflag & OB_SOFT_BODY) {
+               uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
 
                if (ob->bsoft)
                {
+                       
 
                        uiBlockBeginAlign(block);
                        uiDefButBitI(block, TOG, OB_BSB_COL_CL_RS, 0, "Cluster Collision RS", 
@@ -3106,16 +3108,78 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
 
                
                xco = 0;
+               
 
                if (ob->gameflag & OB_DYNAMIC) {
+
+                       yco = 100;
+                       uiDefBut(block, LABEL, 0, "", -10, -10, 380, 120, NULL, 0, 0, 0, 0, "");
+                       uiBlockBeginAlign(block);
                        if (ob->margin < 0.001f)
                                ob->margin = 0.06f;
                        uiDefButF(block, NUM, 0, "Margin", 
-                                       xco, yco, 170, 19, &ob->margin, 0.001, 1.0, 1, 0, 
+                                       xco, yco, 180, 19, &ob->margin, 0.001, 1.0, 1, 0, 
                                        "Collision margin");
+                       yco -= 20;
+
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_X_AXIS, 0, "Lock X Axis", 
+                               xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of linear motion along the X axis");
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_X_ROT_AXIS, 0, "Lock X Rot Xxis", 
+                               xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of angular motion along the X axis");
+                       yco -= 20;
+                       xco=0;
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Y_AXIS, 0, "Lock Y Axis", 
+                               xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of linear motion along the Y axis");
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Y_ROT_AXIS, 0, "Lock Y Rot Axis", 
+                               xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of angular motion along the Y axis");
+
+                       yco -= 20;
+                       xco=0;
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Z_AXIS, 0, "Lock Z Axis", 
+                               xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of linear motion along the Z axis");
+                       uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Z_ROT_AXIS, 0, "Lock Z Rot Axis", 
+                               xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0, 
+                               "Disable simulation of angular motion along the Z axis");
+
+                       /*
+                       uiDefButBitI(block, TOG, OB_BSB_COL_CL_RS, 0, "Cluster Collision RS", 
+                               xco, yco, 180, 19, &ob->bsoft->collisionflags, 0, 0, 0, 0, 
+                               "Enable cluster collision between soft and rigid body");
+                       uiDefButBitI(block, TOG, OB_BSB_COL_CL_SS, 0, "Cluster Collision SS", 
+                               xco+=180, yco, 180, 19, &ob->bsoft->collisionflags, 0, 0, 0, 0, 
+                               "Enable cluster collision between soft and soft body");
+                       yco -= 20;
+                       xco = 0;
+                       uiDefButI(block, NUM, 0, "Cluster Iter.",               
+                               xco, yco, 180, 19, &ob->bsoft->numclusteriterations, 1.0, 128., 
+                               0, 0, "Specify the number of cluster iterations");
+                       uiDefButI(block, NUM, 0, "Position Iter.",              
+                               xco+=180, yco, 180, 19, &ob->bsoft->piterations, 0, 10, 
+                               0, 0, "Position solver iterations");
+                       #define OB_LOCK_RIGID_BODY_X_AXIS       4
+                       #define OB_LOCK_RIGID_BODY_Y_AXIS       8
+                       #define OB_LOCK_RIGID_BODY_Z_AXIS       16
+                       #define OB_LOCK_RIGID_BODY_X_ROT_AXIS   32
+                       #define OB_LOCK_RIGID_BODY_Y_ROT_AXIS   64
+                       #define OB_LOCK_RIGID_BODY_Z_ROT_AXIS   128
+                       */
+
+                       uiBlockEndAlign(block);
+
+
+                       
+
+
                } else {
+                       
+                       uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
                        uiDefButF(block, NUM, 0, "Margin", 
-                                       xco, yco, 170, 19, &ob->margin, 0.0, 1.0, 1, 0, 
+                                       xco, yco, 180, 19, &ob->margin, 0.0, 1.0, 1, 0, 
                                        "Collision margin");
                }
                yco -= 20;
index 3a0302562e611661f61cc77b451524ef8e31e536..d74243b0eb09cbb9cf9a08dfefe36421463d1c0e 100644 (file)
@@ -1315,6 +1315,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                CreateMaterialFromBlenderObject(blenderobject, kxscene);
                                        
        KX_ObjectProperties objprop;
+       objprop.m_lockXaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_AXIS) !=0;
+       objprop.m_lockYaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_AXIS) !=0;
+       objprop.m_lockZaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_AXIS) !=0;
+       objprop.m_lockXRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_ROT_AXIS) !=0;
+       objprop.m_lockYRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) !=0;
+       objprop.m_lockZRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0;
 
        objprop.m_isCompoundChild = isCompoundChild;
        objprop.m_hasCompoundChildren = (blenderobject->gameflag & OB_CHILD) != 0;
index edacf38ab4316e52cf75f0d2a46adffb47398e78..3534500e61952653b442a09e7f96b462311e4778 100644 (file)
@@ -127,6 +127,14 @@ struct KX_ObjectProperties
 
        /////////////////////////
        
+       bool    m_lockXaxis;
+       bool    m_lockYaxis;
+       bool    m_lockZaxis;
+       bool    m_lockXRotaxis;
+       bool    m_lockYRotaxis;
+       bool    m_lockZRotaxis;
+
+       /////////////////////////
        double  m_margin;
        KX_BoundBoxClass        m_boundclass;
        union {
index 46e46b014b582342e93b5bf2dd6a67563d979249..602486e0017e774593d2e69715c53df76186e13f 100644 (file)
@@ -1101,8 +1101,24 @@ void     KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        {
                btRigidBody* rbody = physicscontroller->GetRigidBody();
 
-               if (rbody && objprop->m_disableSleeping)
-                       rbody->setActivationState(DISABLE_DEACTIVATION);
+               if (rbody)
+               {
+                       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);
+
+                       if (rbody && objprop->m_disableSleeping)
+                       {
+                               rbody->setActivationState(DISABLE_DEACTIVATION);
+                       }
+               }
        }
 
        CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0;