Blender  V2.59
KX_ConstraintWrapper.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_ConstraintWrapper.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 #include "KX_ConstraintWrapper.h"
00037 #include "PHY_IPhysicsEnvironment.h"
00038 
00039 KX_ConstraintWrapper::KX_ConstraintWrapper(
00040                                                 PHY_ConstraintType ctype,
00041                                                 int constraintId,
00042                                                 PHY_IPhysicsEnvironment* physenv) :
00043                 PyObjectPlus(),
00044                 m_constraintId(constraintId),
00045                 m_constraintType(ctype),
00046                 m_physenv(physenv)
00047 {
00048 }
00049 KX_ConstraintWrapper::~KX_ConstraintWrapper()
00050 {
00051 }
00052 
00053 #ifdef WITH_PYTHON
00054 
00055 PyObject* KX_ConstraintWrapper::PyGetConstraintId()
00056 {
00057         return PyLong_FromSsize_t(m_constraintId);
00058 }
00059 
00060 
00061 PyObject* KX_ConstraintWrapper::PyGetParam(PyObject* args, PyObject* kwds)
00062 {
00063         int dof;
00064         float value;
00065         
00066         if (!PyArg_ParseTuple(args,"i:getParam",&dof))
00067                 return NULL;
00068         
00069         value = m_physenv->getConstraintParam(m_constraintId,dof);
00070         return PyFloat_FromDouble(value);
00071         
00072 }
00073 
00074 PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds)
00075 {
00076         int dof;
00077         float minLimit,maxLimit;
00078         
00079         if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit))
00080                 return NULL;
00081         
00082         m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
00083         Py_RETURN_NONE;
00084 }
00085 
00086 
00087 //python specific stuff
00088 PyTypeObject KX_ConstraintWrapper::Type = {
00089         PyVarObject_HEAD_INIT(NULL, 0)
00090         "KX_ConstraintWrapper",
00091         sizeof(PyObjectPlus_Proxy),
00092         0,
00093         py_base_dealloc,
00094         0,
00095         0,
00096         0,
00097         0,
00098         py_base_repr,
00099         0,0,0,0,0,0,0,0,0,
00100         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00101         0,0,0,0,0,0,0,
00102         Methods,
00103         0,
00104         0,
00105         &PyObjectPlus::Type,
00106         0,0,0,0,0,0,
00107         py_base_new
00108 };
00109 
00110 PyMethodDef KX_ConstraintWrapper::Methods[] = {
00111         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS},
00112         {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
00113         {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS},
00114         {NULL,NULL} //Sentinel
00115 };
00116 
00117 PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
00118         KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId),
00119         { NULL }        //Sentinel
00120 };
00121 
00122 PyObject* KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
00123 {
00124         KX_ConstraintWrapper* self= static_cast<KX_ConstraintWrapper*>(self_v);
00125         return self->PyGetConstraintId();
00126 }
00127 
00128 #endif // WITH_PYTHON