diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_ConstraintActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 198 |
1 files changed, 119 insertions, 79 deletions
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index fba9544d702..c2b4db2de8e 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -57,19 +57,21 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, 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, */ @@ -80,13 +82,16 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, 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); @@ -116,7 +121,7 @@ bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* resu bool bFound = false; - if (m_property[0] == 0) + if (m_property.IsEmpty()) { bFound = true; } @@ -126,7 +131,7 @@ bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* resu { 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 @@ -209,7 +214,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) 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; @@ -218,27 +223,27 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) // 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; @@ -470,7 +475,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) // 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) { @@ -483,7 +488,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) 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) { @@ -560,22 +565,22 @@ bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_ConstraintActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_ConstraintActuator", - sizeof(KX_ConstraintActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, 0, 0, 0, - 0 + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_ConstraintActuator::Parents[] = { @@ -587,6 +592,7 @@ PyParentObject KX_ConstraintActuator::Parents[] = { }; 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}, @@ -609,15 +615,47 @@ PyMethodDef KX_ConstraintActuator::Methods[] = { {"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",-FLT_MAX,FLT_MAX,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",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound), + KX_PYATTRIBUTE_FLOAT_RW("distance",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound), + KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,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::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); +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, "actuator.direction = vec: KX_ConstraintActuator, invalid direction"); + return 1; + } + act->m_refDirVector = dir/len; + return 0; } /* 2. setDamp */ @@ -626,11 +664,10 @@ const char KX_ConstraintActuator::SetDamp_doc[] = "\t- duration: integer\n" "\tSets the time constant of the orientation and distance constraint.\n" "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetDamp(PyObject* args) { + ShowDeprecationWarning("setDamp()", "the damp property"); int dampArg; - if(!PyArg_ParseTuple(args, "i", &dampArg)) { + if(!PyArg_ParseTuple(args, "i:setDamp", &dampArg)) { return NULL; } @@ -643,7 +680,8 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, const char KX_ConstraintActuator::GetDamp_doc[] = "getDamp()\n" "\tReturns the damping parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetDamp(){ + ShowDeprecationWarning("getDamp()", "the damp property"); return PyInt_FromLong(m_posDampTime); } @@ -653,11 +691,10 @@ const char KX_ConstraintActuator::SetRotDamp_doc[] = "\t- duration: integer\n" "\tSets the time constant of the orientation constraint.\n" "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* args) { + ShowDeprecationWarning("setRotDamp()", "the rotDamp property"); int dampArg; - if(!PyArg_ParseTuple(args, "i", &dampArg)) { + if(!PyArg_ParseTuple(args, "i:setRotDamp", &dampArg)) { return NULL; } @@ -670,7 +707,8 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, const char KX_ConstraintActuator::GetRotDamp_doc[] = "getRotDamp()\n" "\tReturns the damping time for application of the constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetRotDamp(){ + ShowDeprecationWarning("getRotDamp()", "the rotDamp property"); return PyInt_FromLong(m_rotDampTime); } @@ -679,14 +717,13 @@ const char KX_ConstraintActuator::SetDirection_doc[] = "setDirection(vector)\n" "\t- vector: 3-tuple\n" "\tSets the reference direction in world coordinate for the orientation constraint.\n"; -PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetDirection(PyObject* args) { + ShowDeprecationWarning("setDirection()", "the direction property"); float x, y, z; MT_Scalar len; MT_Vector3 dir; - if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) { + if(!PyArg_ParseTuple(args, "(fff):setDirection", &x, &y, &z)) { return NULL; } dir[0] = x; @@ -697,7 +734,10 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, 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; } @@ -705,7 +745,8 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, const char KX_ConstraintActuator::GetDirection_doc[] = "getDirection()\n" "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n"; -PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetDirection(){ + ShowDeprecationWarning("getDirection()", "the direction property"); PyObject *retVal = PyList_New(3); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0])); @@ -724,11 +765,10 @@ const char KX_ConstraintActuator::SetOption_doc[] = "\t\t128 : Detect material rather than property\n" "\t\t256 : No deactivation if ray does not hit target\n" "\t\t512 : Activate distance control\n"; -PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetOption(PyObject* args) { + ShowDeprecationWarning("setOption()", "the option property"); int option; - if(!PyArg_ParseTuple(args, "i", &option)) { + if(!PyArg_ParseTuple(args, "i:setOption", &option)) { return NULL; } @@ -740,7 +780,8 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, const char KX_ConstraintActuator::GetOption_doc[] = "getOption()\n" "\tReturns the option parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetOption(){ + ShowDeprecationWarning("getOption()", "the option property"); return PyInt_FromLong(m_option); } @@ -751,11 +792,10 @@ const char KX_ConstraintActuator::SetTime_doc[] = "\tSets the activation time of the actuator.\n" "\tThe actuator disables itself after this many frame.\n" "\tIf set to 0 or negative, the actuator is not limited in time.\n"; -PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetTime(PyObject* args) { + ShowDeprecationWarning("setTime()", "the time property"); int t; - if(!PyArg_ParseTuple(args, "i", &t)) { + if(!PyArg_ParseTuple(args, "i:setTime", &t)) { return NULL; } @@ -769,7 +809,8 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, const char KX_ConstraintActuator::GetTime_doc[] = "getTime()\n" "\tReturns the time parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetTime(){ + ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_activeTime); } @@ -779,18 +820,16 @@ const char KX_ConstraintActuator::SetProperty_doc[] = "\t- property: string\n" "\tSets the name of the property or material for the ray detection of the distance constraint.\n" "\tIf empty, the ray will detect any collisioning object.\n"; -PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetProperty(PyObject* args) { + ShowDeprecationWarning("setProperty()", "the 'property' property"); char *property; - if (!PyArg_ParseTuple(args, "s", &property)) { + if (!PyArg_ParseTuple(args, "s:setProperty", &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; @@ -799,8 +838,9 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, const char KX_ConstraintActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the property parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){ - return PyString_FromString(m_property); +PyObject* KX_ConstraintActuator::PyGetProperty(){ + ShowDeprecationWarning("getProperty()", "the 'property' property"); + return PyString_FromString(m_property.Ptr()); } /* 4. setDistance */ @@ -814,11 +854,10 @@ const char KX_ConstraintActuator::SetMin_doc[] = "\t- lower_bound: float\n" "\tSets the lower value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetMin(PyObject* args) { + ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property"); float minArg; - if(!PyArg_ParseTuple(args, "f", &minArg)) { + if(!PyArg_ParseTuple(args, "f:setMin", &minArg)) { return NULL; } @@ -844,7 +883,8 @@ const char KX_ConstraintActuator::GetMin_doc[] = "getMin()\n" "\tReturns the lower value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetMin() { + ShowDeprecationWarning("getMin() or getDistance()", "the min or distance property"); return PyFloat_FromDouble(m_minimumBound); } @@ -859,11 +899,10 @@ const char KX_ConstraintActuator::SetMax_doc[] = "\t- upper_bound: float\n" "\tSets the upper value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PySetMax(PyObject* args){ + ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property"); float maxArg; - if(!PyArg_ParseTuple(args, "f", &maxArg)) { + if(!PyArg_ParseTuple(args, "f:setMax", &maxArg)) { return NULL; } @@ -889,7 +928,8 @@ const char KX_ConstraintActuator::GetMax_doc[] = "getMax()\n" "\tReturns the upper value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetMax() { + ShowDeprecationWarning("getMax() or getRayLength()", "the max or rayLength property"); return PyFloat_FromDouble(m_maximumBound); } @@ -912,11 +952,10 @@ const char KX_ConstraintActuator::SetLimit_doc[] = "\t 14 : Align Y axis\n" "\t 15 : Align Z axis\n" "\tSets the type of constraint.\n"; -PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetLimit(PyObject* args) { + ShowDeprecationWarning("setLimit()", "the limit property"); int locrotArg; - if(!PyArg_ParseTuple(args, "i", &locrotArg)) { + if(!PyArg_ParseTuple(args, "i:setLimit", &locrotArg)) { return NULL; } @@ -928,7 +967,8 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, const char KX_ConstraintActuator::GetLimit_doc[] = "getLimit()\n" "\tReturns the type of constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetLimit() { + ShowDeprecationWarning("setLimit()", "the limit property"); return PyInt_FromLong(m_locrot); } |