Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Ketsji / KX_ConstraintActuator.cpp
index bd03dea..ea0b9f4 100644 (file)
@@ -36,6 +36,7 @@
 #include "MT_Matrix3x3.h"
 #include "KX_GameObject.h"
 #include "KX_RayCast.h"
+#include "KX_PythonInit.h" // KX_GetActiveScene
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -54,9 +55,8 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
                                                                                         int locrotxyz,
                                                                                         int time,
                                                                                         int option,
-                                                                                        char *property,
-                                                                                        PyTypeObject* T) : 
-       SCA_IActuator(gameobj, T),
+                                                                                        char *property) :
+       SCA_IActuator(gameobj, KX_ACT_CONSTRAINT),
        m_refDirVector(refDir),
        m_currentTime(0)
 {
@@ -328,7 +328,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame)
                        }
                        {
                                MT_Point3 topoint = position + (m_maximumBound) * direction;
-                               PHY_IPhysicsEnvironment* pe = obj->GetPhysicsEnvironment();
+                               PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
                                KX_IPhysicsController *spc = obj->GetPhysicsController();
 
                                if (!pe) {
@@ -441,7 +441,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame)
                        }
                        normal.normalize();
                        {
-                               PHY_IPhysicsEnvironment* pe = obj->GetPhysicsEnvironment();
+                               PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
                                KX_IPhysicsController *spc = obj->GetPhysicsController();
 
                                if (!pe) {
@@ -565,13 +565,7 @@ bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE
 
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject KX_ConstraintActuator::Type = {
-#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
-#else
-       /* python 2.5 and below */
-       PyObject_HEAD_INIT( NULL )  /* required py macro */
-       0,                          /* ob_size */
-#endif
        "KX_ConstraintActuator",
        sizeof(PyObjectPlus_Proxy),
        0,
@@ -581,46 +575,18 @@ PyTypeObject KX_ConstraintActuator::Type = {
        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[] = {
-       &KX_ConstraintActuator::Type,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
        &SCA_IActuator::Type,
-       &SCA_ILogicBrick::Type,
-       &CValue::Type,
-       NULL
+       0,0,0,0,0,0,
+       py_base_new
 };
 
 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},
-       {"getRotDamp", (PyCFunction) KX_ConstraintActuator::sPyGetRotDamp, METH_NOARGS, (PY_METHODCHAR)GetRotDamp_doc},
-       {"setDirection", (PyCFunction) KX_ConstraintActuator::sPySetDirection, METH_VARARGS, (PY_METHODCHAR)SetDirection_doc},
-       {"getDirection", (PyCFunction) KX_ConstraintActuator::sPyGetDirection, METH_NOARGS, (PY_METHODCHAR)GetDirection_doc},
-       {"setOption", (PyCFunction) KX_ConstraintActuator::sPySetOption, METH_VARARGS, (PY_METHODCHAR)SetOption_doc},
-       {"getOption", (PyCFunction) KX_ConstraintActuator::sPyGetOption, METH_NOARGS, (PY_METHODCHAR)GetOption_doc},
-       {"setTime", (PyCFunction) KX_ConstraintActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc},
-       {"getTime", (PyCFunction) KX_ConstraintActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc},
-       {"setProperty", (PyCFunction) KX_ConstraintActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
-       {"getProperty", (PyCFunction) KX_ConstraintActuator::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
-       {"setMin", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetMin_doc},
-       {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetMin_doc},
-       {"setDistance", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetDistance_doc},
-       {"getDistance", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetDistance_doc},
-       {"setMax", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetMax_doc},
-       {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, (PY_METHODCHAR)GetMax_doc},
-       {"setRayLength", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetRayLength_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
 };
 
@@ -639,21 +605,6 @@ PyAttributeDef KX_ConstraintActuator::Attributes[] = {
        { NULL }        //Sentinel
 };
 
-PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) 
-{
-       py_getattro_up(SCA_IActuator);
-}
-
-PyObject* KX_ConstraintActuator::py_getattro_dict() {
-       py_getattro_dict_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);
@@ -667,318 +618,4 @@ int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PY
        return 0;       
 }
 
-/* 2. setDamp                                                                */
-const char KX_ConstraintActuator::SetDamp_doc[] = 
-"setDamp(duration)\n"
-"\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* args) {
-       ShowDeprecationWarning("setDamp()", "the damp property");
-       int dampArg;
-       if(!PyArg_ParseTuple(args, "i:setDamp", &dampArg)) {
-               return NULL;            
-       }
-       
-       m_posDampTime = dampArg;
-       if (m_posDampTime < 0) m_posDampTime = 0;
-
-       Py_RETURN_NONE;
-}
-/* 3. getDamp                                                                */
-const char KX_ConstraintActuator::GetDamp_doc[] = 
-"getDamp()\n"
-"\tReturns the damping parameter.\n";
-PyObject* KX_ConstraintActuator::PyGetDamp(){
-       ShowDeprecationWarning("getDamp()", "the damp property");
-       return PyInt_FromLong(m_posDampTime);
-}
-
-/* 2. setRotDamp                                                                */
-const char KX_ConstraintActuator::SetRotDamp_doc[] = 
-"setRotDamp(duration)\n"
-"\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* args) {
-       ShowDeprecationWarning("setRotDamp()", "the rotDamp property");
-       int dampArg;
-       if(!PyArg_ParseTuple(args, "i:setRotDamp", &dampArg)) {
-               return NULL;            
-       }
-       
-       m_rotDampTime = dampArg;
-       if (m_rotDampTime < 0) m_rotDampTime = 0;
-
-       Py_RETURN_NONE;
-}
-/* 3. getRotDamp                                                                */
-const char KX_ConstraintActuator::GetRotDamp_doc[] = 
-"getRotDamp()\n"
-"\tReturns the damping time for application of the constraint.\n";
-PyObject* KX_ConstraintActuator::PyGetRotDamp(){
-       ShowDeprecationWarning("getRotDamp()", "the rotDamp property");
-       return PyInt_FromLong(m_rotDampTime);
-}
-
-/* 2. setDirection                                                                */
-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* args) {
-       ShowDeprecationWarning("setDirection()", "the direction property");
-       float x, y, z;
-       MT_Scalar len;
-       MT_Vector3 dir;
-
-       if(!PyArg_ParseTuple(args, "(fff):setDirection", &x, &y, &z)) {
-               return NULL;            
-       }
-       dir[0] = x;
-       dir[1] = y;
-       dir[2] = z;
-       len = dir.length();
-       if (MT_fuzzyZero(len)) {
-               std::cout << "Invalid direction" << std::endl;
-               return NULL;
-       }
-       m_refDirVector = dir/len;
-       m_refDirection[0] = x/len;
-       m_refDirection[1] = y/len;
-       m_refDirection[2] = z/len;
-
-       Py_RETURN_NONE;
-}
-/* 3. getDirection                                                                */
-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(){
-       ShowDeprecationWarning("getDirection()", "the direction property");
-       PyObject *retVal = PyList_New(3);
-
-       PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
-       PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(m_refDirection[1]));
-       PyList_SET_ITEM(retVal, 2, PyFloat_FromDouble(m_refDirection[2]));
-       return retVal;
-}
-
-/* 2. setOption                                                                */
-const char KX_ConstraintActuator::SetOption_doc[] = 
-"setOption(option)\n"
-"\t- option: integer\n"
-"\tSets several options of the distance  constraint.\n"
-"\tBinary combination of the following values:\n"
-"\t\t 64 : Activate alignment to surface\n"
-"\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* args) {
-       ShowDeprecationWarning("setOption()", "the option property");
-       int option;
-       if(!PyArg_ParseTuple(args, "i:setOption", &option)) {
-               return NULL;            
-       }
-       
-       m_option = option;
-
-       Py_RETURN_NONE;
-}
-/* 3. getOption                                                              */
-const char KX_ConstraintActuator::GetOption_doc[] = 
-"getOption()\n"
-"\tReturns the option parameter.\n";
-PyObject* KX_ConstraintActuator::PyGetOption(){
-       ShowDeprecationWarning("getOption()", "the option property");
-       return PyInt_FromLong(m_option);
-}
-
-/* 2. setTime                                                                */
-const char KX_ConstraintActuator::SetTime_doc[] = 
-"setTime(duration)\n"
-"\t- duration: integer\n"
-"\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* args) {
-       ShowDeprecationWarning("setTime()", "the time property");
-       int t;
-       if(!PyArg_ParseTuple(args, "i:setTime", &t)) {
-               return NULL;            
-       }
-       
-       if (t < 0)
-               t = 0;
-       m_activeTime = t;
-
-       Py_RETURN_NONE;
-}
-/* 3. getTime                                                                */
-const char KX_ConstraintActuator::GetTime_doc[] = 
-"getTime()\n"
-"\tReturns the time parameter.\n";
-PyObject* KX_ConstraintActuator::PyGetTime(){
-       ShowDeprecationWarning("getTime()", "the time property");
-       return PyInt_FromLong(m_activeTime);
-}
-
-/* 2. setProperty                                                                */
-const char KX_ConstraintActuator::SetProperty_doc[] = 
-"setProperty(property)\n"
-"\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* args) {
-       ShowDeprecationWarning("setProperty()", "the 'property' property");
-       char *property;
-       if (!PyArg_ParseTuple(args, "s:setProperty", &property)) {
-               return NULL;
-       }
-       if (property == NULL) {
-               m_property = "";
-       } else {
-               m_property = property;
-       }
-
-       Py_RETURN_NONE;
-}
-/* 3. getProperty                                                                */
-const char KX_ConstraintActuator::GetProperty_doc[] = 
-"getProperty()\n"
-"\tReturns the property parameter.\n";
-PyObject* KX_ConstraintActuator::PyGetProperty(){
-       ShowDeprecationWarning("getProperty()", "the 'property' property");
-       return PyString_FromString(m_property.Ptr());
-}
-
-/* 4. setDistance                                                                 */
-const char KX_ConstraintActuator::SetDistance_doc[] = 
-"setDistance(distance)\n"
-"\t- distance: float\n"
-"\tSets the target distance in distance constraint\n";
-/* 4. setMin                                                                 */
-const char KX_ConstraintActuator::SetMin_doc[] = 
-"setMin(lower_bound)\n"
-"\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* args) {
-       ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property");
-       float minArg;
-       if(!PyArg_ParseTuple(args, "f:setMin", &minArg)) {
-               return NULL;            
-       }
-
-       switch (m_locrot) {
-       default:
-               m_minimumBound = minArg;
-               break;
-       case KX_ACT_CONSTRAINT_ROTX:
-       case KX_ACT_CONSTRAINT_ROTY:
-       case KX_ACT_CONSTRAINT_ROTZ:
-               m_minimumBound = MT_radians(minArg);
-               break;
-       }
-
-       Py_RETURN_NONE;
-}
-/* 5. getDistance                                                                 */
-const char KX_ConstraintActuator::GetDistance_doc[] = 
-"getDistance()\n"
-"\tReturns the distance parameter \n";
-/* 5. getMin                                                                 */
-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() {
-       ShowDeprecationWarning("getMin() or getDistance()", "the min or distance property");
-       return PyFloat_FromDouble(m_minimumBound);
-}
-
-/* 6. setRayLength                                                                 */
-const char KX_ConstraintActuator::SetRayLength_doc[] = 
-"setRayLength(length)\n"
-"\t- length: float\n"
-"\tSets the maximum ray length of the distance constraint\n";
-/* 6. setMax                                                                 */
-const char KX_ConstraintActuator::SetMax_doc[] = 
-"setMax(upper_bound)\n"
-"\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* args){
-       ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property");
-       float maxArg;
-       if(!PyArg_ParseTuple(args, "f:setMax", &maxArg)) {
-               return NULL;            
-       }
-
-       switch (m_locrot) {
-       default:
-               m_maximumBound = maxArg;
-               break;
-       case KX_ACT_CONSTRAINT_ROTX:
-       case KX_ACT_CONSTRAINT_ROTY:
-       case KX_ACT_CONSTRAINT_ROTZ:
-               m_maximumBound = MT_radians(maxArg);
-               break;
-       }
-
-       Py_RETURN_NONE;
-}
-/* 7. getRayLength                                                                 */
-const char KX_ConstraintActuator::GetRayLength_doc[] = 
-"getRayLength()\n"
-"\tReturns the length of the ray\n";
-/* 7. getMax                                                                 */
-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() {
-       ShowDeprecationWarning("getMax() or getRayLength()", "the max or rayLength property");
-       return PyFloat_FromDouble(m_maximumBound);
-}
-
-
-/* This setter/getter probably for the constraint type                       */
-/* 8. setLimit                                                               */
-const char KX_ConstraintActuator::SetLimit_doc[] = 
-"setLimit(type)\n"
-"\t- type: integer\n"
-"\t  1  : LocX\n"
-"\t  2  : LocY\n"
-"\t  3  : LocZ\n"
-"\t  7  : Distance along +X axis\n"
-"\t  8  : Distance along +Y axis\n"
-"\t  9  : Distance along +Z axis\n"
-"\t  10 : Distance along -X axis\n"
-"\t  11 : Distance along -Y axis\n"
-"\t  12 : Distance along -Z axis\n"
-"\t  13 : Align X axis\n"
-"\t  14 : Align Y axis\n"
-"\t  15 : Align Z axis\n"
-"\tSets the type of constraint.\n";
-PyObject* KX_ConstraintActuator::PySetLimit(PyObject* args) {
-       ShowDeprecationWarning("setLimit()", "the limit property");
-       int locrotArg;
-       if(!PyArg_ParseTuple(args, "i:setLimit", &locrotArg)) {
-               return NULL;            
-       }
-       
-       if (IsValidMode((KX_CONSTRAINTTYPE)locrotArg)) m_locrot = locrotArg;
-
-       Py_RETURN_NONE;
-}
-/* 9. getLimit                                                               */
-const char KX_ConstraintActuator::GetLimit_doc[] = 
-"getLimit()\n"
-"\tReturns the type of constraint.\n";
-PyObject* KX_ConstraintActuator::PyGetLimit() {
-       ShowDeprecationWarning("setLimit()", "the limit property");
-       return PyInt_FromLong(m_locrot);
-}
-
 /* eof */