svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22717:22875
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include <Python.h>
30 #include "PyObjectPlus.h"
31 #include "KX_ConstraintWrapper.h"
32 #include "PHY_IPhysicsEnvironment.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 KX_ConstraintWrapper::KX_ConstraintWrapper(
39                                                 PHY_ConstraintType ctype,
40                                                 int constraintId,
41                                                 PHY_IPhysicsEnvironment* physenv) :
42                 PyObjectPlus(),
43                 m_constraintId(constraintId),
44                 m_constraintType(ctype),
45                 m_physenv(physenv)
46 {
47 }
48 KX_ConstraintWrapper::~KX_ConstraintWrapper()
49 {
50 }
51
52 PyObject* KX_ConstraintWrapper::PyGetConstraintId()
53 {
54         return PyLong_FromSsize_t(m_constraintId);
55 }
56
57
58 PyObject* KX_ConstraintWrapper::PyGetParam(PyObject* args, PyObject* kwds)
59 {
60         int dof;
61         float value;
62         
63         if (!PyArg_ParseTuple(args,"i:getParam",&dof))
64                 return NULL;
65         
66         value = m_physenv->getConstraintParam(m_constraintId,dof);
67         return PyFloat_FromDouble(value);
68         
69 }
70
71 PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds)
72 {
73         int dof;
74         float minLimit,maxLimit;
75         
76         if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit))
77                 return NULL;
78         
79         m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
80         Py_RETURN_NONE;
81 }
82
83
84 //python specific stuff
85 PyTypeObject KX_ConstraintWrapper::Type = {
86         PyVarObject_HEAD_INIT(NULL, 0)
87         "KX_ConstraintWrapper",
88         sizeof(PyObjectPlus_Proxy),
89         0,
90         py_base_dealloc,
91         0,
92         0,
93         0,
94         0,
95         py_base_repr,
96         0,0,0,0,0,0,0,0,0,
97         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
98         0,0,0,0,0,0,0,
99         Methods,
100         0,
101         0,
102         &PyObjectPlus::Type,
103         0,0,0,0,0,0,
104         py_base_new
105 };
106
107 PyMethodDef KX_ConstraintWrapper::Methods[] = {
108         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS},
109         {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
110         {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS},
111         {NULL,NULL} //Sentinel
112 };
113
114 PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
115         //KX_PYATTRIBUTE_TODO("constraintId"),
116         { NULL }        //Sentinel
117 };