forked from bartvdbraak/blender
fix generic 6dof constraint support -> convert 3 values into euler angles and convert those into a full constraint frame
(same values as Rigid Body constraint Generic 6DOF values), and add 'setLimit' support for generic 6DOF constraint. todo: enableMotor
This commit is contained in:
parent
eb8c5f3272
commit
4922dd0339
@ -54,6 +54,31 @@ PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* args, PyObject* kwds
|
||||
return PyInt_FromLong(m_constraintId);
|
||||
}
|
||||
|
||||
PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
int len = PyTuple_Size(args);
|
||||
int success = 1;
|
||||
|
||||
if (len == 3)
|
||||
{
|
||||
int dof;
|
||||
float minLimit,maxLimit;
|
||||
success = PyArg_ParseTuple(args,"iff",&dof,&minLimit,&maxLimit);
|
||||
if (success)
|
||||
{
|
||||
m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
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 = {
|
||||
#if (PY_VERSION_HEX >= 0x02060000)
|
||||
@ -100,8 +125,13 @@ 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},
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
|
||||
KX_PYMETHOD(KX_ConstraintWrapper,TestMethod);
|
||||
KX_PYMETHOD(KX_ConstraintWrapper,GetConstraintId);
|
||||
KX_PYMETHOD(KX_ConstraintWrapper,SetLimit);
|
||||
KX_PYMETHOD(KX_ConstraintWrapper,EnableMotor);
|
||||
|
||||
private:
|
||||
int m_constraintId;
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "KX_PhysicsObjectWrapper.h"
|
||||
#include "PHY_IPhysicsController.h"
|
||||
#include "PHY_IVehicle.h"
|
||||
#include "MT_Matrix3x3.h"
|
||||
|
||||
#include "PyObjectPlus.h"
|
||||
|
||||
@ -435,7 +436,31 @@ static PyObject* gPyCreateConstraint(PyObject* self,
|
||||
PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
|
||||
if (physctrl) //TODO:check for existance of this pointer!
|
||||
{
|
||||
int constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
|
||||
PHY_ConstraintType ct = (PHY_ConstraintType) constrainttype;
|
||||
int constraintid =0;
|
||||
|
||||
if (ct == PHY_GENERIC_6DOF_CONSTRAINT)
|
||||
{
|
||||
//convert from euler angle into axis
|
||||
float radsPerDeg = 6.283185307179586232f / 360.f;
|
||||
|
||||
//we need to pass a full constraint frame, not just axis
|
||||
//localConstraintFrameBasis
|
||||
MT_Matrix3x3 localCFrame(MT_Vector3(radsPerDeg*axisX,radsPerDeg*axisY,radsPerDeg*axisZ));
|
||||
MT_Vector3 axis0 = localCFrame.getColumn(0);
|
||||
MT_Vector3 axis1 = localCFrame.getColumn(1);
|
||||
MT_Vector3 axis2 = localCFrame.getColumn(2);
|
||||
|
||||
constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,
|
||||
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?
|
||||
|
||||
} else
|
||||
{
|
||||
constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
|
||||
}
|
||||
|
||||
KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user