#include "MT_Matrix3x3.h"
#include "KX_GameObject.h"
#include "KX_RayCast.h"
+#include "blendef.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
char *property,
PyTypeObject* T) :
SCA_IActuator(gameobj, T),
- m_refDirection(refDir),
+ m_refDirVector(refDir),
m_currentTime(0)
{
+ m_refDirection[0] = refDir[0];
+ m_refDirection[1] = refDir[1];
+ m_refDirection[2] = refDir[2];
m_posDampTime = posDampTime;
m_rotDampTime = rotDampTime;
m_locrot = locrotxyz;
m_option = option;
m_activeTime = time;
if (property) {
- strncpy(m_property, property, sizeof(m_property));
- m_property[sizeof(m_property)-1] = 0;
+ m_property = property;
} else {
- m_property[0] = 0;
+ m_property = "";
}
/* The units of bounds are determined by the type of constraint. To */
/* make the constraint application easier and more transparent later on, */
case KX_ACT_CONSTRAINT_ORIY:
case KX_ACT_CONSTRAINT_ORIZ:
{
- MT_Scalar len = m_refDirection.length();
+ MT_Scalar len = m_refDirVector.length();
if (MT_fuzzyZero(len)) {
// missing a valid direction
std::cout << "WARNING: Constraint actuator " << GetName() << ": There is no valid reference direction!" << std::endl;
m_locrot = KX_ACT_CONSTRAINT_NODEF;
} else {
- m_refDirection /= len;
+ m_refDirection[0] /= len;
+ m_refDirection[1] /= len;
+ m_refDirection[2] /= len;
+ m_refDirVector /= len;
}
m_minimumBound = cos(minBound);
m_maximumBound = cos(maxBound);
bool bFound = false;
- if (m_property[0] == 0)
+ if (m_property.IsEmpty())
{
bFound = true;
}
{
if (client->m_auxilary_info)
{
- bFound = !strcmp(m_property, ((char*)client->m_auxilary_info));
+ bFound = !strcmp(m_property.Ptr(), ((char*)client->m_auxilary_info));
}
}
else
if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) {
// reference direction needs to be evaluated
// 1. get the cosine between current direction and target
- cosangle = direction.dot(m_refDirection);
+ cosangle = direction.dot(m_refDirVector);
if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) {
// no change to do
result = true;
// 2. define a new reference direction
// compute local axis with reference direction as X and
// Y in direction X refDirection plane
- MT_Vector3 zaxis = m_refDirection.cross(direction);
+ MT_Vector3 zaxis = m_refDirVector.cross(direction);
if (MT_fuzzyZero2(zaxis.length2())) {
// direction and refDirection are identical,
// choose any other direction to define plane
if (direction[0] < 0.9999)
- zaxis = m_refDirection.cross(MT_Vector3(1.0,0.0,0.0));
+ zaxis = m_refDirVector.cross(MT_Vector3(1.0,0.0,0.0));
else
- zaxis = m_refDirection.cross(MT_Vector3(0.0,1.0,0.0));
+ zaxis = m_refDirVector.cross(MT_Vector3(0.0,1.0,0.0));
}
- MT_Vector3 yaxis = zaxis.cross(m_refDirection);
+ MT_Vector3 yaxis = zaxis.cross(m_refDirVector);
yaxis.normalize();
if (cosangle > m_minimumBound) {
// angle is too close to reference direction,
// choose a new reference that is exactly at minimum angle
- refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis;
+ refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis;
} else {
// angle is too large, choose new reference direction at maximum angle
- refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis;
+ refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis;
}
} else {
- refDirection = m_refDirection;
+ refDirection = m_refDirVector;
}
// apply damping on the direction
direction = filter*direction + (1.0-filter)*refDirection;
// Fh force is stored in m_maximum
MT_Scalar springForce = springExtent * m_maximumBound;
// damping is stored in m_refDirection [0] = damping, [1] = rot damping
- MT_Scalar springDamp = relativeVelocityRay * m_refDirection[0];
+ MT_Scalar springDamp = relativeVelocityRay * m_refDirVector[0];
MT_Vector3 newVelocity = spc->GetLinearVelocity()-(springForce+springDamp)*direction;
if (m_option & KX_ACT_CONSTRAINT_NORMAL)
{
MT_Vector3 angVelocity = spc->GetAngularVelocity();
// remove component that is parallel to normal
angVelocity -= angVelocity.dot(newnormal)*newnormal;
- MT_Vector3 angDamp = angVelocity * ((m_refDirection[1]>MT_EPSILON)?m_refDirection[1]:m_refDirection[0]);
+ MT_Vector3 angDamp = angVelocity * ((m_refDirVector[1]>MT_EPSILON)?m_refDirVector[1]:m_refDirVector[0]);
spc->SetAngularVelocity(spc->GetAngularVelocity()+(angSpring-angDamp), false);
}
} else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
};
PyMethodDef KX_ConstraintActuator::Methods[] = {
+ // Deprecated -->
{"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, (PY_METHODCHAR)SetDamp_doc},
{"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_NOARGS, (PY_METHODCHAR)GetDamp_doc},
{"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, (PY_METHODCHAR)SetRotDamp_doc},
{"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, (PY_METHODCHAR)GetRayLength_doc},
{"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, (PY_METHODCHAR)SetLimit_doc},
{"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_NOARGS, (PY_METHODCHAR)GetLimit_doc},
+ // <--
{NULL,NULL} //Sentinel
};
PyAttributeDef KX_ConstraintActuator::Attributes[] = {
+ KX_PYATTRIBUTE_INT_RW("damp",0,100,true,KX_ConstraintActuator,m_posDampTime),
+ KX_PYATTRIBUTE_INT_RW("rotDamp",0,100,true,KX_ConstraintActuator,m_rotDampTime),
+ KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction),
+ KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option),
+ KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime),
+ KX_PYATTRIBUTE_STRING_RW("property",0,32,true,KX_ConstraintActuator,m_property),
+ KX_PYATTRIBUTE_FLOAT_RW("min",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound),
+ KX_PYATTRIBUTE_FLOAT_RW("distance",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound),
+ KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_maximumBound),
+ KX_PYATTRIBUTE_FLOAT_RW("rayLength",0,2000.f,KX_ConstraintActuator,m_maximumBound),
+ KX_PYATTRIBUTE_INT_RW("limit",KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF+1,KX_ConstraintActuator::KX_ACT_CONSTRAINT_MAX-1,false,KX_ConstraintActuator,m_locrot),
{ NULL } //Sentinel
};
-PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) {
+PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr)
+{
py_getattro_up(SCA_IActuator);
}
+int KX_ConstraintActuator::py_setattro(PyObject *attr, PyObject* value)
+{
+ py_setattro_up(SCA_IActuator);
+}
+
+
+int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_ConstraintActuator* act = static_cast<KX_ConstraintActuator*>(self);
+ MT_Vector3 dir(act->m_refDirection);
+ MT_Scalar len = dir.length();
+ if (MT_fuzzyZero(len)) {
+ PyErr_SetString(PyExc_ValueError, "Invalid direction");
+ return 1;
+ }
+ act->m_refDirVector = dir/len;
+ return 0;
+}
+
/* 2. setDamp */
const char KX_ConstraintActuator::SetDamp_doc[] =
"setDamp(duration)\n"
PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setDamp()", "the damp property");
int dampArg;
if(!PyArg_ParseTuple(args, "i", &dampArg)) {
return NULL;
"getDamp()\n"
"\tReturns the damping parameter.\n";
PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){
+ ShowDeprecationWarning("getDamp()", "the damp property");
return PyInt_FromLong(m_posDampTime);
}
PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setRotDamp()", "the rotDamp property");
int dampArg;
if(!PyArg_ParseTuple(args, "i", &dampArg)) {
return NULL;
"getRotDamp()\n"
"\tReturns the damping time for application of the constraint.\n";
PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){
+ ShowDeprecationWarning("getRotDamp()", "the rotDamp property");
return PyInt_FromLong(m_rotDampTime);
}
PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setDirection()", "the direction property");
float x, y, z;
MT_Scalar len;
MT_Vector3 dir;
std::cout << "Invalid direction" << std::endl;
return NULL;
}
- m_refDirection = dir/len;
+ m_refDirVector = dir/len;
+ m_refDirection[0] = x/len;
+ m_refDirection[1] = y/len;
+ m_refDirection[2] = z/len;
Py_RETURN_NONE;
}
"getDirection()\n"
"\tReturns the reference direction of the orientation constraint as a 3-tuple.\n";
PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){
+ ShowDeprecationWarning("getDirection()", "the direction property");
PyObject *retVal = PyList_New(3);
PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
PyObject* KX_ConstraintActuator::PySetOption(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setOption()", "the option property");
int option;
if(!PyArg_ParseTuple(args, "i", &option)) {
return NULL;
"getOption()\n"
"\tReturns the option parameter.\n";
PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){
+ ShowDeprecationWarning("getOption()", "the option property");
return PyInt_FromLong(m_option);
}
PyObject* KX_ConstraintActuator::PySetTime(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setTime()", "the time property");
int t;
if(!PyArg_ParseTuple(args, "i", &t)) {
return NULL;
"getTime()\n"
"\tReturns the time parameter.\n";
PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){
+ ShowDeprecationWarning("getTime()", "the time property");
return PyInt_FromLong(m_activeTime);
}
PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setProperty()", "the 'property' property");
char *property;
if (!PyArg_ParseTuple(args, "s", &property)) {
return NULL;
}
if (property == NULL) {
- m_property[0] = 0;
+ m_property = "";
} else {
- strncpy(m_property, property, sizeof(m_property));
- m_property[sizeof(m_property)-1] = 0;
+ m_property = property;
}
Py_RETURN_NONE;
"getProperty()\n"
"\tReturns the property parameter.\n";
PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){
- return PyString_FromString(m_property);
+ ShowDeprecationWarning("getProperty()", "the 'property' property");
+ return PyString_FromString(m_property.Ptr());
}
/* 4. setDistance */
PyObject* KX_ConstraintActuator::PySetMin(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property");
float minArg;
if(!PyArg_ParseTuple(args, "f", &minArg)) {
return NULL;
"\tReturns the lower value of the interval to which the value\n"
"\tis clipped.\n";
PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) {
+ ShowDeprecationWarning("getMin() or getDistance()", "the min or distance property");
return PyFloat_FromDouble(m_minimumBound);
}
PyObject* KX_ConstraintActuator::PySetMax(PyObject* self,
PyObject* args,
PyObject* kwds){
+ ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property");
float maxArg;
if(!PyArg_ParseTuple(args, "f", &maxArg)) {
return NULL;
"\tReturns the upper value of the interval to which the value\n"
"\tis clipped.\n";
PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) {
+ ShowDeprecationWarning("getMax() or getRayLength()", "the max or rayLength property");
return PyFloat_FromDouble(m_maximumBound);
}
PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self,
PyObject* args,
PyObject* kwds) {
+ ShowDeprecationWarning("setLimit()", "the limit property");
int locrotArg;
if(!PyArg_ParseTuple(args, "i", &locrotArg)) {
return NULL;
"getLimit()\n"
"\tReturns the type of constraint.\n";
PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) {
+ ShowDeprecationWarning("setLimit()", "the limit property");
return PyInt_FromLong(m_locrot);
}
class KX_ConstraintActuator(SCA_IActuator):
"""
A constraint actuator limits the position, rotation, distance or orientation of an object.
+
+ Properties:
+
+ @ivar damp: time constant of the constraint expressed in frame (not use by Force field constraint)
+ @type damp: integer
+
+ @ivar rotDamp: time constant for the rotation expressed in frame (only for the distance constraint)
+ 0 = use damp for rotation as well
+ @type rotDamp: integer
+
+ @ivar direction: the reference direction in world coordinate for the orientation constraint
+ @type direction: 3-tuple of float: [x,y,z]
+
+ @ivar option: Binary combination of the following values:
+ Applicable to Distance constraint:
+ KX_ACT_CONSTRAINT_NORMAL ( 64) : Activate alignment to surface
+ KX_ACT_CONSTRAINT_DISTANCE ( 512) : Activate distance control
+ KX_ACT_CONSTRAINT_LOCAL (1024) : direction of the ray is along the local axis
+ Applicable to Force field constraint:
+ KX_ACT_CONSTRAINT_DOROTFH (2048) : Force field act on rotation as well
+ Applicable to both:
+ KX_ACT_CONSTRAINT_MATERIAL ( 128) : Detect material rather than property
+ KX_ACT_CONSTRAINT_PERMANENT ( 256) : No deactivation if ray does not hit target
+ @type option: integer
+
+ @ivar time: activation time of the actuator. The actuator disables itself after this many frame.
+ If set to 0, the actuator is not limited in time.
+ @type time: integer
+
+ @ivar property: the name of the property or material for the ray detection of the distance constraint.
+ @type property: string
+
+ @ivar min: The lower bound of the constraint
+ For the rotation and orientation constraint, it represents radiant
+ @type min: float
+
+ @ivar distance: the target distance of the distance constraint
+ @type distance: float
+
+ @ivar max: the upper bound of the constraint.
+ For rotation and orientation constraints, it represents radiant.
+ @type max: float
+
+ @ivar rayLength: the length of the ray of the distance constraint.
+ @type rayLength: float
+
+ @ivar limit: type of constraint, use one of the following constant:
+ KX_ACT_CONSTRAINT_LOCX ( 1) : limit X coord
+ KX_ACT_CONSTRAINT_LOCY ( 2) : limit Y coord
+ KX_ACT_CONSTRAINT_LOCZ ( 3) : limit Z coord
+ KX_ACT_CONSTRAINT_ROTX ( 4) : limit X rotation
+ KX_ACT_CONSTRAINT_ROTY ( 5) : limit Y rotation
+ KX_ACT_CONSTRAINT_ROTZ ( 6) : limit Z rotation
+ KX_ACT_CONSTRAINT_DIRPX ( 7) : set distance along positive X axis
+ KX_ACT_CONSTRAINT_DIRPY ( 8) : set distance along positive Y axis
+ KX_ACT_CONSTRAINT_DIRPZ ( 9) : set distance along positive Z axis
+ KX_ACT_CONSTRAINT_DIRNX (10) : set distance along negative X axis
+ KX_ACT_CONSTRAINT_DIRNY (11) : set distance along negative Y axis
+ KX_ACT_CONSTRAINT_DIRNZ (12) : set distance along negative Z axis
+ KX_ACT_CONSTRAINT_ORIX (13) : set orientation of X axis
+ KX_ACT_CONSTRAINT_ORIY (14) : set orientation of Y axis
+ KX_ACT_CONSTRAINT_ORIZ (15) : set orientation of Z axis
+ KX_ACT_CONSTRAINT_FHPX (16) : set force field along positive X axis
+ KX_ACT_CONSTRAINT_FHPY (17) : set force field along positive Y axis
+ KX_ACT_CONSTRAINT_FHPZ (18) : set force field along positive Z axis
+ KX_ACT_CONSTRAINT_FHNX (19) : set force field along negative X axis
+ KX_ACT_CONSTRAINT_FHNY (20) : set force field along negative Y axis
+ KX_ACT_CONSTRAINT_FHNZ (21) : set force field along negative Z axis
+ @type limit: integer
"""
def setDamp(time):
"""