add missing files after merging
[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 /** \file gameengine/Ketsji/KX_ConstraintWrapper.cpp
31  *  \ingroup ketsji
32  */
33
34
35 #include "PyObjectPlus.h"
36 #include "KX_ConstraintWrapper.h"
37 #include "PHY_IPhysicsEnvironment.h"
38
39 KX_ConstraintWrapper::KX_ConstraintWrapper(
40                                                 PHY_ConstraintType ctype,
41                                                 int constraintId,
42                                                 PHY_IPhysicsEnvironment* physenv) :
43                 PyObjectPlus(),
44                 m_constraintId(constraintId),
45                 m_constraintType(ctype),
46                 m_physenv(physenv)
47 {
48 }
49 KX_ConstraintWrapper::~KX_ConstraintWrapper()
50 {
51 }
52
53 #ifdef WITH_PYTHON
54
55 PyObject* KX_ConstraintWrapper::PyGetConstraintId()
56 {
57         return PyLong_FromSsize_t(m_constraintId);
58 }
59
60
61 PyObject* KX_ConstraintWrapper::PyGetParam(PyObject* args, PyObject* kwds)
62 {
63         int dof;
64         float value;
65         
66         if (!PyArg_ParseTuple(args,"i:getParam",&dof))
67                 return NULL;
68         
69         value = m_physenv->getConstraintParam(m_constraintId,dof);
70         return PyFloat_FromDouble(value);
71         
72 }
73
74 PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds)
75 {
76         int dof;
77         float minLimit,maxLimit;
78         
79         if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit))
80                 return NULL;
81         
82         m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
83         Py_RETURN_NONE;
84 }
85
86
87 //python specific stuff
88 PyTypeObject KX_ConstraintWrapper::Type = {
89         PyVarObject_HEAD_INIT(NULL, 0)
90         "KX_ConstraintWrapper",
91         sizeof(PyObjectPlus_Proxy),
92         0,
93         py_base_dealloc,
94         0,
95         0,
96         0,
97         0,
98         py_base_repr,
99         0,0,0,0,0,0,0,0,0,
100         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
101         0,0,0,0,0,0,0,
102         Methods,
103         0,
104         0,
105         &PyObjectPlus::Type,
106         0,0,0,0,0,0,
107         py_base_new
108 };
109
110 PyMethodDef KX_ConstraintWrapper::Methods[] = {
111         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS},
112         {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
113         {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS},
114         {NULL,NULL} //Sentinel
115 };
116
117 PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
118         KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId),
119         { NULL }        //Sentinel
120 };
121
122 PyObject* KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
123 {
124         KX_ConstraintWrapper* self= static_cast<KX_ConstraintWrapper*>(self_v);
125         return self->PyGetConstraintId();
126 }
127
128 #endif // WITH_PYTHON