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