fix for bug #18898: GE perspective 3D View not working properly (missing LENS)
[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,PyTypeObject *T) :
43                                         PyObjectPlus(T),
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 #if (PY_VERSION_HEX >= 0x02060000)
117         PyVarObject_HEAD_INIT(NULL, 0)
118 #else
119         /* python 2.5 and below */
120         PyObject_HEAD_INIT( NULL )  /* required py macro */
121         0,                          /* ob_size */
122 #endif
123                 "KX_PhysicsObjectWrapper",
124                 sizeof(PyObjectPlus_Proxy),
125                 0,
126                 py_base_dealloc,
127                 0,
128                 0,
129                 0,
130                 0,
131                 py_base_repr,
132                 0,0,0,0,0,0,
133                 py_base_getattro,
134                 py_base_setattro,
135                 0,0,0,0,0,0,0,0,0,
136                 Methods
137 };
138
139 PyParentObject KX_PhysicsObjectWrapper::Parents[] = {
140         &KX_PhysicsObjectWrapper::Type,
141         NULL
142 };
143
144 PyObject* KX_PhysicsObjectWrapper::py_getattro(PyObject *attr)
145 {
146         py_getattro_up(PyObjectPlus);
147 }
148
149 PyObject* KX_PhysicsObjectWrapper::py_getattro_dict() {
150         py_getattro_dict_up(PyObjectPlus);
151 }
152
153 int     KX_PhysicsObjectWrapper::py_setattro(PyObject *attr,PyObject *pyobj)
154 {
155         int result = 1;
156
157         if (PyInt_Check(pyobj))
158         {
159                 result = 0;
160         }
161         if (PyString_Check(pyobj))
162         {
163                 result = 0;
164         }
165         if (result)
166                 result = PyObjectPlus::py_setattro(attr,pyobj);
167                 
168         return result;
169 };
170
171
172 PyMethodDef KX_PhysicsObjectWrapper::Methods[] = {
173         {"setPosition",(PyCFunction) KX_PhysicsObjectWrapper::sPySetPosition, METH_VARARGS},
174         {"setLinearVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetLinearVelocity, METH_VARARGS},
175         {"setAngularVelocity",(PyCFunction) KX_PhysicsObjectWrapper::sPySetAngularVelocity, METH_VARARGS},
176         {"setActive",(PyCFunction) KX_PhysicsObjectWrapper::sPySetActive, METH_VARARGS},
177         {NULL,NULL} //Sentinel
178 };