bugfixes for generic (experimental) Bullet rigidbody constraint: use cone-twist inste...
authorErwin Coumans <blender@erwincoumans.com>
Mon, 16 Jul 2007 05:56:51 +0000 (05:56 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Mon, 16 Jul 2007 05:56:51 +0000 (05:56 +0000)
Note: Visual Studio projectfiles and other buildsystems need to add extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp to the project!

source/blender/makesdna/DNA_constraint_types.h
source/blender/src/buttons_object.c
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
source/gameengine/Physics/common/PHY_DynamicTypes.h

index a1a136b8836516b0df285b46e888fad5de4a5509..ce2b558e714241d7d19e2708e9cac9dd66bc9a5b 100644 (file)
@@ -405,6 +405,7 @@ typedef struct bSizeLimitConstraint {
 /* important: these defines need to match up with PHY_DynamicTypes headerfile */
 #define CONSTRAINT_RB_BALL             1
 #define CONSTRAINT_RB_HINGE            2
+#define CONSTRAINT_RB_CONETWIST 4
 #define CONSTRAINT_RB_VEHICLE  11
 #define CONSTRAINT_RB_GENERIC6DOF 12
 
index 6c1059fc8a19deae59e753ae738679a7655b34f6..0f7aee08afc4a47ac2fa1da811a3ba3bcf58b14c 100644 (file)
@@ -1353,11 +1353,13 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                int offsetY = 150;
                                int textButWidth = ((width/2)-togButWidth);
 
-                               uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Generic (experimental)%x12",//|Extra Force%x6",
+                               uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Cone Twist%x4|Generic (experimental)%x12",//|Extra Force%x6",
                                                                                                *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
                 height = 140;
                                if (data->type==CONSTRAINT_RB_GENERIC6DOF)
                                        height = 270;
+                               if (data->type==CONSTRAINT_RB_CONETWIST)
+                                       height = 200;
                                
                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
 
@@ -1400,7 +1402,8 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                        uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
                                        uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit"); 
                                        offsetY += 20;
-                       
+                               }
+                               if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
                                        /* Draw Pairs of LimitToggle+LimitValue */
                                        uiBlockBeginAlign(block); 
                                        uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
index bc69fe85effbc6d5572814ac659d38a81ca28c58..99c3e5f77c7bb44d83776c8d2b34c6b2506573cf 100644 (file)
@@ -1135,6 +1135,74 @@ int                      CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
                                return genericConstraint->getUserConstraintId();
                        } 
 
+                       break;
+               }
+       case PHY_CONE_TWIST_CONSTRAINT:
+               {
+                       btConeTwistConstraint* coneTwistContraint = 0;
+
+                       
+                       if (rb1)
+                       {
+                               btTransform frameInA;
+                               btTransform frameInB;
+                               
+                               btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
+                               if (axis1.length() == 0.0)
+                               {
+                                       btPlaneSpace1( axisInA, axis1, axis2 );
+                               }
+                               
+                               frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
+                                                                 axisInA.y(), axis1.y(), axis2.y(),
+                                                                                         axisInA.z(), axis1.z(), axis2.z() );
+                               frameInA.setOrigin( pivotInA );
+
+                               btTransform inv = rb1->getCenterOfMassTransform().inverse();
+
+                               btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
+                               
+                               frameInB = inv  * globalFrameA;
+                               
+                               coneTwistContraint = new btConeTwistConstraint( *rb0,*rb1,
+                                       frameInA,frameInB);
+
+
+                       } else
+                       {
+                               static btRigidBody s_fixedObject2( 0,0,0);
+                               btTransform frameInA;
+                               btTransform frameInB;
+                               
+                               btVector3 axis1, axis2;
+                               btPlaneSpace1( axisInA, axis1, axis2 );
+
+                               frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
+                                                                 axisInA.y(), axis1.y(), axis2.y(),
+                                                                                         axisInA.z(), axis1.z(), axis2.z() );
+
+                               frameInA.setOrigin( pivotInA );
+
+                               ///frameInB in worldspace
+                               frameInB = rb0->getCenterOfMassTransform() * frameInA;
+
+                               coneTwistContraint = new btConeTwistConstraint(
+                                       *rb0,s_fixedObject2,
+                                       frameInA,frameInB);
+                       }
+                       
+                       if (coneTwistContraint)
+                       {
+                               //m_constraints.push_back(genericConstraint);
+                               m_dynamicsWorld->addConstraint(coneTwistContraint);
+                               coneTwistContraint->setUserConstraintId(gConstraintUid++);
+                               coneTwistContraint->setUserConstraintType(type);
+                               //64 bit systems can't cast pointer to int. could use size_t instead.
+                               return coneTwistContraint->getUserConstraintId();
+                       } 
+
+
+
                        break;
                }
        case PHY_ANGULAR_CONSTRAINT:
index 3952377181a0f270260531d4edd50e1e48e29449..68b60192fbc3324d2a58eae06b96c406122f9bed 100644 (file)
@@ -81,6 +81,7 @@ typedef enum PHY_ConstraintType {
        PHY_POINT2POINT_CONSTRAINT=1,
        PHY_LINEHINGE_CONSTRAINT=2,
        PHY_ANGULAR_CONSTRAINT = 3,//hinge without ball socket
+       PHY_CONE_TWIST_CONSTRAINT = 4,
        PHY_VEHICLE_CONSTRAINT=11,//complex 'constraint' that turns a rigidbody into a vehicle
        PHY_GENERIC_6DOF_CONSTRAINT=12,//can leave any of the 6 degree of freedom 'free' or 'locked'