~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_VehicleWrapper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#include <Python.h>
 
4
#include "KX_VehicleWrapper.h"
 
5
#include "PHY_IPhysicsEnvironment.h"
 
6
#include "PHY_IVehicle.h"
 
7
#include "KX_PyMath.h"
 
8
#include "KX_GameObject.h"
 
9
#include "KX_MotionState.h"
 
10
 
 
11
#ifdef HAVE_CONFIG_H
 
12
#include <config.h>
 
13
#endif
 
14
 
 
15
KX_VehicleWrapper::KX_VehicleWrapper(
 
16
                                                PHY_IVehicle* vehicle,
 
17
                                                PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
 
18
                PyObjectPlus(T),
 
19
                m_vehicle(vehicle),
 
20
                m_physenv(physenv)
 
21
{
 
22
}
 
23
 
 
24
KX_VehicleWrapper::~KX_VehicleWrapper()
 
25
{
 
26
        int numMotion = m_motionStates.size();
 
27
        for (int i=0;i<numMotion;i++)
 
28
        {
 
29
                PHY_IMotionState* motionState = m_motionStates[i];
 
30
                delete motionState;
 
31
        }
 
32
        m_motionStates.clear();
 
33
}
 
34
 
 
35
 
 
36
PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self, 
 
37
                                                                                        PyObject* args, 
 
38
                                                                                        PyObject* kwds)
 
39
{
 
40
        
 
41
        PyObject* pylistPos,*pylistDir,*pylistAxleDir;
 
42
        PyObject* wheelGameObject;
 
43
        float suspensionRestLength,wheelRadius;
 
44
        int hasSteering;
 
45
 
 
46
        
 
47
        if (PyArg_ParseTuple(args,"OOOOffi",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
 
48
        {
 
49
                KX_GameObject* gameOb = (KX_GameObject*) wheelGameObject;
 
50
                
 
51
                PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode());
 
52
 
 
53
                MT_Vector3 attachPos,attachDir,attachAxle;
 
54
                PyVecTo(pylistPos,attachPos);
 
55
                PyVecTo(pylistDir,attachDir);
 
56
                PyVecTo(pylistAxleDir,attachAxle);
 
57
                PHY__Vector3 aPos,aDir,aAxle;
 
58
                aPos[0] = attachPos[0];
 
59
                aPos[1] = attachPos[1];
 
60
                aPos[2] = attachPos[2];
 
61
                aDir[0] = attachDir[0];
 
62
                aDir[1] = attachDir[1];
 
63
                aDir[2] = attachDir[2];
 
64
                aAxle[0] = attachAxle[0];
 
65
                aAxle[1] = attachAxle[1];
 
66
                aAxle[2] = attachAxle[2];
 
67
                
 
68
                printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering);
 
69
                m_vehicle->AddWheel(motionState,aPos,aDir,aAxle,suspensionRestLength,wheelRadius,hasSteering);
 
70
                
 
71
        }
 
72
        Py_INCREF(Py_None);
 
73
        return Py_None;
 
74
}
 
75
 
 
76
 
 
77
 
 
78
 
 
79
PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self, 
 
80
                                                                                        PyObject* args, 
 
81
                                                                                        PyObject* kwds)
 
82
{
 
83
        
 
84
        int wheelIndex;
 
85
 
 
86
        if (PyArg_ParseTuple(args,"i",&wheelIndex))
 
87
        {
 
88
                float position[3];
 
89
                m_vehicle->GetWheelPosition(wheelIndex,position[0],position[1],position[2]);
 
90
                MT_Vector3 pos(position[0],position[1],position[2]);
 
91
                return PyObjectFrom(pos);
 
92
        }
 
93
        Py_INCREF(Py_None);
 
94
        return Py_None;
 
95
}
 
96
 
 
97
PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self, 
 
98
                                                                                        PyObject* args, 
 
99
                                                                                        PyObject* kwds)
 
100
{
 
101
        int wheelIndex;
 
102
        if (PyArg_ParseTuple(args,"i",&wheelIndex))
 
103
        {
 
104
                return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex));
 
105
        }
 
106
        Py_INCREF(Py_None);
 
107
        return Py_None;
 
108
}
 
109
 
 
110
PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self, 
 
111
                                                                                        PyObject* args, 
 
112
                                                                                        PyObject* kwds)
 
113
{
 
114
        int wheelIndex;
 
115
        if (PyArg_ParseTuple(args,"i",&wheelIndex))
 
116
        {
 
117
                float orn[4];
 
118
                m_vehicle->GetWheelOrientationQuaternion(wheelIndex,orn[0],orn[1],orn[2],orn[3]);
 
119
                MT_Quaternion   quatorn(orn[0],orn[1],orn[2],orn[3]);
 
120
                MT_Matrix3x3 ornmat(quatorn);
 
121
                return PyObjectFrom(ornmat);
 
122
        }
 
123
        Py_INCREF(Py_None);
 
124
        return Py_None;
 
125
 
 
126
}
 
