get/set Angular velocity for KX_GameObjects python api and for the AddObject actuator.
[blender.git] / source / gameengine / Ketsji / KX_SCA_AddObjectActuator.cpp
index 7e0d0df1ab7bd45795bc22d6dfd83be8cef5c02d..a7330b9a20ac1d0fd798f5346e90b8217b8397e2 100644 (file)
@@ -52,14 +52,20 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
                                                                                                   int time,
                                                                                                   SCA_IScene* scene,
                                                                                                   const MT_Vector3& linvel,
                                                                                                   int time,
                                                                                                   SCA_IScene* scene,
                                                                                                   const MT_Vector3& linvel,
-                                                                                                  bool local,
+                                                                                                  bool linv_local,
+                                                                                                  const MT_Vector3& angvel,
+                                                                                                  bool angv_local,
                                                                                                   PyTypeObject* T)
        : 
        SCA_IActuator(gameobj, T),
        m_OriginalObject(original),
        m_scene(scene),
                                                                                                   PyTypeObject* T)
        : 
        SCA_IActuator(gameobj, T),
        m_OriginalObject(original),
        m_scene(scene),
+       
        m_linear_velocity(linvel),
        m_linear_velocity(linvel),
-       m_localFlag(local)
+       m_localLinvFlag(linv_local),
+       
+       m_angular_velocity(angvel),
+       m_localAngvFlag(angv_local)
 {
        if (m_OriginalObject)
                m_OriginalObject->RegisterActuator(this);
 {
        if (m_OriginalObject)
                m_OriginalObject->RegisterActuator(this);
@@ -181,13 +187,15 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = {
 };
 PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
   {"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, SetObject_doc},
 };
 PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
   {"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, SetObject_doc},
-  {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_VARARGS, SetTime_doc},
+  {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, SetTime_doc},
   {"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
   {"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
-  {"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_VARARGS, GetTime_doc},
-  {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_VARARGS, GetLinearVelocity_doc},
+  {"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, GetTime_doc},
+  {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, GetLinearVelocity_doc},
   {"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, SetLinearVelocity_doc},
   {"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, SetLinearVelocity_doc},
-  {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_VARARGS,"getLastCreatedObject() : get the object handle to the last created object\n"},
-  {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_VARARGS,"instantAddObject() : immediately add object without delay\n"},
+  {"getAngularVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetAngularVelocity, METH_NOARGS, GetAngularVelocity_doc},
+  {"setAngularVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetAngularVelocity, METH_VARARGS, SetAngularVelocity_doc},
+  {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"},
+  {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"},
   
   {NULL,NULL} //Sentinel
 };
   
   {NULL,NULL} //Sentinel
 };
@@ -231,19 +239,18 @@ char KX_SCA_AddObjectActuator::SetTime_doc[] =
 "\tIf the duration is negative, it is set to 0.\n";
 
 
 "\tIf the duration is negative, it is set to 0.\n";
 
 
-PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self,
-                                                                                         PyObject* args,
-                                                                                         PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value)
 {
 {
-       int deltatime;
-       
-       if (!PyArg_ParseTuple(args, "i", &deltatime))
+       int deltatime = PyInt_AsLong(value);
+       if (deltatime==-1 && PyErr_Occurred()) {
+               PyErr_SetString(PyExc_TypeError, "expected an int");
                return NULL;
                return NULL;
+       }
        
        m_timeProp = deltatime;
        if (m_timeProp < 0) m_timeProp = 0;
        
        
        m_timeProp = deltatime;
        if (m_timeProp < 0) m_timeProp = 0;
        
-       Py_Return;
+       Py_RETURN_NONE;
 }
 
 
 }
 
 
@@ -254,9 +261,7 @@ char KX_SCA_AddObjectActuator::GetTime_doc[] =
 "\tReturns the lifetime of the object that will be added.\n";
 
 
 "\tReturns the lifetime of the object that will be added.\n";
 
 
-PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self,
-                                                                                         PyObject* args,
-                                                                                         PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self)
 {
        return PyInt_FromLong(m_timeProp);
 }
 {
        return PyInt_FromLong(m_timeProp);
 }
@@ -290,17 +295,13 @@ char KX_SCA_AddObjectActuator::GetLinearVelocity_doc[] =
 "\tReturns the linear velocity that will be assigned to \n"
 "\tthe created object.\n";
 
 "\tReturns the linear velocity that will be assigned to \n"
 "\tthe created object.\n";
 
-
-
-PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self,
-                                                                                                               PyObject* args,
-                                                                                                               PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self)
 {
        PyObject *retVal = PyList_New(3);
 
 {
        PyObject *retVal = PyList_New(3);
 
-       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0]));
-       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_linear_velocity[1]));
-       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_linear_velocity[2]));
+       PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0]));
+       PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(m_linear_velocity[1]));
+       PyList_SET_ITEM(retVal, 2, PyFloat_FromDouble(m_linear_velocity[2]));
        
        return retVal;
 }
        
        return retVal;
 }
