Blender  V2.59
KX_PhysicsObjectWrapper.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_PhysicsObjectWrapper.cpp 35171 2011-02-25 13:35:59Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "PyObjectPlus.h"
00036 
00037 #include "KX_PhysicsObjectWrapper.h"
00038 #include "PHY_IPhysicsEnvironment.h"
00039 #include "PHY_IPhysicsController.h"
00040 
00041 KX_PhysicsObjectWrapper::KX_PhysicsObjectWrapper(
00042                                                 PHY_IPhysicsController* ctrl,
00043                                                 PHY_IPhysicsEnvironment* physenv) :
00044                                         PyObjectPlus(),
00045                                         m_ctrl(ctrl),
00046                                         m_physenv(physenv)
00047 {
00048 }
00049 
00050 KX_PhysicsObjectWrapper::~KX_PhysicsObjectWrapper()
00051 {
00052 }
00053 
00054 #ifdef WITH_PYTHON
00055 
00056 PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* args)
00057 {
00058         float x,y,z;
00059         if (PyArg_ParseTuple(args,"fff:setPosition",&x,&y,&z))
00060         {
00061                 m_ctrl->setPosition(x,y,z);
00062         }
00063         else {
00064                 return NULL;
00065         }
00066         Py_RETURN_NONE;
00067 }
00068 
00069 
00070 PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* args)
00071 {
00072         float x,y,z;
00073         int local;
00074         if (PyArg_ParseTuple(args,"fffi:setLinearVelocity",&x,&y,&z,&local))
00075         {
00076                 m_ctrl->SetLinearVelocity(x,y,z,local != 0);
00077         }
00078         else {
00079                 return NULL;
00080         }
00081         Py_RETURN_NONE;
00082 }
00083 
00084 PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* args)
00085 {
00086         float x,y,z;
00087         int local;
00088         if (PyArg_ParseTuple(args,"fffi:setAngularVelocity",&x,&y,&z,&local))
00089         {
00090                 m_ctrl->SetAngularVelocity(x,y,z,local != 0);
00091         }
00092         else {
00093                 return NULL;
00094         }
00095         Py_RETURN_NONE;
00096 }
00097 
00098 PyObject*       KX_PhysicsObjectWrapper::PySetActive(PyObject* args)
00099 {
00100         int active;
00101         if (PyArg_ParseTuple(args,"i:setActive",&active))
00102         {
00103                 m_ctrl->SetActive(active!=0);
00104         }
00105         else {
00106                 return NULL;
00107         }
00108         Py_RETURN_NONE;
00109 }
00110 
00111 
00112 PyAttributeDef KX_PhysicsObjectWrapper::Attributes[] = {
00113         { NULL }        //Sentinel
00114 };
00115 
00116 //python specific stuff
00117 PyTypeObject KX_PhysicsObjectWrapper::Type = {
00118         PyVarObject_HEAD_INIT(NULL, 0)
00119         "KX_PhysicsObjectWrapper",
00120         sizeof(PyObjectPlus_Proxy),
00121         0,
00122         py_base_dealloc,
00123         0,
00124         0,
00125         0,
00126         0,
00127         py_base_repr,
00128         0,0,0,0,0,0,0,0,0,
00129         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00130         0,0,0,0,0,0,0,
00131         Methods,
00132         0,
00133         0,
00134         &PyObjectPlus::Type,
00135         0,0,0,0,0,0,
00136         py_base_new
00137 };
00138 
00139 PyMethodDef KX_PhysicsObjectWrapper::Methods[] = {
00140         {"setPosition",(PyCFunction) KX_PhysicsObjectWrapper::sPySetPosition, METH_VARARGS},
00141         {"setLinearVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetLinearVelocity, METH_VARARGS},
00142         {"setAngularVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetAngularVelocity, METH_VARARGS},
00143         {"setActive",(PyCFunction) KX_PhysicsObjectWrapper::sPySetActive, METH_VARARGS},
00144         {NULL,NULL} //Sentinel
00145 };
00146 
00147 #endif