4
#include "KX_VehicleWrapper.h"
5
#include "PHY_IPhysicsEnvironment.h"
6
#include "PHY_IVehicle.h"
8
#include "KX_GameObject.h"
9
#include "KX_MotionState.h"
15
KX_VehicleWrapper::KX_VehicleWrapper(
16
PHY_IVehicle* vehicle,
17
PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
24
KX_VehicleWrapper::~KX_VehicleWrapper()
26
int numMotion = m_motionStates.size();
27
for (int i=0;i<numMotion;i++)
29
PHY_IMotionState* motionState = m_motionStates[i];
32
m_motionStates.clear();
36
PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self,
41
PyObject* pylistPos,*pylistDir,*pylistAxleDir;
42
PyObject* wheelGameObject;
43
float suspensionRestLength,wheelRadius;
47
if (PyArg_ParseTuple(args,"OOOOffi",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
49
KX_GameObject* gameOb = (KX_GameObject*) wheelGameObject;
51
PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode());
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];
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);
79
PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self,
86
if (PyArg_ParseTuple(args,"i",&wheelIndex))
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);
97
PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self,
102
if (PyArg_ParseTuple(args,"i",&wheelIndex))
104
return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex));
110
PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self,
115
if (PyArg_ParseTuple(args,"i",&wheelIndex))
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);
129
PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* self,
133
return PyInt_FromLong(m_vehicle->GetNumWheels());
137
PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* self,
141
return PyInt_FromLong(m_vehicle->GetUserConstraintId());
146
PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self,
153
if (PyArg_ParseTuple(args,"fi",&force,&wheelIndex))
155
m_vehicle->ApplyEngineForce(force,wheelIndex);
161
PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* self,
168
if (PyArg_ParseTuple(args,"fi",&wheelFriction,&wheelIndex))
170
m_vehicle->SetWheelFriction(wheelFriction,wheelIndex);
176
PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* self,
180
float suspensionStiffness;
183
if (PyArg_ParseTuple(args,"fi",&suspensionStiffness,&wheelIndex))
185
m_vehicle->SetSuspensionStiffness(suspensionStiffness,wheelIndex);
191
PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* self,
195
float suspensionDamping;
198
if (PyArg_ParseTuple(args,"fi",&suspensionDamping,&wheelIndex))
200
m_vehicle->SetSuspensionDamping(suspensionDamping,wheelIndex);
206
PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* self,
210
float suspensionCompression;
213
if (PyArg_ParseTuple(args,"fi",&suspensionCompression,&wheelIndex))
215
m_vehicle->SetSuspensionCompression(suspensionCompression,wheelIndex);
221
PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* self,
228
if (PyArg_ParseTuple(args,"fi",&rollInfluence,&wheelIndex))
230
m_vehicle->SetRollInfluence(rollInfluence,wheelIndex);
237
PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self,
244
if (PyArg_ParseTuple(args,"fi",&braking,&wheelIndex))
246
m_vehicle->ApplyBraking(braking,wheelIndex);
255
PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self,
262
if (PyArg_ParseTuple(args,"fi",&steeringValue,&wheelIndex))
264
m_vehicle->SetSteeringValue(steeringValue,wheelIndex);
271
PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self,
275
return PyInt_FromLong(m_vehicle->GetUserConstraintType());
282
//python specific stuff
283
PyTypeObject KX_VehicleWrapper::Type = {
284
PyObject_HEAD_INIT(&PyType_Type)
287
sizeof(KX_VehicleWrapper),
295
0, //&cvalue_as_number,
302
PyParentObject KX_VehicleWrapper::Parents[] = {
303
&KX_VehicleWrapper::Type,
307
PyObject* KX_VehicleWrapper::_getattr(const STR_String& attr)
309
//here you can search for existing data members (like mass,friction etc.)
310
_getattr_up(PyObjectPlus);
313
int KX_VehicleWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
316
PyTypeObject* type = pyobj->ob_type;
319
if (type == &PyList_Type)
323
if (type == &PyFloat_Type)
328
if (type == &PyInt_Type)
332
if (type == &PyString_Type)
337
result = PyObjectPlus::_setattr(attr,pyobj);
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},
354
{"setTyreFriction",(PyCFunction) KX_VehicleWrapper::sPySetTyreFriction, METH_VARARGS},
356
{"setSuspensionStiffness",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionStiffness, METH_VARARGS},
358
{"setSuspensionDamping",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionDamping, METH_VARARGS},
360
{"setSuspensionCompression",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionCompression, METH_VARARGS},
362
{"setRollInfluence",(PyCFunction) KX_VehicleWrapper::sPySetRollInfluence, METH_VARARGS},
364
{NULL,NULL} //Sentinel