Revision: 19233
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19233
Author:   erwin
Date:     2009-03-09 08:12:16 +0100 (Mon, 09 Mar 2009)

Log Message:
-----------
Add support to lock individual axis during rigid body simulation, for 
translation and rotation. This makes it easier to do 1D or 2D physics (tetris, 
blockout)
todo: create some example/demo.blend.

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp

Modified: trunk/blender/source/blender/makesdna/DNA_object_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_types.h    2009-03-09 
07:00:40 UTC (rev 19232)
+++ trunk/blender/source/blender/makesdna/DNA_object_types.h    2009-03-09 
07:12:16 UTC (rev 19233)
@@ -440,6 +440,12 @@
 
 /* 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)
 

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c    2009-03-09 07:00:40 UTC 
(rev 19232)
+++ trunk/blender/source/blender/src/buttons_logic.c    2009-03-09 07:12:16 UTC 
(rev 19233)
@@ -3058,12 +3058,14 @@
 
        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 @@
 
                
                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;

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-03-09 07:00:40 UTC (rev 19232)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-03-09 07:12:16 UTC (rev 19233)
@@ -1315,6 +1315,12 @@
                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;

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h    
2009-03-09 07:00:40 UTC (rev 19232)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h    
2009-03-09 07:12:16 UTC (rev 19233)
@@ -127,6 +127,14 @@
 
        /////////////////////////
        
+       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 {

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 
2009-03-09 07:00:40 UTC (rev 19232)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 
2009-03-09 07:12:16 UTC (rev 19233)
@@ -1101,8 +1101,24 @@
        {
                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;


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to