Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2009-05-24 05:55:24 +0400
committerErwin Coumans <blender@erwincoumans.com>2009-05-24 05:55:24 +0400
commit52b0a2b3dbf5c5e0b930dcaff8647ec1d06e2d3c (patch)
tree30dff2055ffbfd7dfc5d1cb399912db7fd8cede6 /source
parent4922dd03393489e85f04bd5785496c44af78d0d6 (diff)
PhysicsConstraints.createConstraint:
allow to dynamically create rigid body constraints while disable collision detection between connected bodies, pass as 10th argument the flag 128 PhysiPython KX_ConstraintWrapper, setParam export setParam(paramIndex,paramValue0,paramValue1) for Physics constraints paramIndex 0,1,2 are linear limits, 3,4,5 are angular limits, 6,7,8 are linear motors, 9,10,11 are angular motors For example: disableConnectedBodies=128 cons = PhysicsConstraints.createConstraint(oid,rid,generic6dof,pivotInAx,pivotInAy,pivotInAz,angleX,angleY,angleZ,disableConnectedBodies) #params 0,1,2 are linear limits, low,high value. if low > high then disable limit cons.setParam(0,0,0) I will provide an example .blend for Blender 2.49
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.cpp11
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.h3
-rw-r--r--source/gameengine/Ketsji/KX_PyConstraintBinding.cpp9
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp47
4 files changed, 56 insertions, 14 deletions
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
index 7af2b15a14c..b0576424a47 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
@@ -54,7 +54,7 @@ PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* args, PyObject* kwds
return PyInt_FromLong(m_constraintId);
}
-PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
+PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds)
{
int len = PyTuple_Size(args);
int success = 1;
@@ -73,11 +73,7 @@ PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
return NULL;
}
-PyObject* KX_ConstraintWrapper::PyEnableMotor(PyObject* args, PyObject* kwds)
-{
- ///will add it soon
- return PyInt_FromLong(0);
-}
+
//python specific stuff
PyTypeObject KX_ConstraintWrapper::Type = {
@@ -130,8 +126,7 @@ int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* value)
PyMethodDef KX_ConstraintWrapper::Methods[] = {
{"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
- {"setLimit",(PyCFunction) KX_ConstraintWrapper::sPySetLimit, METH_VARARGS},
- {"enableMotor",(PyCFunction) KX_ConstraintWrapper::sPyEnableMotor, METH_VARARGS},
+ {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
{NULL,NULL} //Sentinel
};
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h
index 0772d257b56..b8ac464ceab 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.h
@@ -45,8 +45,7 @@ public:
KX_PYMETHOD(KX_ConstraintWrapper,TestMethod);
KX_PYMETHOD(KX_ConstraintWrapper,GetConstraintId);
- KX_PYMETHOD(KX_ConstraintWrapper,SetLimit);
- KX_PYMETHOD(KX_ConstraintWrapper,EnableMotor);
+ KX_PYMETHOD(KX_ConstraintWrapper,SetParam);
private:
int m_constraintId;
diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
index 1d52057317e..a098d99864f 100644
--- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
+++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
@@ -405,6 +405,8 @@ static PyObject* gPyCreateConstraint(PyObject* self,
int physicsid=0,physicsid2 = 0,constrainttype=0,extrainfo=0;
int len = PyTuple_Size(args);
int success = 1;
+ int flag = 0;
+
float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1;
if (len == 3)
{
@@ -421,6 +423,11 @@ static PyObject* gPyCreateConstraint(PyObject* self,
success = PyArg_ParseTuple(args,"iiiffffff",&physicsid,&physicsid2,&constrainttype,
&pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
}
+ else if (len == 10)
+ {
+ success = PyArg_ParseTuple(args,"iiiffffffi",&physicsid,&physicsid2,&constrainttype,
+ &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
+ }
else if (len==4)
{
success = PyArg_ParseTuple(args,"iiii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
@@ -455,7 +462,7 @@ static PyObject* gPyCreateConstraint(PyObject* self,
pivotX,pivotY,pivotZ,
(float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
(float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
- (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),0);//dat->flag); //flag?
+ (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag);
} else
{
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index ed517e637dc..561c370854f 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -426,6 +426,13 @@ void CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctr
btRigidBody* body = ctrl->GetRigidBody();
if (body)
{
+ for (int i=body->getNumConstraintRefs()-1;i>=0;i--)
+ {
+ btTypedConstraint* con = body->getConstraintRef(i);
+ m_dynamicsWorld->removeConstraint(con);
+ body->removeConstraintRef(con);
+ //delete con; //might be kept by python KX_ConstraintWrapper
+ }
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
} else
{
@@ -1791,9 +1798,43 @@ void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float
{
case PHY_GENERIC_6DOF_CONSTRAINT:
{
- //param = 1..12, min0,max0,min1,max1...min6,max6
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- genCons->setLimit(param,value0,value1);
+
+ switch (param)
+ {
+ case 0: case 1: case 2: case 3: case 4: case 5:
+ {
+ //param = 0..5 are constraint limits, with low/high limit value
+ btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
+ genCons->setLimit(param,value0,value1);
+ break;
+ }
+ case 6: case 7: case 8:
+ {
+ //param = 6,7,8 are translational motors, with value0=target velocity, value1 = max motor force
+ btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
+ int transMotorIndex = param-6;
+ btTranslationalLimitMotor* transMotor = genCons->getTranslationalLimitMotor();
+ transMotor->m_targetVelocity[transMotorIndex]= value0;
+ transMotor->m_maxMotorForce[transMotorIndex]=value1;
+ transMotor->m_enableMotor[transMotorIndex] = (value1>0.f);
+ break;
+ }
+ case 9: case 10: case 11:
+ {
+ //param = 9,10,11 are rotational motors, with value0=target velocity, value1 = max motor force
+ btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
+ int angMotorIndex = param-9;
+ btRotationalLimitMotor* rotMotor = genCons->getRotationalLimitMotor(angMotorIndex);
+ rotMotor->m_enableMotor = (value1 > 0.f);
+ rotMotor->m_targetVelocity = value0;
+ rotMotor->m_maxMotorForce = value1;
+ break;
+ }
+
+ default:
+ {
+ }
+ }
break;
};
default: