Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "PyObjectPlus.h" 00034 #include "KX_ConstraintWrapper.h" 00035 #include "PHY_IPhysicsEnvironment.h" 00036 00037 KX_ConstraintWrapper::KX_ConstraintWrapper( 00038 PHY_ConstraintType ctype, 00039 int constraintId, 00040 PHY_IPhysicsEnvironment* physenv) : 00041 PyObjectPlus(), 00042 m_constraintId(constraintId), 00043 m_constraintType(ctype), 00044 m_physenv(physenv) 00045 { 00046 } 00047 KX_ConstraintWrapper::~KX_ConstraintWrapper() 00048 { 00049 } 00050 00051 #ifdef WITH_PYTHON 00052 00053 PyObject* KX_ConstraintWrapper::PyGetConstraintId() 00054 { 00055 return PyLong_FromSsize_t(m_constraintId); 00056 } 00057 00058 00059 PyObject* KX_ConstraintWrapper::PyGetParam(PyObject* args, PyObject* kwds) 00060 { 00061 int dof; 00062 float value; 00063 00064 if (!PyArg_ParseTuple(args,"i:getParam",&dof)) 00065 return NULL; 00066 00067 value = m_physenv->getConstraintParam(m_constraintId,dof); 00068 return PyFloat_FromDouble(value); 00069 00070 } 00071 00072 PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds) 00073 { 00074 int dof; 00075 float minLimit,maxLimit; 00076 00077 if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit)) 00078 return NULL; 00079 00080 m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit); 00081 Py_RETURN_NONE; 00082 } 00083 00084 00085 //python specific stuff 00086 PyTypeObject KX_ConstraintWrapper::Type = { 00087 PyVarObject_HEAD_INIT(NULL, 0) 00088 "KX_ConstraintWrapper", 00089 sizeof(PyObjectPlus_Proxy), 00090 0, 00091 py_base_dealloc, 00092 0, 00093 0, 00094 0, 00095 0, 00096 py_base_repr, 00097 0,0,0,0,0,0,0,0,0, 00098 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 00099 0,0,0,0,0,0,0, 00100 Methods, 00101 0, 00102 0, 00103 &PyObjectPlus::Type, 00104 0,0,0,0,0,0, 00105 py_base_new 00106 }; 00107 00108 PyMethodDef KX_ConstraintWrapper::Methods[] = { 00109 {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS}, 00110 {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS}, 00111 {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS}, 00112 {NULL,NULL} //Sentinel 00113 }; 00114 00115 PyAttributeDef KX_ConstraintWrapper::Attributes[] = { 00116 KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId), 00117 { NULL } //Sentinel 00118 }; 00119 00120 PyObject* KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) 00121 { 00122 KX_ConstraintWrapper* self= static_cast<KX_ConstraintWrapper*>(self_v); 00123 return self->PyGetConstraintId(); 00124 } 00125 00126 #endif // WITH_PYTHON