Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
| Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static PyObject *gPyCreateConstraint(PyObject *self, | static PyObject *gPyCreateConstraint(PyObject *self, | ||||
| PyObject *args, | PyObject *args, | ||||
| PyObject *kwds) | PyObject *kwds) | ||||
| { | { | ||||
| /* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */ | /* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */ | ||||
| unsigned long long physicsid = 0, physicsid2 = 0; | unsigned long long physicsid = 0, physicsid2 = 0; | ||||
| int constrainttype=0, extrainfo=0; | int constrainttype = 0; | ||||
| int len = PyTuple_Size(args); | int len = PyTuple_Size(args); | ||||
| int success = 1; | |||||
| int flag = 0; | int flag = 0; | ||||
| float pivotX = 0.0f, pivotY = 0.0f, pivotZ = 0.0f, axisX = 0.0f, axisY = 0.0f, axisZ = 0.0f; | |||||
| float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1; | static const char *kwlist[] = {"physicsid_1", "physicsid_2", "constraint_type", "pivot_x", "pivot_y", "pivot_z", | ||||
| if (len == 3) | "axis_X", "axis_y", "axis_z", "flag", NULL}; | ||||
| { | |||||
| success = PyArg_ParseTuple(args, "KKi", &physicsid, &physicsid2, &constrainttype); | |||||
| } | |||||
| else if (len == 6) | |||||
| { | |||||
| success = PyArg_ParseTuple(args, "KKifff", &physicsid, &physicsid2, &constrainttype, | |||||
| &pivotX, &pivotY, &pivotZ); | |||||
| } | |||||
| else if (len == 9) | |||||
| { | |||||
| success = PyArg_ParseTuple(args, "KKiffffff", &physicsid, &physicsid2, &constrainttype, | |||||
| &pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ); | |||||
| } | |||||
| else if (len == 10) | |||||
| { | |||||
| success = PyArg_ParseTuple(args, "KKiffffffi", &physicsid, &physicsid2, &constrainttype, | |||||
| &pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ, &flag); | |||||
| } | |||||
| /* XXX extrainfo seems to be nothing implemented. right now it works as a pivot with [X,0,0] */ | if (!PyArg_ParseTupleAndKeywords(args, kwds, "KKi|ffffffi:createConstraint", (char **)kwlist, | ||||
| else if (len == 4) | &physicsid, &physicsid2, &constrainttype, | ||||
| &pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ, &flag)) | |||||
| { | { | ||||
lordloki: Would it be better "if ((len != 3) || (len != 6) || (len != 9) || (len != 10))"? this way we… | |||||
Not Done Inline ActionsThat is not necessary, because the other checks will be done by PyArg_ParseTupleAndKeywords method, which generates more advanced error messages. I don't want to overwrite it. hg1: That is not necessary, because the other checks will be done by PyArg_ParseTupleAndKeywords… | |||||
Not Done Inline ActionsOk. lordloki: Ok. | |||||
Not Done Inline ActionsAs far as I can see this length check isnt needed. Original code that checks this is only doing so because I guess the author didnt know to use | in PyArg_ParseTuple campbellbarton: As far as I can see this length check isnt needed. Original code that checks this is only doing… | |||||
| success = PyArg_ParseTuple(args,"KKii", &physicsid, &physicsid2, &constrainttype, &extrainfo); | return NULL; | ||||
| pivotX=extrainfo; | |||||
| } | } | ||||
| if (success) | if (PHY_GetActiveEnvironment()) { | ||||
| { | |||||
| if (PHY_GetActiveEnvironment()) | |||||
| { | |||||
| PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) physicsid; | PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid; | ||||
| PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2; | PHY_IPhysicsController *physctrl2 = (PHY_IPhysicsController*)physicsid2; | ||||
| if (physctrl) //TODO:check for existence of this pointer! | if (physctrl) { //TODO:check for existence of this pointer! | ||||
| { | |||||
| int constraintid =0; | |||||
| //convert from euler angle into axis | //convert from euler angle into axis | ||||
| float radsPerDeg = 6.283185307179586232f / 360.f; | const float deg2rad = 0.017453292f; | ||||
| //we need to pass a full constraint frame, not just axis | //we need to pass a full constraint frame, not just axis | ||||
| //localConstraintFrameBasis | //localConstraintFrameBasis | ||||
| MT_Matrix3x3 localCFrame(MT_Vector3(radsPerDeg*axisX,radsPerDeg*axisY,radsPerDeg*axisZ)); | MT_Matrix3x3 localCFrame(MT_Vector3(deg2rad*axisX, deg2rad*axisY, deg2rad*axisZ)); | ||||
| MT_Vector3 axis0 = localCFrame.getColumn(0); | MT_Vector3 axis0 = localCFrame.getColumn(0); | ||||
| MT_Vector3 axis1 = localCFrame.getColumn(1); | MT_Vector3 axis1 = localCFrame.getColumn(1); | ||||
| MT_Vector3 axis2 = localCFrame.getColumn(2); | MT_Vector3 axis2 = localCFrame.getColumn(2); | ||||
| constraintid = PHY_GetActiveEnvironment()->CreateConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype, | int constraintid = PHY_GetActiveEnvironment()->CreateConstraint( | ||||
| pivotX,pivotY,pivotZ, | physctrl, physctrl2, (enum PHY_ConstraintType)constrainttype, pivotX, pivotY, pivotZ, | ||||
| (float)axis0.x(),(float)axis0.y(),(float)axis0.z(), | (float)axis0.x(), (float)axis0.y(), (float)axis0.z(), | ||||
| (float)axis1.x(),(float)axis1.y(),(float)axis1.z(), | (float)axis1.x(), (float)axis1.y(), (float)axis1.z(), | ||||
| (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag); | (float)axis2.x(), (float)axis2.y(), (float)axis2.z(), flag); | ||||
| KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment()); | KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper( | ||||
| (enum PHY_ConstraintType)constrainttype, constraintid, PHY_GetActiveEnvironment()); | |||||
| return wrap->NewProxy(true); | return wrap->NewProxy(true); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else { | |||||
| return NULL; | |||||
| } | |||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
Not Done Inline ActionsNormally we use 8 spaces indentation for function args. Helps differentiate with indentation between braces. campbellbarton: Normally we use 8 spaces indentation for function args.
http://wiki.blender.org/index.php/Dev… | |||||
Not Done Inline ActionsThen the Wiki is wrong.http://wiki.blender.org/index.php/Dev:Doc/Code_Style#Indentation.
hg1: Then the Wiki is wrong.http://wiki.blender.org/index.php/Dev:Doc/Code_Style#Indentation.
* It… | |||||
| static PyObject *gPyGetAppliedImpulse(PyObject *self, | static PyObject *gPyGetAppliedImpulse(PyObject *self, | ||||
| PyObject *args, | PyObject *args, | ||||
| PyObject *kwds) | PyObject *kwds) | ||||
| { | { | ||||
| float appliedImpulse = 0.f; | float appliedImpulse = 0.f; | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | static struct PyMethodDef physicsconstraints_methods[] = { | ||||
| {"setUseEpa",(PyCFunction) gPySetUseEpa, | {"setUseEpa",(PyCFunction) gPySetUseEpa, | ||||
| METH_VARARGS, (const char *)gPySetUseEpa__doc__}, | METH_VARARGS, (const char *)gPySetUseEpa__doc__}, | ||||
| {"setSolverType",(PyCFunction) gPySetSolverType, | {"setSolverType",(PyCFunction) gPySetSolverType, | ||||
| METH_VARARGS, (const char *)gPySetSolverType__doc__}, | METH_VARARGS, (const char *)gPySetSolverType__doc__}, | ||||
| {"createConstraint",(PyCFunction) gPyCreateConstraint, | {"createConstraint",(PyCFunction) gPyCreateConstraint, | ||||
| METH_VARARGS, (const char *)gPyCreateConstraint__doc__}, | METH_VARARGS|METH_KEYWORDS, (const char *)gPyCreateConstraint__doc__}, | ||||
| {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint, | {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint, | ||||
| METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__}, | METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__}, | ||||
| {"getCharacter",(PyCFunction) gPyGetCharacter, | {"getCharacter",(PyCFunction) gPyGetCharacter, | ||||
| METH_VARARGS, (const char *)gPyGetCharacter__doc__}, | METH_VARARGS, (const char *)gPyGetCharacter__doc__}, | ||||
| {"removeConstraint",(PyCFunction) gPyRemoveConstraint, | {"removeConstraint",(PyCFunction) gPyRemoveConstraint, | ||||
| METH_VARARGS, (const char *)gPyRemoveConstraint__doc__}, | METH_VARARGS, (const char *)gPyRemoveConstraint__doc__}, | ||||
| ▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines | |||||
Would it be better "if ((len != 3) || (len != 6) || (len != 9) || (len != 10))"? this way we check for len < 3 and len > 10 also