bugfixes for generic (experimental) Bullet rigidbody constraint: use cone-twist instead (needs a few more minor fixes)

Note: Visual Studio projectfiles and other buildsystems need to add extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp to the project!
This commit is contained in:
2007-07-16 05:56:51 +00:00
parent 044b354458
commit 3792ae1560
4 changed files with 75 additions and 2 deletions

View 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

View 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");

View 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:

View 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'