diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-04-10 03:10:12 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-04-10 03:10:12 +0400 |
commit | 5031fe982ea464ccb49ccfb4df857bf9dcb27c33 (patch) | |
tree | 9d4b29ff7542d6d0a4b1d8177c00c33876d1b0ff /source/gameengine/Ketsji/KX_ConstraintActuator.cpp | |
parent | ac45472a1707934573a12d629a21a81c3ed409ba (diff) |
BGE API cleanup: ConstraintActuator.
Diffstat (limited to 'source/gameengine/Ketsji/KX_ConstraintActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 107 |
1 files changed, 83 insertions, 24 deletions
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index feee851bb01..b41435e71a1 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -36,6 +36,7 @@ #include "MT_Matrix3x3.h" #include "KX_GameObject.h" #include "KX_RayCast.h" +#include "blendef.h" #ifdef HAVE_CONFIG_H #include <config.h> @@ -57,19 +58,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 +83,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 +122,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 +132,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 +215,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 +224,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 +476,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 +489,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) { @@ -587,6 +593,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,17 +616,49 @@ 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",-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" @@ -629,6 +668,7 @@ const char KX_ConstraintActuator::SetDamp_doc[] = 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; @@ -644,6 +684,7 @@ const char KX_ConstraintActuator::GetDamp_doc[] = "getDamp()\n" "\tReturns the damping parameter.\n"; PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){ + ShowDeprecationWarning("getDamp()", "the damp property"); return PyInt_FromLong(m_posDampTime); } @@ -656,6 +697,7 @@ const char KX_ConstraintActuator::SetRotDamp_doc[] = 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; @@ -671,6 +713,7 @@ const char KX_ConstraintActuator::GetRotDamp_doc[] = "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); } @@ -682,6 +725,7 @@ const char KX_ConstraintActuator::SetDirection_doc[] = 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; @@ -697,7 +741,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; } @@ -706,6 +753,7 @@ 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){ + ShowDeprecationWarning("getDirection()", "the direction property"); PyObject *retVal = PyList_New(3); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0])); @@ -727,6 +775,7 @@ const char KX_ConstraintActuator::SetOption_doc[] = 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; @@ -741,6 +790,7 @@ const char KX_ConstraintActuator::GetOption_doc[] = "getOption()\n" "\tReturns the option parameter.\n"; PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){ + ShowDeprecationWarning("getOption()", "the option property"); return PyInt_FromLong(m_option); } @@ -754,6 +804,7 @@ const char KX_ConstraintActuator::SetTime_doc[] = 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; @@ -770,6 +821,7 @@ const char KX_ConstraintActuator::GetTime_doc[] = "getTime()\n" "\tReturns the time parameter.\n"; PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){ + ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_activeTime); } @@ -782,15 +834,15 @@ const char KX_ConstraintActuator::SetProperty_doc[] = 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; @@ -800,7 +852,8 @@ const char KX_ConstraintActuator::GetProperty_doc[] = "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 */ @@ -817,6 +870,7 @@ const char KX_ConstraintActuator::SetMin_doc[] = 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; @@ -845,6 +899,7 @@ const char KX_ConstraintActuator::GetMin_doc[] = "\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); } @@ -862,6 +917,7 @@ const char KX_ConstraintActuator::SetMax_doc[] = 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; @@ -890,6 +946,7 @@ const char KX_ConstraintActuator::GetMax_doc[] = "\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); } @@ -915,6 +972,7 @@ const char KX_ConstraintActuator::SetLimit_doc[] = 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; @@ -929,6 +987,7 @@ const char KX_ConstraintActuator::GetLimit_doc[] = "getLimit()\n" "\tReturns the type of constraint.\n"; PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) { + ShowDeprecationWarning("setLimit()", "the limit property"); return PyInt_FromLong(m_locrot); } |