diff --git a/doc/python_api/rst/bge.constraints.rst b/doc/python_api/rst/bge.constraints.rst index ed965c3dfc1d..97302ff98098 100644 --- a/doc/python_api/rst/bge.constraints.rst +++ b/doc/python_api/rst/bge.constraints.rst @@ -60,6 +60,16 @@ Functions :return: A constraint wrapper. :rtype: :class:`~bge.types.KX_ConstraintWrapper` +.. function:: createVehicle(physicsid) + + Creates a vehicle constraint. + + :arg physicsid: The physics id of the chassis object in constraint. + :type physicsid: int + + :return: A vehicle constraint wrapper. + :rtype: :class:`~bge.types.KX_VehicleWrapper` + .. function:: exportBulletFile(filename) Exports a file representing the dynamics world (usually using ``.bullet`` extension). diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 8042b5485e3a..8e705ad24e27 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -241,18 +241,6 @@ set(SRC KX_WorldInfo.h KX_WorldIpoController.h KX_CollisionContactPoints.h - - # orphan headers (not apart of a library) - ../Physics/Common/PHY_DynamicTypes.h - ../Physics/Common/PHY_ICharacter.h - ../Physics/Common/PHY_IController.h - ../Physics/Common/PHY_IGraphicController.h - ../Physics/Common/PHY_IMotionState.h - ../Physics/Common/PHY_IPhysicsController.h - ../Physics/Common/PHY_IPhysicsEnvironment.h - ../Physics/Common/PHY_IVehicle.h - ../Physics/Common/PHY_Pro.h - ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index 16ed81a294bb..8b60d130339a 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -30,17 +30,11 @@ */ -#include "EXP_PyObjectPlus.h" #include "KX_ConstraintWrapper.h" -#include "PHY_IPhysicsEnvironment.h" - -KX_ConstraintWrapper::KX_ConstraintWrapper( - PHY_ConstraintType ctype, - int constraintId, - PHY_IPhysicsEnvironment* physenv) : - m_constraintId(constraintId), - m_constraintType(ctype), - m_physenv(physenv) +#include "PHY_IConstraint.h" + +KX_ConstraintWrapper::KX_ConstraintWrapper(PHY_IConstraint *constraint) + :m_constraint(constraint) { } KX_ConstraintWrapper::~KX_ConstraintWrapper() @@ -56,7 +50,7 @@ std::string KX_ConstraintWrapper::GetName() PyObject *KX_ConstraintWrapper::PyGetConstraintId() { - return PyLong_FromLong(m_constraintId); + return PyLong_FromLong(m_constraint->GetIdentifier()); } @@ -68,7 +62,7 @@ PyObject *KX_ConstraintWrapper::PyGetParam(PyObject *args, PyObject *kwds) if (!PyArg_ParseTuple(args,"i:getParam",&dof)) return nullptr; - value = m_physenv->GetConstraintParam(m_constraintId,dof); + value = m_constraint->GetParam(dof); return PyFloat_FromDouble(value); } @@ -81,7 +75,7 @@ PyObject *KX_ConstraintWrapper::PySetParam(PyObject *args, PyObject *kwds) if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit)) return nullptr; - m_physenv->SetConstraintParam(m_constraintId,dof,minLimit,maxLimit); + m_constraint->SetParam(dof,minLimit,maxLimit); Py_RETURN_NONE; } @@ -125,13 +119,13 @@ PyAttributeDef KX_ConstraintWrapper::Attributes[] = { PyObject *KX_ConstraintWrapper::pyattr_get_constraintId(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_ConstraintWrapper* self = static_cast(self_v); - return self->PyGetConstraintId(); + return PyLong_FromLong(self->m_constraint->GetIdentifier()); } PyObject *KX_ConstraintWrapper::pyattr_get_constraintType(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_ConstraintWrapper* self = static_cast(self_v); - return PyLong_FromLong(self->m_constraintType); + return PyLong_FromLong(self->m_constraint->GetType()); } #endif // WITH_PYTHON diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h index aee6fa24575f..cd3f624caeec 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.h @@ -33,18 +33,17 @@ #define __KX_CONSTRAINTWRAPPER_H__ #include "EXP_Value.h" -#include "PHY_DynamicTypes.h" + +class PHY_IConstraint; class KX_ConstraintWrapper : public CValue { Py_Header public: - KX_ConstraintWrapper(PHY_ConstraintType ctype,int constraintId,class PHY_IPhysicsEnvironment* physenv); + KX_ConstraintWrapper(PHY_IConstraint *constraint); virtual ~KX_ConstraintWrapper (); virtual std::string GetName(); - - int getConstraintId() { return m_constraintId; } #ifdef WITH_PYTHON KX_PYMETHOD_NOARGS(KX_ConstraintWrapper,GetConstraintId); @@ -56,9 +55,7 @@ class KX_ConstraintWrapper : public CValue #endif private: - int m_constraintId; - PHY_ConstraintType m_constraintType; - PHY_IPhysicsEnvironment* m_physenv; + PHY_IConstraint *m_constraint; }; #endif /* __KX_CONSTRAINTWRAPPER_H__ */ diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp index aa5998e7025e..c5dc2709bda4 100644 --- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp +++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp @@ -130,6 +130,10 @@ PyDoc_STRVAR(gPyCreateConstraint__doc__, "createConstraint(ob1,ob2,float restLength,float restitution,float damping)\n" "" ); +PyDoc_STRVAR(gPyCreateVehicle__doc__, +"createVehicle(chassis)\n" +"" +); PyDoc_STRVAR(gPyGetVehicleConstraint__doc__, "getVehicleConstraint(int constraintId)\n" "" @@ -450,7 +454,7 @@ static PyObject *gPyGetVehicleConstraint(PyObject *self, PHY_IVehicle* vehicle = PHY_GetActiveEnvironment()->GetVehicleConstraint(constraintid); if (vehicle) { - KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle,PHY_GetActiveEnvironment()); + KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle); return pyWrapper->NewProxy(true); } @@ -515,6 +519,14 @@ static PyObject *gPyCreateConstraint(PyObject *self, PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid; PHY_IPhysicsController *physctrl2 = (PHY_IPhysicsController*)physicsid2; if (physctrl) { //TODO:check for existence of this pointer! + if (constrainttype == PHY_VEHICLE_CONSTRAINT) { + ShowDeprecationWarning("bge.constraints.createConstraint(...)", "bge.constraints.createVehicle(chassis)"); + PHY_IVehicle *vehicle = PHY_GetActiveEnvironment()->CreateVehicle(physctrl); + + KX_VehicleWrapper *wrap = new KX_VehicleWrapper(vehicle); + + return wrap->NewProxy(true); + } //convert from euler angle into axis const float deg2rad = 0.017453292f; @@ -525,14 +537,17 @@ static PyObject *gPyCreateConstraint(PyObject *self, MT_Vector3 axis1 = localCFrame.getColumn(1); MT_Vector3 axis2 = localCFrame.getColumn(2); - int constraintid = PHY_GetActiveEnvironment()->CreateConstraint( + PHY_IConstraint *constraint = PHY_GetActiveEnvironment()->CreateConstraint( physctrl, physctrl2, (enum PHY_ConstraintType)constrainttype, pivotX, pivotY, pivotZ, (float)axis0.x(), (float)axis0.y(), (float)axis0.z(), (float)axis1.x(), (float)axis1.y(), (float)axis1.z(), (float)axis2.x(), (float)axis2.y(), (float)axis2.z(), flag); - KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper( - (enum PHY_ConstraintType)constrainttype, constraintid, PHY_GetActiveEnvironment()); + if (!constraint) { + return nullptr; + } + + KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper(constraint); return wrap->NewProxy(true); } @@ -540,8 +555,33 @@ static PyObject *gPyCreateConstraint(PyObject *self, Py_RETURN_NONE; } +static PyObject *gPyCreateVehicle(PyObject *self, PyObject *args) +{ + /* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */ + unsigned long long physicsid = 0; + if (!PyArg_ParseTuple(args, "K:createVehicle", &physicsid)) { + return nullptr; + } + if (!PHY_GetActiveEnvironment()) { + Py_RETURN_NONE; + } + + PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid; + if (!physctrl) { //TODO:check for existence of this pointer! + return nullptr; + } + + PHY_IVehicle *vehicle = PHY_GetActiveEnvironment()->CreateVehicle(physctrl); + if (!vehicle) { + return nullptr; + } + + KX_VehicleWrapper *wrap = new KX_VehicleWrapper(vehicle); + + return wrap->NewProxy(true); +} static PyObject *gPyGetAppliedImpulse(PyObject *self, PyObject *args, @@ -650,6 +690,8 @@ static struct PyMethodDef physicsconstraints_methods[] = { {"createConstraint",(PyCFunction) gPyCreateConstraint, METH_VARARGS|METH_KEYWORDS, (const char *)gPyCreateConstraint__doc__}, + {"createVehicle",(PyCFunction) gPyCreateVehicle, + METH_VARARGS, (const char *)gPyCreateVehicle__doc__}, {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint, METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__}, diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index ebc75507aead..92c8f77e8685 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -22,10 +22,7 @@ * \ingroup ketsji */ -#include "EXP_PyObjectPlus.h" - #include "KX_VehicleWrapper.h" -#include "PHY_IPhysicsEnvironment.h" #include "PHY_IVehicle.h" #include "KX_PyMath.h" #include "KX_GameObject.h" @@ -34,23 +31,13 @@ #include "DNA_object_types.h" // for OB_MAX_COL_MASKS -KX_VehicleWrapper::KX_VehicleWrapper( - PHY_IVehicle* vehicle, - PHY_IPhysicsEnvironment* physenv) : - m_vehicle(vehicle), - m_physenv(physenv) +KX_VehicleWrapper::KX_VehicleWrapper(PHY_IVehicle *vehicle) + :m_vehicle(vehicle) { } KX_VehicleWrapper::~KX_VehicleWrapper() { - int numMotion = m_motionStates.size(); - for (int i=0;i(self_v); + return PyLong_FromLong(self->m_vehicle->GetUserConstraintId()); +} + +PyObject *KX_VehicleWrapper::pyattr_get_constraintType(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_VehicleWrapper* self = static_cast(self_v); + return PyLong_FromLong(PHY_VEHICLE_CONSTRAINT); +} + PyObject *KX_VehicleWrapper::pyattr_get_ray_mask(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_VehicleWrapper *wrapper = static_cast(self); diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h index fe1c82a561e5..52497bff5a9b 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.h +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.h @@ -8,25 +8,18 @@ #include "EXP_Value.h" class PHY_IVehicle; -class PHY_IMotionState; - -#include ///Python interface to physics vehicles (primarily 4-wheel cars and 2wheel bikes) class KX_VehicleWrapper : public CValue { Py_Header - std::vector m_motionStates; - public: - KX_VehicleWrapper(PHY_IVehicle* vehicle,class PHY_IPhysicsEnvironment* physenv); + KX_VehicleWrapper(PHY_IVehicle* vehicle); virtual ~KX_VehicleWrapper (); virtual std::string GetName(); - int getConstraintId(); - #ifdef WITH_PYTHON KX_PYMETHOD_VARARGS(KX_VehicleWrapper,AddWheel); @@ -57,12 +50,13 @@ class KX_VehicleWrapper : public CValue static PyObject *pyattr_get_ray_mask(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_ray_mask(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject *pyattr_get_constraintId(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject *pyattr_get_constraintType(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef); #endif /* WITH_PYTHON */ private: PHY_IVehicle* m_vehicle; - PHY_IPhysicsEnvironment* m_physenv; }; #endif /* __KX_VEHICLEWRAPPER_H__ */ diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index c6bbbacae438..5db6c6b805a8 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -51,10 +51,12 @@ set(INC_SYS ) set(SRC + CcdConstraint.cpp CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp CcdGraphicController.cpp + CcdConstraint.h CcdMathUtils.h CcdGraphicController.h CcdPhysicsController.h diff --git a/source/gameengine/Physics/Bullet/CcdConstraint.cpp b/source/gameengine/Physics/Bullet/CcdConstraint.cpp new file mode 100644 index 000000000000..5e965b507d29 --- /dev/null +++ b/source/gameengine/Physics/Bullet/CcdConstraint.cpp @@ -0,0 +1,189 @@ +#include "CcdConstraint.h" + +#include "btBulletDynamicsCommon.h" + +CcdConstraint::CcdConstraint(btTypedConstraint *constraint, bool disableCollision) + :m_constraint(constraint), + m_disableCollision(disableCollision), + m_enabled(true) +{ +} + +CcdConstraint::~CcdConstraint() +{ +} + +bool CcdConstraint::GetDisableCollision() const +{ + return m_disableCollision; +} + +bool CcdConstraint::GetEnabled() const +{ + return m_enabled; +} + +void CcdConstraint::SetEnabled(bool enabled) +{ + m_enabled = enabled; +} + +void CcdConstraint::SetParam(int param, float value0, float value1) +{ + if (!m_constraint) + return; + + switch (m_constraint->getUserConstraintType()) + { + case PHY_GENERIC_6DOF_CONSTRAINT: + { + switch (param) + { + case 0: case 1: case 2: case 3: case 4: case 5: + { + //param = 0..5 are constraint limits, with low/high limit value + btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)m_constraint; + genCons->setLimit(param, value0, value1); + break; + } + case 6: case 7: case 8: + { + //param = 6,7,8 are translational motors, with value0=target velocity, value1 = max motor force + btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)m_constraint; + int transMotorIndex = param - 6; + btTranslationalLimitMotor *transMotor = genCons->getTranslationalLimitMotor(); + transMotor->m_targetVelocity[transMotorIndex] = value0; + transMotor->m_maxMotorForce[transMotorIndex] = value1; + transMotor->m_enableMotor[transMotorIndex] = (value1 > 0.0f); + break; + } + case 9: case 10: case 11: + { + //param = 9,10,11 are rotational motors, with value0=target velocity, value1 = max motor force + btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)m_constraint; + int angMotorIndex = param - 9; + btRotationalLimitMotor *rotMotor = genCons->getRotationalLimitMotor(angMotorIndex); + rotMotor->m_enableMotor = (value1 > 0.0f); + rotMotor->m_targetVelocity = value0; + rotMotor->m_maxMotorForce = value1; + break; + } + + case 12: case 13: case 14: case 15: case 16: case 17: + { + //param 12-17 are for motorized springs on each of the degrees of freedom + btGeneric6DofSpringConstraint *genCons = (btGeneric6DofSpringConstraint *)m_constraint; + int springIndex = param - 12; + if (value0 != 0.0f) { + bool springEnabled = true; + genCons->setStiffness(springIndex, value0); + genCons->setDamping(springIndex, value1); + genCons->enableSpring(springIndex, springEnabled); + genCons->setEquilibriumPoint(springIndex); + } + else { + bool springEnabled = false; + genCons->enableSpring(springIndex, springEnabled); + } + break; + } + + default: + { + } + }; + break; + }; + case PHY_CONE_TWIST_CONSTRAINT: + { + switch (param) + { + case 3: case 4: case 5: + { + //param = 3,4,5 are constraint limits, high limit values + btConeTwistConstraint *coneTwist = (btConeTwistConstraint *)m_constraint; + if (value1 < 0.0f) + coneTwist->setLimit(param, btScalar(BT_LARGE_FLOAT)); + else + coneTwist->setLimit(param, value1); + break; + } + default: + { + } + }; + break; + }; + case PHY_ANGULAR_CONSTRAINT: + case PHY_LINEHINGE_CONSTRAINT: + { + switch (param) + { + case 3: + { + //param = 3 is a constraint limit, with low/high limit value + btHingeConstraint *hingeCons = (btHingeConstraint *)m_constraint; + hingeCons->setLimit(value0, value1); + break; + } + default: + { + } + } + break; + }; + default: + { + }; + }; +} + +float CcdConstraint::GetParam(int param) +{ + if (!m_constraint) + return 0.0f; + + switch (m_constraint->getUserConstraintType()) + { + case PHY_GENERIC_6DOF_CONSTRAINT: + { + switch (param) + { + case 0: case 1: case 2: + { + //param = 0..2 are linear constraint values + btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)m_constraint; + genCons->calculateTransforms(); + return genCons->getRelativePivotPosition(param); + break; + } + case 3: case 4: case 5: + { + //param = 3..5 are relative constraint (Euler) angles + btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)m_constraint; + genCons->calculateTransforms(); + return genCons->getAngle(param - 3); + break; + } + default: + { + } + } + break; + }; + default: + { + }; + }; + return 0.0f; +} + +int CcdConstraint::GetIdentifier() const +{ + return m_constraint->getUserConstraintId(); +} + +PHY_ConstraintType CcdConstraint::GetType() const +{ + return (PHY_ConstraintType)m_constraint->getUserConstraintType(); +} diff --git a/source/gameengine/Physics/Bullet/CcdConstraint.h b/source/gameengine/Physics/Bullet/CcdConstraint.h new file mode 100644 index 000000000000..9534c390407a --- /dev/null +++ b/source/gameengine/Physics/Bullet/CcdConstraint.h @@ -0,0 +1,33 @@ +#ifndef __CCD_CONSTRAINT_H__ +#define __CCD_CONSTRAINT_H__ + +#include "PHY_IConstraint.h" + +class btTypedConstraint; + +class CcdConstraint : public PHY_IConstraint +{ +private: + btTypedConstraint *m_constraint; + + /// Disable collision between constrained objects? + bool m_disableCollision; + /// The constraint is added in dynamic world? + bool m_enabled; + +public: + CcdConstraint(btTypedConstraint *constraint, bool disableCollision); + virtual ~CcdConstraint(); + + bool GetDisableCollision() const; + bool GetEnabled() const; + void SetEnabled(bool enabled); + + virtual void SetParam(int param, float value0, float value1); + virtual float GetParam(int param); + + virtual int GetIdentifier() const; + virtual PHY_ConstraintType GetType() const; +}; + +#endif // __CCD_CONSTRAINT_H__ diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 26d2882ed060..bff2f27475f5 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -266,13 +266,6 @@ class BlenderBulletMotionState : public btMotionState } }; -CcdPhysicsController::CcdConstraint::CcdConstraint(bool disableCollision) - :m_disableCollision(disableCollision), - m_active(false) -{ -} - - btRigidBody *CcdPhysicsController::GetRigidBody() { return btRigidBody::upcast(m_object); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index bc91e7d68645..4507dfde5701 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -530,17 +530,6 @@ class CleanPairCallback : public btOverlapCallback /// CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution. class CcdPhysicsController : public PHY_IPhysicsController { -public: - /// Constraint user data. - struct CcdConstraint - { - CcdConstraint(bool m_disableCollision); - /// Disable collision between constrained objects? - bool m_disableCollision; - /// The constraint is added in dynamic world? - bool m_active; - }; - protected: btCollisionObject *m_object; BlenderBulletCharacterController *m_characterController; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index ce9191341f8c..be0ad090b3b8 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -19,6 +19,7 @@ #include "CcdPhysicsEnvironment.h" #include "CcdPhysicsController.h" #include "CcdGraphicController.h" +#include "CcdConstraint.h" #include "CcdMathUtils.h" #include @@ -57,14 +58,12 @@ extern "C" { #define CCD_CONSTRAINT_DISABLE_LINKED_COLLISION 0x80 -#ifdef NEW_BULLET_VEHICLE_SUPPORT #include "BulletDynamics/Vehicle/btRaycastVehicle.h" #include "BulletDynamics/Vehicle/btVehicleRaycaster.h" #include "BulletDynamics/Vehicle/btWheelInfo.h" #include "PHY_IVehicle.h" static btRaycastVehicle::btVehicleTuning gTuning; -#endif //NEW_BULLET_VEHICLE_SUPPORT #include "LinearMath/btAabbUtil2.h" #include "MT_MinMax.h" @@ -92,8 +91,6 @@ void DrawRasterizerLine(const float *from, const float *to, int color); #endif //_MSC_VER #endif //WIN32 -#ifdef NEW_BULLET_VEHICLE_SUPPORT - class VehicleClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback { private: @@ -365,8 +362,6 @@ class WrapperVehicle : public PHY_IVehicle } }; -#endif //NEW_BULLET_VEHICLE_SUPPORT - class CcdOverlapFilterCallBack : public btOverlapFilterCallback { private: @@ -503,8 +498,8 @@ void CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController *ctrl) void CcdPhysicsEnvironment::RemoveConstraint(btTypedConstraint *con, bool free) { - CcdPhysicsController::CcdConstraint *userData = (CcdPhysicsController::CcdConstraint *)con->getUserConstraintPtr(); - if (!userData->m_active) { + CcdConstraint *userData = (CcdConstraint *)con->getUserConstraintPtr(); + if (!userData->GetEnabled()) { return; } @@ -513,7 +508,7 @@ void CcdPhysicsEnvironment::RemoveConstraint(btTypedConstraint *con, bool free) rbA.activate(); rbB.activate(); - userData->m_active = false; + userData->SetEnabled(false); m_dynamicsWorld->removeConstraint(con); if (free) { @@ -532,10 +527,19 @@ void CcdPhysicsEnvironment::RemoveConstraint(btTypedConstraint *con, bool free) } } +void CcdPhysicsEnvironment::RemoveVehicle(WrapperVehicle *vehicle, bool free) +{ + m_dynamicsWorld->removeVehicle(vehicle->GetVehicle()); + if (free) { + m_wrapperVehicles.erase(std::remove(m_wrapperVehicles.begin(), m_wrapperVehicles.end(), vehicle)); + delete vehicle; + } +} + void CcdPhysicsEnvironment::RestoreConstraint(CcdPhysicsController *ctrl, btTypedConstraint *con) { - CcdPhysicsController::CcdConstraint *userData = (CcdPhysicsController::CcdConstraint *)con->getUserConstraintPtr(); - if (userData->m_active) { + CcdConstraint *userData = (CcdConstraint *)con->getUserConstraintPtr(); + if (userData->GetEnabled()) { return; } @@ -554,8 +558,8 @@ void CcdPhysicsEnvironment::RestoreConstraint(CcdPhysicsController *ctrl, btType // Avoid add constraint if one of the objects are not available. if (IsActiveCcdPhysicsController(other)) { - userData->m_active = true; - m_dynamicsWorld->addConstraint(con, userData->m_disableCollision); + userData->SetEnabled(true); + m_dynamicsWorld->addConstraint(con, userData->GetDisableCollision()); } } @@ -583,16 +587,11 @@ bool CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController *ctr m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody()); // Handle potential vehicle constraints - int numVehicles = m_wrapperVehicles.size(); - int vehicle_constraint = 0; - for (int i = 0; i < numVehicles; i++) { - WrapperVehicle *wrapperVehicle = m_wrapperVehicles[i]; - if (wrapperVehicle->GetChassis() == ctrl) - vehicle_constraint = wrapperVehicle->GetVehicle()->getUserConstraintId(); + for (WrapperVehicle *vehicle : m_wrapperVehicles) { + if (vehicle->GetChassis() == ctrl) { + RemoveVehicle(vehicle, freeConstraints); + } } - - if (vehicle_constraint > 0) - RemoveConstraintById(vehicle_constraint, freeConstraints); } else { //if a softbody @@ -1049,14 +1048,9 @@ void CcdPhysicsEnvironment::RemoveConstraintById(int constraintId, bool free) } } - WrapperVehicle *vehicle; - if ((vehicle = (WrapperVehicle *)GetVehicleConstraint(constraintId))) - { - m_dynamicsWorld->removeVehicle(vehicle->GetVehicle()); - if (free) { - m_wrapperVehicles.erase(std::remove(m_wrapperVehicles.begin(), m_wrapperVehicles.end(), vehicle)); - delete vehicle; - } + WrapperVehicle *vehicle = static_cast(GetVehicleConstraint(constraintId)); + if (vehicle) { + RemoveVehicle(vehicle, free); } } @@ -1971,9 +1965,7 @@ void CcdPhysicsEnvironment::MergeEnvironment(PHY_IPhysicsEnvironment *other_env) CcdPhysicsEnvironment::~CcdPhysicsEnvironment() { -#ifdef NEW_BULLET_VEHICLE_SUPPORT m_wrapperVehicles.clear(); -#endif //NEW_BULLET_VEHICLE_SUPPORT //m_broadphase->DestroyScene(); //delete broadphase ? release reference on broadphase ? @@ -2013,158 +2005,6 @@ CcdPhysicsEnvironment::~CcdPhysicsEnvironment() delete m_cullingCache; } -float CcdPhysicsEnvironment::GetConstraintParam(int constraintId, int param) -{ - btTypedConstraint *typedConstraint = GetConstraintById(constraintId); - if (!typedConstraint) - return 0.0f; - - switch (typedConstraint->getUserConstraintType()) - { - case PHY_GENERIC_6DOF_CONSTRAINT: - { - switch (param) - { - case 0: case 1: case 2: - { - //param = 0..2 are linear constraint values - btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)typedConstraint; - genCons->calculateTransforms(); - return genCons->getRelativePivotPosition(param); - break; - } - case 3: case 4: case 5: - { - //param = 3..5 are relative constraint (Euler) angles - btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)typedConstraint; - genCons->calculateTransforms(); - return genCons->getAngle(param - 3); - break; - } - default: - { - } - } - break; - }; - default: - { - }; - }; - return 0.0f; -} - -void CcdPhysicsEnvironment::SetConstraintParam(int constraintId, int param, float value0, float value1) -{ - btTypedConstraint *typedConstraint = GetConstraintById(constraintId); - if (!typedConstraint) - return; - - switch (typedConstraint->getUserConstraintType()) - { - case PHY_GENERIC_6DOF_CONSTRAINT: - { - switch (param) - { - case 0: case 1: case 2: case 3: case 4: case 5: - { - //param = 0..5 are constraint limits, with low/high limit value - btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)typedConstraint; - genCons->setLimit(param, value0, value1); - break; - } - case 6: case 7: case 8: - { - //param = 6,7,8 are translational motors, with value0=target velocity, value1 = max motor force - btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)typedConstraint; - int transMotorIndex = param - 6; - btTranslationalLimitMotor *transMotor = genCons->getTranslationalLimitMotor(); - transMotor->m_targetVelocity[transMotorIndex] = value0; - transMotor->m_maxMotorForce[transMotorIndex] = value1; - transMotor->m_enableMotor[transMotorIndex] = (value1 > 0.0f); - break; - } - case 9: case 10: case 11: - { - //param = 9,10,11 are rotational motors, with value0=target velocity, value1 = max motor force - btGeneric6DofConstraint *genCons = (btGeneric6DofConstraint *)typedConstraint; - int angMotorIndex = param - 9; - btRotationalLimitMotor *rotMotor = genCons->getRotationalLimitMotor(angMotorIndex); - rotMotor->m_enableMotor = (value1 > 0.0f); - rotMotor->m_targetVelocity = value0; - rotMotor->m_maxMotorForce = value1; - break; - } - - case 12: case 13: case 14: case 15: case 16: case 17: - { - //param 12-17 are for motorized springs on each of the degrees of freedom - btGeneric6DofSpringConstraint *genCons = (btGeneric6DofSpringConstraint *)typedConstraint; - int springIndex = param - 12; - if (value0 != 0.0f) { - bool springEnabled = true; - genCons->setStiffness(springIndex, value0); - genCons->setDamping(springIndex, value1); - genCons->enableSpring(springIndex, springEnabled); - genCons->setEquilibriumPoint(springIndex); - } - else { - bool springEnabled = false; - genCons->enableSpring(springIndex, springEnabled); - } - break; - } - - default: - { - } - }; - break; - }; - case PHY_CONE_TWIST_CONSTRAINT: - { - switch (param) - { - case 3: case 4: case 5: - { - //param = 3,4,5 are constraint limits, high limit values - btConeTwistConstraint *coneTwist = (btConeTwistConstraint *)typedConstraint; - if (value1 < 0.0f) - coneTwist->setLimit(param, btScalar(BT_LARGE_FLOAT)); - else - coneTwist->setLimit(param, value1); - break; - } - default: - { - } - }; - break; - }; - case PHY_ANGULAR_CONSTRAINT: - case PHY_LINEHINGE_CONSTRAINT: - { - switch (param) - { - case 3: - { - //param = 3 is a constraint limit, with low/high limit value - btHingeConstraint *hingeCons = (btHingeConstraint *)typedConstraint; - hingeCons->setLimit(value0, value1); - break; - } - default: - { - } - } - break; - }; - default: - { - }; - }; -} - btTypedConstraint *CcdPhysicsEnvironment::GetConstraintById(int constraintId) { // For soft body constraints @@ -2329,8 +2169,6 @@ bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy *proxy0 return true; } -#ifdef NEW_BULLET_VEHICLE_SUPPORT - //complex constraint for vehicles PHY_IVehicle *CcdPhysicsEnvironment::GetVehicleConstraint(int constraintId) { @@ -2346,8 +2184,6 @@ PHY_IVehicle *CcdPhysicsEnvironment::GetVehicleConstraint(int constraintId) return nullptr; } -#endif //NEW_BULLET_VEHICLE_SUPPORT - PHY_ICharacter *CcdPhysicsEnvironment::GetCharacterController(KX_GameObject *ob) { CcdPhysicsController *controller = (CcdPhysicsController *)ob->GetPhysicsController(); @@ -2399,7 +2235,7 @@ int findClosestNode(btSoftBody *sb, const btVector3& worldPoint) return node; } -int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, class PHY_IPhysicsController *ctrl1, PHY_ConstraintType type, +PHY_IConstraint *CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, class PHY_IPhysicsController *ctrl1, PHY_ConstraintType type, float pivotX, float pivotY, float pivotZ, float axisX, float axisY, float axisZ, float axis1X, float axis1Y, float axis1Z, @@ -2418,7 +2254,7 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, btCollisionObject *colObj0 = c0->GetCollisionObject(); if (!colObj0) { - return 0; + return nullptr; } btVector3 pivotInA(pivotX, pivotY, pivotZ); @@ -2429,7 +2265,7 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, if (sb0 && sb1) { //not between two soft bodies? - return 0; + return nullptr; } if (sb0) { @@ -2445,7 +2281,7 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, sb0->setMass(node, 0.0f); } } - return 0;//can't remove soft body anchors yet + return nullptr;//can't remove soft body anchors yet } if (sb1) { @@ -2459,19 +2295,23 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, sb1->setMass(node, 0.0f); } } - return 0;//can't remove soft body anchors yet + return nullptr;//can't remove soft body anchors yet } if (rb0static && rb1static) { - return 0; + return nullptr; } if (!rb0) - return 0; + return nullptr; + + // If either of the controllers is missing, we can't do anything. + if (!c0 || !c1) { + return nullptr; + } btTypedConstraint *con = nullptr; - btRaycastVehicle *vehicle = nullptr; btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) : rb0->getCenterOfMassTransform() * pivotInA; @@ -2484,11 +2324,6 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, { case PHY_POINT2POINT_CONSTRAINT: { - // If either of the controllers is missing, we can't do anything. - if (!c0 || !c1) { - return 0; - } - btPoint2PointConstraint *p2p = nullptr; if (rb1) { @@ -2505,11 +2340,6 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, case PHY_GENERIC_6DOF_CONSTRAINT: { - // If either of the controllers is missing, we can't do anything. - if (!c0 || !c1) { - return 0; - } - btGeneric6DofConstraint *genericConstraint = nullptr; if (rb1) { @@ -2567,11 +2397,6 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, } case PHY_CONE_TWIST_CONSTRAINT: { - // If either of the controllers is missing, we can't do anything. - if (!c0 || !c1) { - return 0; - } - btConeTwistConstraint *coneTwistContraint = nullptr; if (rb1) { @@ -2629,11 +2454,6 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, case PHY_LINEHINGE_CONSTRAINT: { - // If either of the controllers is missing, we can't do anything. - if (!c0 || !c1) { - return 0; - } - btHingeConstraint *hinge = nullptr; if (rb1) { @@ -2688,48 +2508,40 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl0, break; } -#ifdef NEW_BULLET_VEHICLE_SUPPORT - - case PHY_VEHICLE_CONSTRAINT: - { - const btRaycastVehicle::btVehicleTuning tuning = btRaycastVehicle::btVehicleTuning(); - btRigidBody *chassis = rb0; - BlenderVehicleRaycaster *raycaster = new BlenderVehicleRaycaster(m_dynamicsWorld); - vehicle = new btRaycastVehicle(tuning, chassis, raycaster); - WrapperVehicle *wrapperVehicle = new WrapperVehicle(vehicle, raycaster, ctrl0); - m_wrapperVehicles.push_back(wrapperVehicle); - - break; - }; -#endif //NEW_BULLET_VEHICLE_SUPPORT - default: { } }; - if (con) { - c0->addCcdConstraintRef(con); - c1->addCcdConstraintRef(con); - con->setUserConstraintId(gConstraintUid++); - con->setUserConstraintType(type); - CcdPhysicsController::CcdConstraint *userData = new CcdPhysicsController::CcdConstraint(disableCollisionBetweenLinkedBodies); - con->setUserConstraintPtr(userData); - userData->m_active = true; - m_dynamicsWorld->addConstraint(con, disableCollisionBetweenLinkedBodies); - - return con->getUserConstraintId(); + if (!con) { + return nullptr; } - else if (vehicle) { - m_dynamicsWorld->addVehicle(vehicle); - vehicle->setUserConstraintId(gConstraintUid++); - vehicle->setUserConstraintType(type); + c0->addCcdConstraintRef(con); + c1->addCcdConstraintRef(con); + con->setUserConstraintId(gConstraintUid++); + con->setUserConstraintType(type); + CcdConstraint *constraintData = new CcdConstraint(con, disableCollisionBetweenLinkedBodies); + con->setUserConstraintPtr(constraintData); + m_dynamicsWorld->addConstraint(con, disableCollisionBetweenLinkedBodies); - return vehicle->getUserConstraintId(); - } + return constraintData; +} - return 0; +PHY_IVehicle *CcdPhysicsEnvironment::CreateVehicle(PHY_IPhysicsController *ctrl) +{ + const btRaycastVehicle::btVehicleTuning tuning = btRaycastVehicle::btVehicleTuning(); + BlenderVehicleRaycaster *raycaster = new BlenderVehicleRaycaster(m_dynamicsWorld); + btRaycastVehicle *vehicle = new btRaycastVehicle(tuning, ((CcdPhysicsController *)ctrl)->GetRigidBody(), raycaster); + WrapperVehicle *wrapperVehicle = new WrapperVehicle(vehicle, raycaster, ctrl); + m_wrapperVehicles.push_back(wrapperVehicle); + + m_dynamicsWorld->addVehicle(vehicle); + + vehicle->setUserConstraintId(gConstraintUid++); + vehicle->setUserConstraintType(PHY_VEHICLE_CONSTRAINT); + + return wrapperVehicle; } PHY_IPhysicsController *CcdPhysicsEnvironment::CreateConeController(float coneradius, float coneheight) @@ -3308,7 +3120,7 @@ void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_Ga /* Apply not only the pivot and axis values, but also take scale into count * this is not working well, if only one or two axis are scaled, but works ok on * homogeneous scaling. */ - int constraintId = phys_env->CreateConstraint( + PHY_IConstraint *constraint = phys_env->CreateConstraint( phy_src, phy_dest, (PHY_ConstraintType)dat->type, (float)(dat->pivX * scale.x()), (float)(dat->pivY * scale.y()), (float)(dat->pivZ * scale.z()), (float)(axis0.x() * scale.x()), (float)(axis0.y() * scale.y()), (float)(axis0.z() * scale.z()), @@ -3323,7 +3135,7 @@ void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_Ga * PHY_VEHICLE_CONSTRAINT = 11, * PHY_GENERIC_6DOF_CONSTRAINT = 12 */ - if (!constraintId) + if (!constraint) return; int dof = 0; @@ -3355,11 +3167,11 @@ void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_Ga for (; dof < dof_max; dof++) { if (dat->flag & dofbit) { - phys_env->SetConstraintParam(constraintId, dof, dat->minLimit[dof], dat->maxLimit[dof]); + constraint->SetParam(dof, dat->minLimit[dof], dat->maxLimit[dof]); } else { /* minLimit > maxLimit means free (no limit) for this degree of freedom. */ - phys_env->SetConstraintParam(constraintId, dof, 1.0f, -1.0f); + constraint->SetParam(dof, 1.0f, -1.0f); } dofbit <<= 1; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 985e8a0b7883..8b179dfe863d 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -38,10 +38,6 @@ class btTypedConstraint; class btSimulationIslandManager; class btCollisionDispatcher; class btDispatcher; -//#include "btBroadphaseInterface.h" - -//switch on/off new vehicle support -#define NEW_BULLET_VEHICLE_SUPPORT 1 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h" @@ -68,6 +64,8 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment /// Removes the constraint and his references from the owner and the target. void RemoveConstraint(btTypedConstraint *con, bool free); + /// Remove a vehicle wrapper. + void RemoveVehicle(WrapperVehicle *vehicle, bool free); /// Restore the constraint if the owner and target are presents. void RestoreConstraint(CcdPhysicsController *ctrl, btTypedConstraint *con); @@ -168,15 +166,12 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment virtual void GetGravity(MT_Vector3& grav); - virtual int CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, + virtual PHY_IConstraint *CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, float pivotX, float pivotY, float pivotZ, float axisX, float axisY, float axisZ, float axis1X = 0, float axis1Y = 0, float axis1Z = 0, float axis2X = 0, float axis2Y = 0, float axis2Z = 0, int flag = 0); - - virtual void SetConstraintParam(int constraintId, int param, float value, float value1); - - virtual float GetConstraintParam(int constraintId, int param); + virtual PHY_IVehicle *CreateVehicle(PHY_IPhysicsController *ctrl); virtual void RemoveConstraintById(int constraintid, bool free); @@ -184,15 +179,8 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment virtual void CallbackTriggers(); -#ifdef NEW_BULLET_VEHICLE_SUPPORT //complex constraint for vehicles virtual PHY_IVehicle *GetVehicleConstraint(int constraintId); -#else - virtual class PHY_IVehicle *GetVehicleConstraint(int constraintId) - { - return nullptr; - } -#endif /* NEW_BULLET_VEHICLE_SUPPORT */ // Character physics wrapper virtual PHY_ICharacter *GetCharacterController(class KX_GameObject *ob); diff --git a/source/gameengine/Physics/Common/CMakeLists.txt b/source/gameengine/Physics/Common/CMakeLists.txt new file mode 100644 index 000000000000..c773021512db --- /dev/null +++ b/source/gameengine/Physics/Common/CMakeLists.txt @@ -0,0 +1,47 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# The Original Code is Copyright (C) 2006, Blender Foundation +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): Jacques Beaurain. +# +# ***** END GPL LICENSE BLOCK ***** + +set(INC + . +) + +set(INC_SYS + ../../../../intern/moto/include +) + +set(SRC + PHY_IConstraint.h + PHY_DynamicTypes.h + PHY_ICharacter.h + PHY_IController.h + PHY_IGraphicController.h + PHY_IMotionState.h + PHY_IPhysicsController.h + PHY_IPhysicsEnvironment.h + PHY_IVehicle.h + PHY_Pro.h +) + +blender_add_lib(ge_phys_dummy "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Physics/Common/PHY_IConstraint.h b/source/gameengine/Physics/Common/PHY_IConstraint.h new file mode 100644 index 000000000000..3b279df4deda --- /dev/null +++ b/source/gameengine/Physics/Common/PHY_IConstraint.h @@ -0,0 +1,19 @@ +#ifndef __PHY_ICONSTRAINT_H__ +#define __PHY_ICONSTRAINT_H__ + +#include "PHY_DynamicTypes.h" // For PHY_ConstraintType. + +class PHY_IConstraint +{ +public: + PHY_IConstraint() = default; + virtual ~PHY_IConstraint() = default; + + virtual void SetParam(int param, float value, float value1) = 0; + virtual float GetParam(int param) = 0; + + virtual int GetIdentifier() const = 0; + virtual PHY_ConstraintType GetType() const = 0; +}; + +#endif // __PHY_ICONSTRAINT_H__ diff --git a/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h index b5578421f956..c7786779ffd3 100644 --- a/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h @@ -37,6 +37,7 @@ #include "MT_Vector3.h" #include "MT_Vector4.h" +class PHY_IConstraint; class PHY_IVehicle; class PHY_ICharacter; class RAS_MeshObject; @@ -186,11 +187,12 @@ class PHY_IPhysicsEnvironment virtual void SetGravity(float x, float y, float z) = 0; virtual void GetGravity(MT_Vector3& grav) = 0; - virtual int CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, + virtual PHY_IConstraint *CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, float pivotX, float pivotY, float pivotZ, float axis0X, float axis0Y, float axis0Z, float axis1X = 0, float axis1Y = 0, float axis1Z = 0, float axis2X = 0, float axis2Y = 0, float axis2Z = 0, int flag = 0) = 0; + virtual PHY_IVehicle *CreateVehicle(PHY_IPhysicsController *ctrl) = 0; virtual void RemoveConstraintById(int constraintid, bool free) = 0; virtual float GetAppliedImpulse(int constraintid) { @@ -199,7 +201,6 @@ class PHY_IPhysicsEnvironment // complex constraint for vehicles virtual PHY_IVehicle *GetVehicleConstraint(int constraintId) = 0; - // Character physics wrapper virtual PHY_ICharacter *GetCharacterController(class KX_GameObject *ob) = 0; @@ -220,9 +221,6 @@ class PHY_IPhysicsEnvironment virtual PHY_IPhysicsController *CreateSphereController(float radius, const MT_Vector3& position) = 0; virtual PHY_IPhysicsController *CreateConeController(float coneradius, float coneheight) = 0; - virtual void SetConstraintParam(int constraintId, int param, float value, float value1) = 0; - virtual float GetConstraintParam(int constraintId, int param) = 0; - virtual void ExportFile(const std::string& filename) { }; diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp index bc2774ff9c8d..9bfcc072ee0e 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp @@ -88,13 +88,17 @@ void DummyPhysicsEnvironment::GetGravity(class MT_Vector3& grav) { } -int DummyPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, +PHY_IConstraint *DummyPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, float pivotX, float pivotY, float pivotZ, float axisX, float axisY, float axisZ, float axis1X, float axis1Y, float axis1Z, float axis2X, float axis2Y, float axis2Z, int flag) { - int constraintid = 0; - return constraintid; + return nullptr; +} + +PHY_IVehicle *DummyPhysicsEnvironment::CreateVehicle(PHY_IPhysicsController *ctrl) +{ + return nullptr; } void DummyPhysicsEnvironment::RemoveConstraintById(int constraintid, bool free) diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index 4ea0bc0379d3..9a30def4dae5 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -60,11 +60,12 @@ class DummyPhysicsEnvironment : public PHY_IPhysicsEnvironment virtual void SetGravity(float x, float y, float z); virtual void GetGravity(class MT_Vector3& grav); - virtual int CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, + virtual PHY_IConstraint *CreateConstraint(class PHY_IPhysicsController *ctrl, class PHY_IPhysicsController *ctrl2, PHY_ConstraintType type, float pivotX, float pivotY, float pivotZ, float axisX, float axisY, float axisZ, float axis1X = 0, float axis1Y = 0, float axis1Z = 0, float axis2X = 0, float axis2Y = 0, float axis2Z = 0, int flag = 0); + virtual PHY_IVehicle *CreateVehicle(PHY_IPhysicsController *ctrl); virtual void RemoveConstraintById(int constraintid, bool free); @@ -113,15 +114,6 @@ class DummyPhysicsEnvironment : public PHY_IPhysicsEnvironment return nullptr; } - virtual void SetConstraintParam(int constraintId, int param, float value, float value1) - { - } - - virtual float GetConstraintParam(int constraintId, int param) - { - return 0.f; - } - virtual void MergeEnvironment(PHY_IPhysicsEnvironment *other_env) { // Dummy, nothing to do here