forked from bartvdbraak/blender
prepared physics/game engine infrastructure for vehicle support.
fixed a python related bug with physics contraints fixed some line-ending problem with blenderbuttons.c makefile/scons/projectfiles need to add source/gameengine/Ketsji/KX_VehicleWrapper.cpp
This commit is contained in:
parent
8e9222ec21
commit
18857a6225
@ -79,7 +79,10 @@ PyTypeObject PyObjectPlus::Type = {
|
||||
|
||||
PyObjectPlus::~PyObjectPlus()
|
||||
{
|
||||
_Py_ForgetReference(this);
|
||||
if (ob_refcnt)
|
||||
{
|
||||
_Py_ForgetReference(this);
|
||||
}
|
||||
// assert(ob_refcnt==0);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,10 @@
|
||||
#include "KX_PyConstraintBinding.h"
|
||||
#include "PHY_IPhysicsEnvironment.h"
|
||||
#include "KX_ConstraintWrapper.h"
|
||||
#include "KX_VehicleWrapper.h"
|
||||
#include "KX_PhysicsObjectWrapper.h"
|
||||
#include "PHY_IPhysicsController.h"
|
||||
#include "PHY_IVehicle.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
@ -66,7 +68,8 @@ static char gPySetSolverType__doc__[] = "setSolverType(int solverType) Very expe
|
||||
|
||||
|
||||
static char gPyCreateConstraint__doc__[] = "createConstraint(ob1,ob2,float restLength,float restitution,float damping)";
|
||||
static char gPyRemoveConstraint__doc__[] = "removeConstraint(constraint id)";
|
||||
static char gPyGetVehicleConstraint__doc__[] = "getVehicleConstraint(int constraintId)";
|
||||
static char gPyRemoveConstraint__doc__[] = "removeConstraint(int constraintId)";
|
||||
|
||||
|
||||
|
||||
@ -291,6 +294,35 @@ static PyObject* gPySetSolverType(PyObject* self,
|
||||
|
||||
|
||||
|
||||
static PyObject* gPyGetVehicleConstraint(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
#if defined(_WIN64)
|
||||
__int64 constraintid;
|
||||
if (PyArg_ParseTuple(args,"L",&constraintid))
|
||||
#else
|
||||
long constraintid;
|
||||
if (PyArg_ParseTuple(args,"l",&constraintid))
|
||||
#endif
|
||||
{
|
||||
if (PHY_GetActiveEnvironment())
|
||||
{
|
||||
|
||||
PHY_IVehicle* vehicle = PHY_GetActiveEnvironment()->getVehicleConstraint(constraintid);
|
||||
if (vehicle)
|
||||
{
|
||||
KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle,PHY_GetActiveEnvironment());
|
||||
return pyWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None); return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -407,9 +439,11 @@ static struct PyMethodDef physicsconstraints_methods[] = {
|
||||
METH_VARARGS, gPySetSolverType__doc__},
|
||||
|
||||
|
||||
|
||||
{"createConstraint",(PyCFunction) gPyCreateConstraint,
|
||||
METH_VARARGS, gPyCreateConstraint__doc__},
|
||||
{"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint,
|
||||
METH_VARARGS, gPyGetVehicleConstraint__doc__},
|
||||
|
||||
{"removeConstraint",(PyCFunction) gPyRemoveConstraint,
|
||||
METH_VARARGS, gPyRemoveConstraint__doc__},
|
||||
|
||||
|
140
source/gameengine/Ketsji/KX_VehicleWrapper.cpp
Normal file
140
source/gameengine/Ketsji/KX_VehicleWrapper.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
#include "KX_VehicleWrapper.h"
|
||||
#include "PHY_IPhysicsEnvironment.h"
|
||||
#include "PHY_IVehicle.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
KX_VehicleWrapper::KX_VehicleWrapper(
|
||||
PHY_IVehicle* vehicle,
|
||||
PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
|
||||
PyObjectPlus(T),
|
||||
m_vehicle(vehicle),
|
||||
m_physenv(physenv)
|
||||
{
|
||||
}
|
||||
|
||||
KX_VehicleWrapper::~KX_VehicleWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject* KX_VehicleWrapper::PyGetWheelsTransform(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
assert(0);
|
||||
return PyInt_FromLong(m_vehicle->GetNumWheels());
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
return PyInt_FromLong(m_vehicle->GetNumWheels());
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
return PyInt_FromLong(m_vehicle->GetUserConstraintId());
|
||||
}
|
||||
|
||||
PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
return PyInt_FromLong(m_vehicle->GetUserConstraintType());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//python specific stuff
|
||||
PyTypeObject KX_VehicleWrapper::Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"KX_VehicleWrapper",
|
||||
sizeof(KX_VehicleWrapper),
|
||||
0,
|
||||
PyDestructor,
|
||||
0,
|
||||
__getattr,
|
||||
__setattr,
|
||||
0, //&MyPyCompare,
|
||||
__repr,
|
||||
0, //&cvalue_as_number,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
PyParentObject KX_VehicleWrapper::Parents[] = {
|
||||
&KX_VehicleWrapper::Type,
|
||||
NULL
|
||||
};
|
||||
|
||||
PyObject* KX_VehicleWrapper::_getattr(const STR_String& attr)
|
||||
{
|
||||
//here you can search for existing data members (like mass,friction etc.)
|
||||
_getattr_up(PyObjectPlus);
|
||||
}
|
||||
|
||||
int KX_VehicleWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
|
||||
{
|
||||
|
||||
PyTypeObject* type = pyobj->ob_type;
|
||||
int result = 1;
|
||||
|
||||
if (type == &PyList_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (type == &PyFloat_Type)
|
||||
{
|
||||
result = 0;
|
||||
|
||||
}
|
||||
if (type == &PyInt_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (type == &PyString_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (result)
|
||||
result = PyObjectPlus::_setattr(attr,pyobj);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
PyMethodDef KX_VehicleWrapper::Methods[] = {
|
||||
{"addWheel",(PyCFunction) KX_VehicleWrapper::sPyAddWheel, METH_VARARGS},
|
||||
{"getNumWheels",(PyCFunction) KX_VehicleWrapper::sPyGetNumWheels, METH_VARARGS},
|
||||
{"getWheelsTransform",(PyCFunction) KX_VehicleWrapper::sPyGetWheelsTransform, METH_VARARGS},
|
||||
{"getConstraintId",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintId, METH_VARARGS},
|
||||
{"getConstraintType",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintType, METH_VARARGS},
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
|
||||
|
33
source/gameengine/Ketsji/KX_VehicleWrapper.h
Normal file
33
source/gameengine/Ketsji/KX_VehicleWrapper.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef KX_VEHICLE_WRAPPER
|
||||
#define KX_VEHICLE_WRAPPER
|
||||
|
||||
#include "Value.h"
|
||||
#include "PHY_DynamicTypes.h"
|
||||
class PHY_IVehicle;
|
||||
|
||||
///Python interface to physics vehicles (primarily 4-wheel cars and 2wheel bikes)
|
||||
class KX_VehicleWrapper : public PyObjectPlus
|
||||
{
|
||||
Py_Header;
|
||||
virtual PyObject* _getattr(const STR_String& attr);
|
||||
virtual int _setattr(const STR_String& attr, PyObject *value);
|
||||
public:
|
||||
KX_VehicleWrapper(PHY_IVehicle* vehicle,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type);
|
||||
virtual ~KX_VehicleWrapper ();
|
||||
int getConstraintId();
|
||||
|
||||
|
||||
KX_PYMETHOD(KX_VehicleWrapper,AddWheel);
|
||||
KX_PYMETHOD(KX_VehicleWrapper,GetNumWheels);
|
||||
KX_PYMETHOD(KX_VehicleWrapper,GetWheelsTransform);
|
||||
|
||||
KX_PYMETHOD(KX_VehicleWrapper,GetConstraintId);
|
||||
KX_PYMETHOD(KX_VehicleWrapper,GetConstraintType);
|
||||
|
||||
|
||||
private:
|
||||
PHY_IVehicle* m_vehicle;
|
||||
PHY_IPhysicsEnvironment* m_physenv;
|
||||
};
|
||||
|
||||
#endif //KX_VEHICLE_WRAPPER
|
@ -79,6 +79,11 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
|
||||
float axisX,float axisY,float axisZ);
|
||||
virtual void removeConstraint(int constraintid);
|
||||
|
||||
//complex constraint for vehicles
|
||||
virtual PHY_IVehicle* getVehicleConstraint(int constraintId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ,
|
||||
float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
|
||||
|
@ -62,6 +62,13 @@ public:
|
||||
float axisX,float axisY,float axisZ);
|
||||
|
||||
virtual void removeConstraint(int constraintid);
|
||||
|
||||
//complex constraint for vehicles
|
||||
virtual PHY_IVehicle* getVehicleConstraint(int constraintId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ,
|
||||
float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
|
||||
|
||||
|
@ -67,6 +67,13 @@ public:
|
||||
float axisX,float axisY,float axisZ);
|
||||
|
||||
virtual void removeConstraint(int constraintid);
|
||||
|
||||
//complex constraint for vehicles
|
||||
virtual PHY_IVehicle* getVehicleConstraint(int constraintId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ,
|
||||
float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
|
||||
|
||||
|
@ -98,7 +98,8 @@ typedef enum PHY_PhysicsType {
|
||||
/// PHY_ConstraintType enumerates all supported Constraint Types
|
||||
typedef enum PHY_ConstraintType {
|
||||
PHY_POINT2POINT_CONSTRAINT=1,
|
||||
PHY_LINEHINGE_CONSTRAINT
|
||||
PHY_LINEHINGE_CONSTRAINT=2,
|
||||
PHY_VEHICLE_CONSTRAINT=11,//complex 'constraint' that turns a rigidbody into a vehicle
|
||||
|
||||
} PHY_ConstraintType;
|
||||
|
||||
|
@ -29,11 +29,13 @@
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef _IPHYSICSENVIRONMENT
|
||||
#define _IPHYSICSENVIRONMENT
|
||||
|
||||
#include <vector>
|
||||
#include "PHY_DynamicTypes.h"
|
||||
class PHY_IVehicle;
|
||||
|
||||
/**
|
||||
* Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.)
|
||||
@ -85,6 +87,9 @@ class PHY_IPhysicsEnvironment
|
||||
float axisX,float axisY,float axisZ)=0;
|
||||
virtual void removeConstraint(int constraintid)=0;
|
||||
|
||||
//complex constraint for vehicles
|
||||
virtual PHY_IVehicle* getVehicleConstraint(int constraintId) =0;
|
||||
|
||||
virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ,
|
||||
float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)=0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user