2006-01-30 20:33:59 +00:00
|
|
|
|
|
|
|
|
2008-09-06 14:13:31 +00:00
|
|
|
#include "PyObjectPlus.h"
|
2008-09-06 02:46:11 +00:00
|
|
|
|
2006-01-30 20:33:59 +00:00
|
|
|
#include "KX_VehicleWrapper.h"
|
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
|
|
|
#include "PHY_IVehicle.h"
|
2006-02-13 06:28:35 +00:00
|
|
|
#include "KX_PyMath.h"
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
#include "KX_MotionState.h"
|
2006-01-30 20:33:59 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
KX_VehicleWrapper::KX_VehicleWrapper(
|
|
|
|
PHY_IVehicle* vehicle,
|
2009-06-28 11:22:26 +00:00
|
|
|
PHY_IPhysicsEnvironment* physenv) :
|
|
|
|
PyObjectPlus(),
|
2006-01-30 20:33:59 +00:00
|
|
|
m_vehicle(vehicle),
|
|
|
|
m_physenv(physenv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KX_VehicleWrapper::~KX_VehicleWrapper()
|
|
|
|
{
|
2006-02-13 06:28:35 +00:00
|
|
|
int numMotion = m_motionStates.size();
|
|
|
|
for (int i=0;i<numMotion;i++)
|
|
|
|
{
|
|
|
|
PHY_IMotionState* motionState = m_motionStates[i];
|
|
|
|
delete motionState;
|
|
|
|
}
|
|
|
|
m_motionStates.clear();
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
#ifndef DISABLE_PYTHON
|
2006-01-30 20:33:59 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* args)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
PyObject* pylistPos,*pylistDir,*pylistAxleDir;
|
|
|
|
PyObject* wheelGameObject;
|
|
|
|
float suspensionRestLength,wheelRadius;
|
|
|
|
int hasSteering;
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_GameObject *gameOb;
|
|
|
|
if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
|
|
|
|
return NULL;
|
|
|
|
|
2008-10-16 23:33:40 +00:00
|
|
|
|
|
|
|
if (gameOb->GetSGNode())
|
|
|
|
{
|
|
|
|
PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode());
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
/* TODO - no error checking here! - bad juju */
|
2008-10-16 23:33:40 +00:00
|
|
|
MT_Vector3 attachPos,attachDir,attachAxle;
|
|
|
|
PyVecTo(pylistPos,attachPos);
|
|
|
|
PyVecTo(pylistDir,attachDir);
|
|
|
|
PyVecTo(pylistAxleDir,attachAxle);
|
|
|
|
PHY__Vector3 aPos,aDir,aAxle;
|
|
|
|
aPos[0] = attachPos[0];
|
|
|
|
aPos[1] = attachPos[1];
|
|
|
|
aPos[2] = attachPos[2];
|
|
|
|
aDir[0] = attachDir[0];
|
|
|
|
aDir[1] = attachDir[1];
|
|
|
|
aDir[2] = attachDir[2];
|
|
|
|
aAxle[0] = -attachAxle[0];//someone reverse some conventions inside Bullet (axle winding)
|
|
|
|
aAxle[1] = -attachAxle[1];
|
|
|
|
aAxle[2] = -attachAxle[2];
|
|
|
|
|
|
|
|
printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering);
|
|
|
|
m_vehicle->AddWheel(motionState,aPos,aDir,aAxle,suspensionRestLength,wheelRadius,hasSteering);
|
|
|
|
}
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2008-07-01 16:43:46 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* args)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"i:getWheelPosition",&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
float position[3];
|
|
|
|
m_vehicle->GetWheelPosition(wheelIndex,position[0],position[1],position[2]);
|
|
|
|
MT_Vector3 pos(position[0],position[1],position[2]);
|
|
|
|
return PyObjectFrom(pos);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
return NULL;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* args)
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
int wheelIndex;
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"i:getWheelRotation",&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex));
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
return NULL;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* args)
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
int wheelIndex;
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"i:getWheelOrientationQuaternion",&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
float orn[4];
|
|
|
|
m_vehicle->GetWheelOrientationQuaternion(wheelIndex,orn[0],orn[1],orn[2],orn[3]);
|
|
|
|
MT_Quaternion quatorn(orn[0],orn[1],orn[2],orn[3]);
|
|
|
|
MT_Matrix3x3 ornmat(quatorn);
|
|
|
|
return PyObjectFrom(ornmat);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
return NULL;
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* args)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyLong_FromSsize_t(m_vehicle->GetNumWheels());
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* args)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyLong_FromSsize_t(m_vehicle->GetUserConstraintId());
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* args)
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
float force;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:applyEngineForce",&force,&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
2007-07-06 04:45:57 +00:00
|
|
|
force *= -1.f;//someone reverse some conventions inside Bullet (axle winding)
|
2006-02-13 06:28:35 +00:00
|
|
|
m_vehicle->ApplyEngineForce(force,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* args)
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
float wheelFriction;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setTyreFriction",&wheelFriction,&wheelIndex))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetWheelFriction(wheelFriction,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* args)
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
float suspensionStiffness;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setSuspensionStiffness",&suspensionStiffness,&wheelIndex))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetSuspensionStiffness(suspensionStiffness,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* args)
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
float suspensionDamping;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setSuspensionDamping",&suspensionDamping,&wheelIndex))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetSuspensionDamping(suspensionDamping,wheelIndex);
|
2008-07-01 16:43:46 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* args)
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
float suspensionCompression;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setSuspensionCompression",&suspensionCompression,&wheelIndex))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetSuspensionCompression(suspensionCompression,wheelIndex);
|
2008-07-01 16:43:46 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* args)
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
float rollInfluence;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setRollInfluence",&rollInfluence,&wheelIndex))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetRollInfluence(rollInfluence,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-21 07:08:23 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* args)
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
float braking;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:applyBraking",&braking,&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
m_vehicle->ApplyBraking(braking,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* args)
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
float steeringValue;
|
|
|
|
int wheelIndex;
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyArg_ParseTuple(args,"fi:setSteeringValue",&steeringValue,&wheelIndex))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
m_vehicle->SetSteeringValue(steeringValue,wheelIndex);
|
|
|
|
}
|
2008-07-01 16:43:46 +00:00
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-14 03:23:36 +00:00
|
|
|
Py_RETURN_NONE;
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* args)
|
2006-01-30 20:33:59 +00:00
|
|
|
{
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyLong_FromSsize_t(m_vehicle->GetUserConstraintType());
|
2006-01-30 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2006-01-30 20:33:59 +00:00
|
|
|
//python specific stuff
|
|
|
|
PyTypeObject KX_VehicleWrapper::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"KX_VehicleWrapper",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,0,0,0,0,0,0,0,0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&PyObjectPlus::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2006-01-30 20:33:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_VehicleWrapper::Methods[] = {
|
|
|
|
{"addWheel",(PyCFunction) KX_VehicleWrapper::sPyAddWheel, METH_VARARGS},
|
|
|
|
{"getNumWheels",(PyCFunction) KX_VehicleWrapper::sPyGetNumWheels, METH_VARARGS},
|
2006-02-13 06:28:35 +00:00
|
|
|
{"getWheelOrientationQuaternion",(PyCFunction) KX_VehicleWrapper::sPyGetWheelOrientationQuaternion, METH_VARARGS},
|
|
|
|
{"getWheelRotation",(PyCFunction) KX_VehicleWrapper::sPyGetWheelRotation, METH_VARARGS},
|
|
|
|
{"getWheelPosition",(PyCFunction) KX_VehicleWrapper::sPyGetWheelPosition, METH_VARARGS},
|
2006-01-30 20:33:59 +00:00
|
|
|
{"getConstraintId",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintId, METH_VARARGS},
|
|
|
|
{"getConstraintType",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintType, METH_VARARGS},
|
2006-02-13 06:28:35 +00:00
|
|
|
{"setSteeringValue",(PyCFunction) KX_VehicleWrapper::sPySetSteeringValue, METH_VARARGS},
|
|
|
|
{"applyEngineForce",(PyCFunction) KX_VehicleWrapper::sPyApplyEngineForce, METH_VARARGS},
|
|
|
|
{"applyBraking",(PyCFunction) KX_VehicleWrapper::sPyApplyBraking, METH_VARARGS},
|
2006-01-30 20:33:59 +00:00
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
{"setTyreFriction",(PyCFunction) KX_VehicleWrapper::sPySetTyreFriction, METH_VARARGS},
|
|
|
|
|
|
|
|
{"setSuspensionStiffness",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionStiffness, METH_VARARGS},
|
|
|
|
|
|
|
|
{"setSuspensionDamping",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionDamping, METH_VARARGS},
|
|
|
|
|
|
|
|
{"setSuspensionCompression",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionCompression, METH_VARARGS},
|
2006-01-30 20:33:59 +00:00
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
{"setRollInfluence",(PyCFunction) KX_VehicleWrapper::sPySetRollInfluence, METH_VARARGS},
|
|
|
|
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
2006-01-30 20:33:59 +00:00
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_VehicleWrapper::Attributes[] = {
|
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
#endif // DISABLE_PYTHON
|