BGE: Add keyword arguments to createConstraint API
Added keyword arguments to createConstraint. Changed initial values for the pivod XYZ form 1 to 0.0. Changed initial values for the axis Z form 1 to 0.0. Delete the parsing for 4 parameters, because parsing only the X pivot is not necessary, also it was not working correctly (int instead of float). Reviewers: brita_, sybren, lordloki, campbellbarton, moguri Reviewed By: lordloki, campbellbarton Subscribers: campbellbarton Differential Revision: https://developer.blender.org/D705
This commit is contained in:
parent
b329016b29
commit
87b6d3c796
|
@ -11,14 +11,14 @@ Physics Constraints (bge.constraints)
|
|||
.. literalinclude:: ../examples/bge.constraints.py
|
||||
:lines: 6-
|
||||
|
||||
.. function:: createConstraint(physicsid, physicsid2, constrainttype, [pivotX, pivotY, pivotZ, [axisX, axisY, axisZ, [flag]]]])
|
||||
.. function:: createConstraint(physicsid_1, physicsid_2, constraint_type, pivot_X, pivot_y, pivot_z, axis_x, axis_y, axis_z, flag)
|
||||
|
||||
Creates a constraint.
|
||||
|
||||
:arg physicsid: the physics id of the first object in constraint
|
||||
:arg physicsid_1: the physics id of the first object in constraint
|
||||
:type physicsid: int
|
||||
|
||||
:arg physicsid2: the physics id of the second object in constraint
|
||||
:arg physicsid_2: the physics id of the second object in constraint
|
||||
:type physicsid2: int
|
||||
|
||||
:arg constrainttype: the type of the constraint. The constraint types are:
|
||||
|
@ -32,26 +32,26 @@ Physics Constraints (bge.constraints)
|
|||
|
||||
:type constrainttype: int
|
||||
|
||||
:arg pivotX: pivot X position
|
||||
:type pivotX: float
|
||||
:arg pivot_X: pivot X position
|
||||
:type pivot_X: float (optional)
|
||||
|
||||
:arg pivotY: pivot Y position
|
||||
:type pivotY: float
|
||||
:arg pivot_Y: pivot Y position
|
||||
:type pivot_Y: float (optional)
|
||||
|
||||
:arg pivotZ: pivot Z position
|
||||
:type pivotZ: float
|
||||
:arg pivot_Z: pivot Z position
|
||||
:type pivot_Z: float (optional)
|
||||
|
||||
:arg axisX: X axis
|
||||
:type axisX: float
|
||||
:arg axis_X: X axis angle in degrees
|
||||
:type axis_X: float (optional)
|
||||
|
||||
:arg axisY: Y axis
|
||||
:type axisY: float
|
||||
:arg axis_Y: Y axis angle in degrees
|
||||
:type axis_Y: float (optional)
|
||||
|
||||
:arg axisZ: Z axis
|
||||
:type axisZ: float
|
||||
:arg axis_Z: Z axis angle in degrees
|
||||
:type axis_Z: float (optional)
|
||||
|
||||
:arg flag: 128 to disable collision between linked bodies
|
||||
:type flag: int
|
||||
:type flag: int (optional)
|
||||
|
||||
.. attribute:: error
|
||||
|
||||
|
|
|
@ -496,78 +496,47 @@ static PyObject *gPyCreateConstraint(PyObject *self,
|
|||
{
|
||||
/* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */
|
||||
unsigned long long physicsid = 0, physicsid2 = 0;
|
||||
int constrainttype=0, extrainfo=0;
|
||||
int constrainttype = 0;
|
||||
int len = PyTuple_Size(args);
|
||||
int success = 1;
|
||||
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;
|
||||
if (len == 3)
|
||||
static const char *kwlist[] = {"physicsid_1", "physicsid_2", "constraint_type", "pivot_x", "pivot_y", "pivot_z",
|
||||
"axis_X", "axis_y", "axis_z", "flag", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "KKi|ffffffi:createConstraint", (char **)kwlist,
|
||||
&physicsid, &physicsid2, &constrainttype,
|
||||
&pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ, &flag))
|
||||
{
|
||||
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] */
|
||||
else if (len == 4)
|
||||
{
|
||||
success = PyArg_ParseTuple(args,"KKii", &physicsid, &physicsid2, &constrainttype, &extrainfo);
|
||||
pivotX=extrainfo;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (PHY_GetActiveEnvironment())
|
||||
{
|
||||
|
||||
PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) physicsid;
|
||||
PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
|
||||
if (physctrl) //TODO:check for existence of this pointer!
|
||||
{
|
||||
int constraintid =0;
|
||||
|
||||
//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(),flag);
|
||||
|
||||
KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment());
|
||||
|
||||
return wrap->NewProxy(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PHY_GetActiveEnvironment()) {
|
||||
PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid;
|
||||
PHY_IPhysicsController *physctrl2 = (PHY_IPhysicsController*)physicsid2;
|
||||
if (physctrl) { //TODO:check for existence of this pointer!
|
||||
//convert from euler angle into axis
|
||||
const float deg2rad = 0.017453292f;
|
||||
|
||||
//we need to pass a full constraint frame, not just axis
|
||||
//localConstraintFrameBasis
|
||||
MT_Matrix3x3 localCFrame(MT_Vector3(deg2rad*axisX, deg2rad*axisY, deg2rad*axisZ));
|
||||
MT_Vector3 axis0 = localCFrame.getColumn(0);
|
||||
MT_Vector3 axis1 = localCFrame.getColumn(1);
|
||||
MT_Vector3 axis2 = localCFrame.getColumn(2);
|
||||
|
||||
int 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(), flag);
|
||||
|
||||
KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper(
|
||||
(enum PHY_ConstraintType)constrainttype, constraintid, PHY_GetActiveEnvironment());
|
||||
|
||||
return wrap->NewProxy(true);
|
||||
}
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
@ -680,7 +649,7 @@ static struct PyMethodDef physicsconstraints_methods[] = {
|
|||
|
||||
|
||||
{"createConstraint",(PyCFunction) gPyCreateConstraint,
|
||||
METH_VARARGS, (const char *)gPyCreateConstraint__doc__},
|
||||
METH_VARARGS|METH_KEYWORDS, (const char *)gPyCreateConstraint__doc__},
|
||||
{"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint,
|
||||
METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__},
|
||||
|
||||
|
|
Loading…
Reference in New Issue