127
 
 
128
 
 
129
PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* self, 
 
130
                                                                                        PyObject* args, 
 
131
                                                                                        PyObject* kwds)
 
132
{
 
133
        return PyInt_FromLong(m_vehicle->GetNumWheels());
 
134
}
 
135
 
 
136
 
 
137
PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* self, 
 
138
                                                                                        PyObject* args, 
 
139
                                                                                        PyObject* kwds)
 
140
{
 
141
        return PyInt_FromLong(m_vehicle->GetUserConstraintId());
 
142
}
 
143
 
 
144
 
 
145
 
 
146
PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self, 
 
147
                                                                                        PyObject* args, 
 
148
                                                                                        PyObject* kwds)
 
149
{
 
150
        float force;
 
151
        int wheelIndex;
 
152
 
 
153
        if (PyArg_ParseTuple(args,"fi",&force,&wheelIndex))
 
154
        {
 
155
                m_vehicle->ApplyEngineForce(force,wheelIndex);
 
156
        }
 
157
        Py_INCREF(Py_None);
 
158
        return Py_None;
 
159
}
 
160
 
 
161
PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* self, 
 
162
                                                                                        PyObject* args, 
 
163
                                                                                        PyObject* kwds)
 
164
{
 
165
        float wheelFriction;
 
166
        int wheelIndex;
 
167
 
 
168
        if (PyArg_ParseTuple(args,"fi",&wheelFriction,&wheelIndex))
 
169
        {
 
170
                m_vehicle->SetWheelFriction(wheelFriction,wheelIndex);
 
171
        }
 
172
        Py_INCREF(Py_None);
 
173
        return Py_None;
 
174
}
 
175
 
 
176
PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* self, 
 
177
                                                                                        PyObject* args, 
 
178
                                                                                        PyObject* kwds)
 
179
{
 
180
        float suspensionStiffness;
 
181
        int wheelIndex;
 
182
 
 
183
        if (PyArg_ParseTuple(args,"fi",&suspensionStiffness,&wheelIndex))
 
184
        {
 
185
                m_vehicle->SetSuspensionStiffness(suspensionStiffness,wheelIndex);
 
186
        }
 
187
        Py_INCREF(Py_None);
 
188
        return Py_None;
 
189
}
 
190
 
 
191
PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* self, 
 
192
                                                                                        PyObject* args, 
 
193
                                                                                        PyObject* kwds)
 
194
{
 
195
        float suspensionDamping;
 
196
        int wheelIndex;
 
197
 
 
198
        if (PyArg_ParseTuple(args,"fi",&suspensionDamping,&wheelIndex))
 
199
        {
 
200
                m_vehicle->SetSuspensionDamping(suspensionDamping,wheelIndex);
 
201
        }
 
202
        Py_INCREF(Py_None);
 
203
        return Py_None;
 
204
}
 
205
 
 
206
PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* self, 
 
207
                                                                                        PyObject* args, 
 
208
                                                                                        PyObject* kwds)
 
209
{
 
210
        float suspensionCompression;
 
211
        int wheelIndex;
 
212
 
 
213
        if (PyArg_ParseTuple(args,"fi",&suspensionCompression,&wheelIndex))
 
214
        {
 
215
                m_vehicle->SetSuspensionCompression(suspensionCompression,wheelIndex);
 
216
        }
 
217
        Py_INCREF(Py_None);
 
218
        return Py_None;
 
219
}
 
220
 
 
221
PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* self, 
 
222
                                                                                        PyObject* args, 
 
223
                                                                                        PyObject* kwds)
 
224
{
 
225
        float rollInfluence;
 
226
        int wheelIndex;
 
227
 
 
228
        if (PyArg_ParseTuple(args,"fi",&rollInfluence,&wheelIndex))
 
229
        {
 
230
                m_vehicle->SetRollInfluence(rollInfluence,wheelIndex);
 
231
        }
 
232
        Py_INCREF(Py_None);
 
233
        return Py_None;
 
234
}
 
235
 
 
236
 
 
237
PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self, 
 
238
                                                                                        PyObject* args, 
 
239
                                                                                        PyObject* kwds)
 
240
{
 
241
        float braking;
 
242
        int wheelIndex;
 
243
 
 
244
        if (PyArg_ParseTuple(args,"fi",&braking,&wheelIndex))
 
245
        {
 
246
                m_vehicle->ApplyBraking(braking,wheelIndex);
 
247
        }
 
248
        Py_INCREF(Py_None);
 
249
        return Py_None;
 
250
}
 
251
 
 
252
 
 
253
 
 
254
 
 
255
PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self, 
 
