- added support for generic 6DOF constraint

- only 6DOF constraint shows buttons for limits
- added python support for rigidbody constraint (untested, but required for COLLADA Physics support)
This commit is contained in:
Erwin Coumans 2006-12-02 03:48:36 +00:00
parent bcb3aec646
commit 28bbf2d616
9 changed files with 366 additions and 89 deletions

View File

@ -318,10 +318,11 @@ typedef struct bRigidBodyJointConstraint{
#define LIMIT_NOPARENT 0x01
/* important: these defines need to match up with PHY_DynamicTypes headerfile */
#define CONSTRAINT_RB_BALL 1
#define CONSTRAINT_RB_HINGE 2
#define CONSTRAINT_RB_GENERIC6DOF 3
#define CONSTRAINT_RB_VEHICLE 11
#define CONSTRAINT_RB_GENERIC6DOF 12
#endif

View File

@ -124,6 +124,33 @@ enum constraint_constants {
EXPP_CONSTR_LIMLOCALBONE,
EXPP_CONSTR_LIMLOCALNOPAR,
EXPP_CONSTR_RB_TYPE,
EXPP_CONSTR_RB_BALL,
EXPP_CONSTR_RB_HINGE,
EXPP_CONSTR_RB_GENERIC6DOF,
EXPP_CONSTR_RB_VEHICLE,
EXPP_CONSTR_RB_PIVX,
EXPP_CONSTR_RB_PIVY,
EXPP_CONSTR_RB_PIVZ,
EXPP_CONSTR_RB_AXX,
EXPP_CONSTR_RB_AXY,
EXPP_CONSTR_RB_AXZ,
EXPP_CONSTR_RB_MINLIMIT0,
EXPP_CONSTR_RB_MINLIMIT1,
EXPP_CONSTR_RB_MINLIMIT2,
EXPP_CONSTR_RB_MINLIMIT3,
EXPP_CONSTR_RB_MINLIMIT4,
EXPP_CONSTR_RB_MINLIMIT5,
EXPP_CONSTR_RB_MAXLIMIT0,
EXPP_CONSTR_RB_MAXLIMIT1,
EXPP_CONSTR_RB_MAXLIMIT2,
EXPP_CONSTR_RB_MAXLIMIT3,
EXPP_CONSTR_RB_MAXLIMIT4,
EXPP_CONSTR_RB_MAXLIMIT5,
EXPP_CONSTR_RB_EXTRAFZ,
EXPP_CONSTR_RB_FLAG,
};
/*****************************************************************************/
@ -1147,6 +1174,125 @@ static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
}
}
static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
{
bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
switch( type ) {
case EXPP_CONSTR_TARGET:
return Object_CreatePyObject( con->tar );
case EXPP_CONSTR_RB_PIVX:
return PyFloat_FromDouble( (double)con->pivX );
case EXPP_CONSTR_RB_PIVY:
return PyFloat_FromDouble( (double)con->pivY );
case EXPP_CONSTR_RB_PIVZ:
return PyFloat_FromDouble( (double)con->pivZ );
case EXPP_CONSTR_RB_AXX:
return PyFloat_FromDouble( (double)con->axX );
case EXPP_CONSTR_RB_AXY:
return PyFloat_FromDouble( (double)con->axY );
case EXPP_CONSTR_RB_AXZ:
return PyFloat_FromDouble( (double)con->axZ );
case EXPP_CONSTR_RB_MINLIMIT0:
return PyFloat_FromDouble( (double)con->minLimit[0] );
case EXPP_CONSTR_RB_MINLIMIT1:
return PyFloat_FromDouble( (double)con->minLimit[1] );
case EXPP_CONSTR_RB_MINLIMIT2:
return PyFloat_FromDouble( (double)con->minLimit[2] );
case EXPP_CONSTR_RB_MINLIMIT3:
return PyFloat_FromDouble( (double)con->minLimit[3] );
case EXPP_CONSTR_RB_MINLIMIT4:
return PyFloat_FromDouble( (double)con->minLimit[4] );
case EXPP_CONSTR_RB_MINLIMIT5:
return PyFloat_FromDouble( (double)con->minLimit[5] );
case EXPP_CONSTR_RB_MAXLIMIT0:
return PyFloat_FromDouble( (double)con->maxLimit[0] );
case EXPP_CONSTR_RB_MAXLIMIT1:
return PyFloat_FromDouble( (double)con->maxLimit[1] );
case EXPP_CONSTR_RB_MAXLIMIT2:
return PyFloat_FromDouble( (double)con->maxLimit[2] );
case EXPP_CONSTR_RB_MAXLIMIT3:
return PyFloat_FromDouble( (double)con->maxLimit[3] );
case EXPP_CONSTR_RB_MAXLIMIT4:
return PyFloat_FromDouble( (double)con->maxLimit[4] );
case EXPP_CONSTR_RB_MAXLIMIT5:
return PyFloat_FromDouble( (double)con->maxLimit[5] );
case EXPP_CONSTR_RB_EXTRAFZ:
return PyFloat_FromDouble( (double)con->extraFz );
case EXPP_CONSTR_LIMIT:
return PyInt_FromLong( (int)con->flag );
case EXPP_CONSTR_RB_TYPE:
return PyInt_FromLong( (int)con->type );
default:
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
}
}
static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
{
bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
switch( type ) {
case EXPP_CONSTR_TARGET: {
Object *obj = (( BPy_Object * )value)->object;
if( !BPy_Object_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected BPy object argument" );
con->tar = obj;
return 0;
}
case EXPP_CONSTR_RB_PIVX:
return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_PIVY:
return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_PIVZ:
return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_AXX:
return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_AXY:
return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_AXZ:
return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT0:
return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT1:
return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT2:
return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT3:
return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT4:
return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MINLIMIT5:
return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT0:
return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT1:
return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT2:
return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT3:
return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT4:
return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_MAXLIMIT5:
return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
case EXPP_CONSTR_RB_EXTRAFZ:
return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );
case EXPP_CONSTR_LIMIT:
return EXPP_setIValueRange( value, &con->flag, 0,
LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
case EXPP_CONSTR_RB_TYPE:
return EXPP_setIValueRange( value, &con->type, 0,
EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
default:
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
}
}
/*
* get data from a constraint
*/
@ -1193,6 +1339,8 @@ static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
return loclimit_getter( self, setting );
case CONSTRAINT_TYPE_SIZELIMIT:
return sizelimit_getter( self, setting );
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
return rigidbody_getter( self, setting );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
case CONSTRAINT_TYPE_PYTHON:
default:
@ -1254,6 +1402,9 @@ static int Constraint_setData( BPy_Constraint * self, PyObject * key,
case CONSTRAINT_TYPE_SIZELIMIT:
result = sizelimit_setter( self, key_int, arg);
break;
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
result = rigidbody_setter( self, key_int, arg);
break;
case CONSTRAINT_TYPE_NULL:
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
@ -1483,7 +1634,7 @@ static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *args )
EXPP_ReturnPyObjError( PyExc_TypeError, "expected int argument" );
/* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these? */
if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_MINMAX )
if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT )
return EXPP_ReturnPyObjError( PyExc_ValueError,
"int argument out of range" );
@ -1747,6 +1898,8 @@ static PyObject *M_Constraint_TypeDict( void )
PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
PyConstant_Insert( d, "LIMITSIZE",
PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
PyConstant_Insert( d, "RIGIDBODYJOINT",
PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
}
return S;
}
@ -1927,6 +2080,58 @@ static PyObject *M_Constraint_SettingsDict( void )
PyInt_FromLong( EXPP_CONSTR_LIMLOCALBONE ) );
PyConstant_Insert( d, "LIMIT_LOCAL_NOPARENT",
PyInt_FromLong( EXPP_CONSTR_LIMLOCALNOPAR ) );
PyConstant_Insert( d, "CONSTR_RB_TYPE",
PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
PyConstant_Insert( d, "CONSTR_RB_BALL",
PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
PyConstant_Insert( d, "CONSTR_RB_HINGE",
PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
PyConstant_Insert( d, "CONSTR_RB_PIVX",
PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
PyConstant_Insert( d, "CONSTR_RB_PIVY",
PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
PyConstant_Insert( d, "CONSTR_RB_PIVZ",
PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
PyConstant_Insert( d, "CONSTR_RB_AXX",
PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
PyConstant_Insert( d, "CONSTR_RB_AXY",
PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
PyConstant_Insert( d, "CONSTR_RB_AXZ",
PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );
PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
PyConstant_Insert( d, "CONSTR_RB_FLAG",
PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
}
return S;
}

View File

@ -1136,21 +1136,23 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
bRigidBodyJointConstraint *data = con->data;
int togButWidth = 70;
int offsetY = 150;
float extremeLin = 1000.f;
float extremeLin = 999.f;
float extremeAngX = 180.f;
float extremeAngY = 45.f;
float extremeAngZ = 45.f;
int textButWidth = ((width/2)-togButWidth);
uiDefButI(block, MENU, B_SWITCHRENDER, "Joint Types%t|Ball%x1|Hinge%x2|Generic6DOF%x3",//|Extra Force%x6",
uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Generic6DOF%x12",//|Extra Force%x6",
*xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
height = 310;
height = 140;
if (data->type==CONSTRAINT_RB_GENERIC6DOF){
height = 270;
}
uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
{
//uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "Child:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
//if (data->tar)
// uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "Child:", *xco+135, *yco-50, 130, 18, &data->child, "Child2 Object (if this exist then this object will be the pivot Only)");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -10000, 10000, 100.0, 0.0, "Offset Joint");
@ -1159,67 +1161,66 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -10000, 10000, 100.0, 0.0, "Offset Joint");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -10000, 10000, 100.0, 0.0, "Offset Joint");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -10000, 10000, 100.0, 0.0, "Offset Joint");
/* Draw Pairs of LimitToggle+LimitValue */
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "LinMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth-5), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "LinMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth-5), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_ZMIN, 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-5), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit");
uiBlockEndAlign(block);
offsetY += 20;
/* Draw Pairs of LimitToggle+LimitValue */
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "AngMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth-5), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "AngMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth-5), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "AngMaxZ", *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-5), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit");
uiBlockEndAlign(block);
}
if (data->type==CONSTRAINT_RB_GENERIC6DOF){
/* Draw Pairs of LimitToggle+LimitValue */
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
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");
uiBlockEndAlign(block);
offsetY += 20;
/* 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");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit");
uiBlockEndAlign(block);
offsetY += 20;
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", *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[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit");
uiBlockEndAlign(block);
}
}
}
break;
case CONSTRAINT_TYPE_NULL:

View File

@ -1939,12 +1939,37 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
for (curcon = (bConstraint *)conlist->first; curcon; curcon=(bConstraint *)curcon->next) {
if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT){
bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data;
if (dat->tar)
//if (dat->tar)
if (!dat->child){
KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist);
PHY_IPhysicsController* physctr2 = 0;
if (dat->tar)
{
KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist);
physctr2 = (PHY_IPhysicsController*) gotar->GetPhysicsController()->GetUserData();
}
PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData();
PHY_IPhysicsController* physctr2 = (PHY_IPhysicsController*) gotar->GetPhysicsController()->GetUserData();
kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ);
int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ);
//if it is a generic 6DOF constraint, set all the limits accordingly
if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT)
{
int dof;
int dofbit=1;
for (dof=0;dof<6;dof++)
{
if (dat->flag & dofbit)
{
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
} else
{
//minLimit > maxLimit means free(disabled limit) for this degree of freedom
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1);
}
dofbit<<=1;
}
}
}
}
}

View File

@ -782,24 +782,37 @@ CcdPhysicsController* CcdPhysicsEnvironment::GetPhysicsController( int index)
void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float value0,float value1)
{
btTypedConstraint* typedConstraint = getConstraintById(constraintId);
switch (typedConstraint->getUserConstraintType())
{
case PHY_GENERIC_6DOF_CONSTRAINT:
{
//param = 1..12, min0,max0,min1,max1...min6,max6
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
genCons->SetLimit(param,value0,value1);
break;
};
default:
{
};
};
}
btTypedConstraint* CcdPhysicsEnvironment::getConstraintById(int constraintId)
{
return 0;
/*
int numConstraint = m_constraints.size();
int numConstraints = m_dynamicsWorld->getNumConstraints();
int i;
for (i=0;i<numConstraint;i++)
for (i=0;i<numConstraints;i++)
{
btTypedConstraint* constraint = m_constraints[i];
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
if (constraint->getUserConstraintId()==constraintId)
{
return constraint;
}
}
*/
return 0;
}
@ -1004,7 +1017,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
return 0;
btVector3 pivotInA(pivotX,pivotY,pivotZ);
btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) : pivotInA;
btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) :
rb0->getCenterOfMassTransform() * pivotInA;
btVector3 axisInA(axisX,axisY,axisZ);
btVector3 axisInB = rb1 ?
(rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * axisInA)) :
@ -1072,17 +1086,41 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
} else
{
// TODO: Implement single body case...
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() );
btPlaneSpace1( axisInB, axis1, axis2 );
frameInB.getBasis().setValue( axisInB.x(), axis1.x(), axis2.x(),
axisInB.y(), axis1.y(), axis2.y(),
axisInB.z(), axis1.z(), axis2.z() );
frameInA.setOrigin( pivotInA );
frameInB.setOrigin( pivotInB );
genericConstraint = new btGeneric6DofConstraint(
*rb0,s_fixedObject2,
frameInA,frameInB);
}
//m_constraints.push_back(genericConstraint);
m_dynamicsWorld->addConstraint(genericConstraint);
genericConstraint->setUserConstraintId(gConstraintUid++);
genericConstraint->setUserConstraintType(type);
//64 bit systems can't cast pointer to int. could use size_t instead.
return genericConstraint->getUserConstraintId();
if (genericConstraint)
{
//m_constraints.push_back(genericConstraint);
m_dynamicsWorld->addConstraint(genericConstraint);
genericConstraint->setUserConstraintId(gConstraintUid++);
genericConstraint->setUserConstraintType(type);
//64 bit systems can't cast pointer to int. could use size_t instead.
return genericConstraint->getUserConstraintId();
}
break;
}

View File

@ -131,6 +131,7 @@ protected:
const btVector3& angularMaxLimits
);
virtual void setConstraintParam(int constraintId,int param,float value,float value1);
virtual void removeConstraint(int constraintid);

View File

@ -83,6 +83,9 @@ public:
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
virtual void setConstraintParam(int constraintId,int param,float value,float value1)
{
}
};

View File

@ -86,7 +86,9 @@ public:
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
virtual void setConstraintParam(int constraintId,int param,float value,float value1)
{
}
SM_Scene* GetSumoScene()
{
return m_sumoScene;

View File

@ -107,6 +107,7 @@ class PHY_IPhysicsEnvironment
virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
virtual void setConstraintParam(int constraintId,int param,float value,float value1) = 0;
};
#endif //_IPHYSICSENVIRONMENT