From f5c3c624f8e62f266994be42fa4c85ce579321c0 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Wed, 23 Apr 2014 19:37:54 -0700 Subject: BGE Cleanup: Moving reinstancing physics shapes from KX_ConvertPhysicsObject to PHY_IPhysicsController This was the last item in KX_ConvertPhysicsObject. Therefore, KX_ConvertPhysicsObject.h and KX_ConvertPhysicsObjects.cpp have been removed. --- .../Physics/Bullet/CcdPhysicsController.cpp | 35 ++++++++++++++++++++++ .../Physics/Bullet/CcdPhysicsController.h | 2 ++ .../Physics/common/PHY_IPhysicsController.h | 5 ++++ 3 files changed, 42 insertions(+) (limited to 'source/gameengine/Physics') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 33726018268..c98cf212265 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1625,6 +1625,41 @@ PHY_IPhysicsController* CcdPhysicsController::GetReplicaForSensors() return replica; } +/* Refresh the physics object from either an object or a mesh. + * from_gameobj and from_meshobj can be NULL + * + * when setting the mesh, the following vars get priority + * 1) from_meshobj - creates the phys mesh from RAS_MeshObject + * 2) from_gameobj - creates the phys mesh from the DerivedMesh where possible, else the RAS_MeshObject + * 3) this - update the phys mesh from DerivedMesh or RAS_MeshObject + * + * Most of the logic behind this is in shapeInfo->UpdateMesh(...) + */ +bool CcdPhysicsController::ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject *from_meshobj) +{ + CcdShapeConstructionInfo *shapeInfo; + + shapeInfo = this->GetShapeInfo(); + + if (shapeInfo->m_shapeType != PHY_SHAPE_MESH/* || spc->GetSoftBody()*/) + return false; + + this->DeleteControllerShape(); + + if (from_gameobj==NULL && from_meshobj==NULL) + from_gameobj = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)this->GetNewClientInfo()); + + /* updates the arrays used for making the new bullet mesh */ + shapeInfo->UpdateMesh(from_gameobj, from_meshobj); + + /* create the new bullet mesh */ + CcdConstructionInfo& cci = this->GetConstructionInfo(); + btCollisionShape* bm= shapeInfo->CreateBulletShape(cci.m_margin, cci.m_bGimpact, !cci.m_bSoft); + + this->ReplaceControllerShape(bm); + return true; +} + /////////////////////////////////////////////////////////// ///A small utility class, DefaultMotionState /// diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 0d6d40861c5..d8bb0d06d10 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -704,6 +704,8 @@ protected: return GetConstructionInfo().m_shapeInfo->m_shapeType == PHY_SHAPE_COMPOUND; } + virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj); + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdPhysicsController") #endif diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h index a1d0972a950..2ffb115e3b2 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsController.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsController.h @@ -41,6 +41,9 @@ class MT_Vector3; class MT_Point3; class MT_Matrix3x3; +class KX_GameObject; +class RAS_MeshObject; + /** * PHY_IPhysicsController is the abstract simplified Interface to a physical object. * It contains the IMotionState and IDeformableMesh Interfaces. @@ -124,6 +127,8 @@ class PHY_IPhysicsController : public PHY_IController virtual bool IsDynamic() = 0; virtual bool IsCompound() = 0; + virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) = 0; + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IPhysicsController") -- cgit v1.2.3