256
                                                                                        PyObject* args, 
 
257
                                                                                        PyObject* kwds)
 
258
{
 
259
        float steeringValue;
 
260
        int wheelIndex;
 
261
 
 
262
        if (PyArg_ParseTuple(args,"fi",&steeringValue,&wheelIndex))
 
263
        {
 
264
                m_vehicle->SetSteeringValue(steeringValue,wheelIndex);
 
265
        }
 
266
        Py_INCREF(Py_None);
 
267
        return Py_None;
 
268
}
 
269
 
 
270
 
 
271
PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self, 
 
272
                                                                                        PyObject* args, 
 
273
                                                                                        PyObject* kwds)
 
274
{
 
275
        return PyInt_FromLong(m_vehicle->GetUserConstraintType());
 
276
}
 
277
 
 
278
 
 
279
 
 
280
 
 
281
 
 
282
//python specific stuff
 
283
PyTypeObject KX_VehicleWrapper::Type = {
 
284
        PyObject_HEAD_INIT(&PyType_Type)
 
285
                0,
 
286
                "KX_VehicleWrapper",
 
287
                sizeof(KX_VehicleWrapper),
 
288
                0,
 
289
                PyDestructor,
 
290
                0,
 
291
                __getattr,
 
292
                __setattr,
 
293
                0, //&MyPyCompare,
 
294
                __repr,
 
295
                0, //&cvalue_as_number,
 
296
                0,
 
297
                0,
 
298
                0,
 
299
                0
 
300
};
 
301
 
 
302
PyParentObject KX_VehicleWrapper::Parents[] = {
 
303
        &KX_VehicleWrapper::Type,
 
304
        NULL
 
305
};
 
306
 
 
307
PyObject*       KX_VehicleWrapper::_getattr(const STR_String& attr)
 
308
{
 
309
        //here you can search for existing data members (like mass,friction etc.)
 
310
        _getattr_up(PyObjectPlus);
 
311
}
 
312
 
 
313
int     KX_VehicleWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
 
314
{
 
315
        
 
316
        PyTypeObject* type = pyobj->ob_type;
 
317
        int result = 1;
 
318
 
 
319
        if (type == &PyList_Type)
 
320
        {
 
321
                result = 0;
 
322
        }
 
323
        if (type == &PyFloat_Type)
 
324
        {
 
325
                result = 0;
 
326
 
 
327
        }
 
328
        if (type == &PyInt_Type)
 
329
        {
 
330
                result = 0;
 
331
        }
 
332
        if (type == &PyString_Type)
 
333
        {
 
334
                result = 0;
 
335
        }
 
336
        if (result)
 
337
                result = PyObjectPlus::_setattr(attr,pyobj);
 
338
        return result;
 
339
};
 
340
 
 
341
 
 
342
PyMethodDef KX_VehicleWrapper::Methods[] = {
 
343
        {"addWheel",(PyCFunction) KX_VehicleWrapper::sPyAddWheel, METH_VARARGS},
 
344
        {"getNumWheels",(PyCFunction) KX_VehicleWrapper::sPyGetNumWheels, METH_VARARGS},
 
345
        {"getWheelOrientationQuaternion",(PyCFunction) KX_VehicleWrapper::sPyGetWheelOrientationQuaternion, METH_VARARGS},
 
346
        {"getWheelRotation",(PyCFunction) KX_VehicleWrapper::sPyGetWheelRotation, METH_VARARGS},
 
347
        {"getWheelPosition",(PyCFunction) KX_VehicleWrapper::sPyGetWheelPosition, METH_VARARGS},
 
348
        {"getConstraintId",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintId, METH_VARARGS},
 
349
        {"getConstraintType",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintType, METH_VARARGS},
 
350
        {"setSteeringValue",(PyCFunction) KX_VehicleWrapper::sPySetSteeringValue, METH_VARARGS},
 
351
        {"applyEngineForce",(PyCFunction) KX_VehicleWrapper::sPyApplyEngineForce, METH_VARARGS},
 
352
        {"applyBraking",(PyCFunction) KX_VehicleWrapper::sPyApplyBraking, METH_VARARGS},
 
353
 
 
354
        {"setTyreFriction",(PyCFunction) KX_VehicleWrapper::sPySetTyreFriction, METH_VARARGS},
 
355
 
 
356
        {"setSuspensionStiffness",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionStiffness, METH_VARARGS},
 
357
 
 
358
        {"setSuspensionDamping",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionDamping, METH_VARARGS},
 
359
 
 
360
        {"setSuspensionCompression",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionCompression, METH_VARARGS},
 
361
 
 
362
        {"setRollInfluence",(PyCFunction) KX_VehicleWrapper::sPySetRollInfluence, METH_VARARGS},
 
363
 
 
364
        {NULL,NULL} //Sentinel
 
365
};
 
366