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