diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-01-30 23:33:59 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-01-30 23:33:59 +0300 |
commit | 18857a6225fba4b2b0d662b904cf04625a56e088 (patch) | |
tree | 2b6efca751351db9d2c32847395d3dbba3db56cc /source | |
parent | 8e9222ec217ab98980ffd75cd14387a062b46c9a (diff) |
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
Diffstat (limited to 'source')
9 files changed, 239 insertions, 4 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 55cd76824c9..1b343088446 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -79,7 +79,10 @@ PyTypeObject PyObjectPlus::Type = { PyObjectPlus::~PyObjectPlus() { - _Py_ForgetReference(this); + if (ob_refcnt) + { + _Py_ForgetReference(this); + } // assert(ob_refcnt==0); } diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp index 0e7ebc6442e..e9c71fe02c9 100644 --- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp +++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp @@ -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__}, diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp new file mode 100644 index 00000000000..299a2d1f180 --- /dev/null +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -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 +}; + + + diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h new file mode 100644 index 00000000000..ebdf1b0fa2f --- /dev/null +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.h @@ -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 diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 1b2527aa5bb..a599968a305 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -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); diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index a400459afe6..278f4eea9ca 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -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); diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index e1641407166..886bc8bb5fd 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -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); diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 340e4b21467..e247a8c5f2a 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -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; diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 078f84d4de2..6b40b51eba7 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -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; |