662db974ee856ea82802be881bcd823c30541e65
[blender.git] / source / gameengine / Ketsji / KX_ConstraintWrapper.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/Ketsji/KX_ConstraintWrapper.cpp
29  *  \ingroup ketsji
30  */
31
32
33 #include "PyObjectPlus.h"
34 #include "KX_ConstraintWrapper.h"
35 #include "PHY_IPhysicsEnvironment.h"
36
37 KX_ConstraintWrapper::KX_ConstraintWrapper(
38                                                 PHY_ConstraintType ctype,
39                                                 int constraintId,
40                                                 PHY_IPhysicsEnvironment* physenv) :
41                 PyObjectPlus(),
42                 m_constraintId(constraintId),
43                 m_constraintType(ctype),
44                 m_physenv(physenv)
45 {
46 }
47 KX_ConstraintWrapper::~KX_ConstraintWrapper()
48 {
49 }
50
51 #ifdef WITH_PYTHON
52
53 PyObject *KX_ConstraintWrapper::PyGetConstraintId()
54 {
55         return PyLong_FromSsize_t(m_constraintId);
56 }
57
58
59 PyObject *KX_ConstraintWrapper::PyGetParam(PyObject *args, PyObject *kwds)
60 {
61         int dof;
62         float value;
63         
64         if (!PyArg_ParseTuple(args,"i:getParam",&dof))
65                 return NULL;
66         
67         value = m_physenv->getConstraintParam(m_constraintId,dof);
68         return PyFloat_FromDouble(value);
69         
70 }
71
72 PyObject *KX_ConstraintWrapper::PySetParam(PyObject *args, PyObject *kwds)
73 {
74         int dof;
75         float minLimit,maxLimit;
76         
77         if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit))
78                 return NULL;
79         
80         m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
81         Py_RETURN_NONE;
82 }
83
84
85 //python specific stuff
86 PyTypeObject KX_ConstraintWrapper::Type = {
87         PyVarObject_HEAD_INIT(NULL, 0)
88         "KX_ConstraintWrapper",
89         sizeof(PyObjectPlus_Proxy),
90         0,
91         py_base_dealloc,
92         0,
93         0,
94         0,
95         0,
96         py_base_repr,
97         0,0,0,0,0,0,0,0,0,
98         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
99         0,0,0,0,0,0,0,
100         Methods,
101         0,
102         0,
103         &PyObjectPlus::Type,
104         0,0,0,0,0,0,
105         py_base_new
106 };
107
108 PyMethodDef KX_ConstraintWrapper::Methods[] = {
109         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS},
110         {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
111         {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS},
112         {NULL,NULL} //Sentinel
113 };
114
115 PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
116         KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId),
117         { NULL }        //Sentinel
118 };
119
120 PyObject *KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
121 {
122         KX_ConstraintWrapper* self = static_cast<KX_ConstraintWrapper*>(self_v);
123         return self->PyGetConstraintId();
124 }
125
126 #endif // WITH_PYTHON