rename and negate DISABLE_PYTHON --> WITH_PYTHON
[blender.git] / source / gameengine / Ketsji / KX_PhysicsObjectWrapper.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
32 #include "KX_PhysicsObjectWrapper.h"
33 #include "PHY_IPhysicsEnvironment.h"
34 #include "PHY_IPhysicsController.h"
35
36 KX_PhysicsObjectWrapper::KX_PhysicsObjectWrapper(
37                                                 PHY_IPhysicsController* ctrl,
38                                                 PHY_IPhysicsEnvironment* physenv) :
39                                         PyObjectPlus(),
40                                         m_ctrl(ctrl),
41                                         m_physenv(physenv)
42 {
43 }
44
45 KX_PhysicsObjectWrapper::~KX_PhysicsObjectWrapper()
46 {
47 }
48
49 #ifdef WITH_PYTHON
50
51 PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* args)
52 {
53         float x,y,z;
54         if (PyArg_ParseTuple(args,"fff:setPosition",&x,&y,&z))
55         {
56                 m_ctrl->setPosition(x,y,z);
57         }
58         else {
59                 return NULL;
60         }
61         Py_RETURN_NONE;
62 }
63
64
65 PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* args)
66 {
67         float x,y,z;
68         int local;
69         if (PyArg_ParseTuple(args,"fffi:setLinearVelocity",&x,&y,&z,&local))
70         {
71                 m_ctrl->SetLinearVelocity(x,y,z,local != 0);
72         }
73         else {
74                 return NULL;
75         }
76         Py_RETURN_NONE;
77 }
78
79 PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* args)
80 {
81         float x,y,z;
82         int local;
83         if (PyArg_ParseTuple(args,"fffi:setAngularVelocity",&x,&y,&z,&local))
84         {
85                 m_ctrl->SetAngularVelocity(x,y,z,local != 0);
86         }
87         else {
88                 return NULL;
89         }
90         Py_RETURN_NONE;
91 }
92
93 PyObject*       KX_PhysicsObjectWrapper::PySetActive(PyObject* args)
94 {
95         int active;
96         if (PyArg_ParseTuple(args,"i:setActive",&active))
97         {
98                 m_ctrl->SetActive(active!=0);
99         }
100         else {
101                 return NULL;
102         }
103         Py_RETURN_NONE;
104 }
105
106
107 PyAttributeDef KX_PhysicsObjectWrapper::Attributes[] = {
108         { NULL }        //Sentinel
109 };
110
111 //python specific stuff
112 PyTypeObject KX_PhysicsObjectWrapper::Type = {
113         PyVarObject_HEAD_INIT(NULL, 0)
114         "KX_PhysicsObjectWrapper",
115         sizeof(PyObjectPlus_Proxy),
116         0,
117         py_base_dealloc,
118         0,
119         0,
120         0,
121         0,
122         py_base_repr,
123         0,0,0,0,0,0,0,0,0,
124         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
125         0,0,0,0,0,0,0,
126         Methods,
127         0,
128         0,
129         &PyObjectPlus::Type,
130         0,0,0,0,0,0,
131         py_base_new
132 };
133
134 PyMethodDef KX_PhysicsObjectWrapper::Methods[] = {
135         {"setPosition",(PyCFunction) KX_PhysicsObjectWrapper::sPySetPosition, METH_VARARGS},
136         {"setLinearVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetLinearVelocity, METH_VARARGS},
137         {"setAngularVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetAngularVelocity, METH_VARARGS},
138         {"setActive",(PyCFunction) KX_PhysicsObjectWrapper::sPySetActive, METH_VARARGS},
139         {NULL,NULL} //Sentinel
140 };
141
142 #endif