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
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2009-05-24 04:42:40 +0400
committerErwin Coumans <blender@erwincoumans.com>2009-05-24 04:42:40 +0400
commit4922dd03393489e85f04bd5785496c44af78d0d6 (patch)
treef4f23d63f4b02aa196ed64541667d30c5a6622d0
parenteb8c5f3272b87fffaf017badf55f761de9a04fd1 (diff)
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
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.cpp30
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.h2
-rw-r--r--source/gameengine/Ketsji/KX_PyConstraintBinding.cpp27
3 files changed, 58 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
index c63f9e57ed2..7af2b15a14c 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
@@ -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
};
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h
index 3270d57188d..0772d257b56 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.h
@@ -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;
diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
index 0f21b24489d..1d52057317e 100644
--- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
+++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
@@ -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());