@@ -313,12 +314,10 @@ char KX_SCA_AddObjectActuator::SetLinearVelocity_doc[] =
 "\t- vx: float\n"
 "\t- vy: float\n"
 "\t- vz: float\n"
 "\t- vx: float\n"
 "\t- vy: float\n"
 "\t- vz: float\n"
+"\t- local: bool\n"
 "\tAssign this velocity to the created object. \n";
 
 "\tAssign this velocity to the created object. \n";
 
-
-PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self,
-                                                                                                               PyObject* args,
-                                                                                                               PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* args)
 {
        
        float vecArg[3];
 {
        
        float vecArg[3];
@@ -326,7 +325,46 @@ PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self,
                return NULL;
 
        m_linear_velocity.setValue(vecArg);
                return NULL;
 
        m_linear_velocity.setValue(vecArg);
-       Py_Return;
+       Py_RETURN_NONE;
+}
+
+/* 7. getAngularVelocity */
+char KX_SCA_AddObjectActuator::GetAngularVelocity_doc[] = 
+"GetAngularVelocity()\n"
+"\tReturns the angular velocity that will be assigned to \n"
+"\tthe created object.\n";
+
+PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity(PyObject* self)
+{
+       PyObject *retVal = PyList_New(3);
+
+       PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0]));
+       PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(m_angular_velocity[1]));
+       PyList_SET_ITEM(retVal, 2, PyFloat_FromDouble(m_angular_velocity[2]));
+       
+       return retVal;
+}
+
+
+
+/* 8. setAngularVelocity                                                 */
+char KX_SCA_AddObjectActuator::SetAngularVelocity_doc[] = 
+"setAngularVelocity(vx, vy, vz)\n"
+"\t- vx: float\n"
+"\t- vy: float\n"
+"\t- vz: float\n"
+"\t- local: bool\n"
+"\tAssign this angular velocity to the created object. \n";
+
+PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* args)
+{
+       
+       float vecArg[3];
+       if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2]))
+               return NULL;
+
+       m_angular_velocity.setValue(vecArg);
+       Py_RETURN_NONE;
 }
 
 void   KX_SCA_AddObjectActuator::InstantAddObject()
 }
 
 void   KX_SCA_AddObjectActuator::InstantAddObject()
@@ -337,8 +375,9 @@ void        KX_SCA_AddObjectActuator::InstantAddObject()
                // Now it needs to be added to the current scene.
                SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp );
                KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica);
                // Now it needs to be added to the current scene.
                SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp );
                KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica);
-               game_obj->setLinearVelocity(m_linear_velocity,m_localFlag);
-               game_obj->ResolveCombinedVelocities(m_linear_velocity, MT_Vector3(0., 0., 0.), m_localFlag, false);
+               game_obj->setLinearVelocity(m_linear_velocity,m_localLinvFlag);
+               game_obj->setAngularVelocity(m_angular_velocity,m_localAngvFlag);
+               game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag);
 
                // keep a copy of the last object, to allow python scripters to change it
                if (m_lastCreatedObject)
 
                // keep a copy of the last object, to allow python scripters to change it
                if (m_lastCreatedObject)
@@ -355,13 +394,11 @@ void      KX_SCA_AddObjectActuator::InstantAddObject()
        }
 }
 
        }
 }
 
-PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* self,
-                                                                                                                  PyObject* args,
-                                                                                                                  PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* self)
 {
        InstantAddObject();
 
 {
        InstantAddObject();
 
-       Py_Return;
+       Py_RETURN_NONE;
 }
 
 
 }
 
 
@@ -372,9 +409,7 @@ char KX_SCA_AddObjectActuator::GetLastCreatedObject_doc[] =
 "\tReturn the last created object. \n";
 
 
 "\tReturn the last created object. \n";
 
 
-PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self,
-                                                                                                                  PyObject* args,
-                                                                                                                  PyObject* kwds)
+PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self)
 {
        SCA_IObject* result = this->GetLastCreatedObject();
        
 {
        SCA_IObject* result = this->GetLastCreatedObject();
        
@@ -386,5 +421,5 @@ PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self,
                return result;
        }
        // don't return NULL to python anymore, it gives trouble in the scripts
                return result;
        }
        // don't return NULL to python anymore, it gives trouble in the scripts
-       Py_Return;
+       Py_RETURN_NONE;
 }
 }