diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 8261cbe4145f..5b29466d5b0e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -383,18 +383,43 @@ class CcdOverlapFilterCallBack : public btOverlapFilterCallback virtual bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const; }; - -void CcdPhysicsEnvironment::SetDebugDrawer(btIDebugDraw *debugDrawer) +CcdDebugDraw::CcdDebugDraw() + :m_debugMode(0) +{ +} +void CcdDebugDraw::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) { - if (debugDrawer && m_dynamicsWorld) { - m_dynamicsWorld->setDebugDrawer(debugDrawer); + if (m_debugMode > 0) { + KX_RasterizerDrawDebugLine(ToMt(from), ToMt(to), mt::vec4(color.x(), color.y(), color.z(), 1.0f)); } - m_debugDrawer = debugDrawer; +} + +void CcdDebugDraw::reportErrorWarning(const char *warningString) +{ +} + +void CcdDebugDraw::drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, float distance, int lifeTime, const btVector3& color) +{ + drawLine(PointOnB, PointOnB + normalOnB, color); + drawSphere(PointOnB, 0.1f, color); +} + +void CcdDebugDraw::setDebugMode(int debugMode) +{ + m_debugMode = debugMode; +} + +int CcdDebugDraw::getDebugMode() const +{ + return m_debugMode; +} + +void CcdDebugDraw::draw3dText(const btVector3& location, const char *textString) +{ } CcdPhysicsEnvironment::CcdPhysicsEnvironment(PHY_SolverType solverType, bool useDbvtCulling) - :m_debugDrawer(nullptr), - m_collisionConfiguration(new btSoftBodyRigidBodyCollisionConfiguration()), + :m_collisionConfiguration(new btSoftBodyRigidBodyCollisionConfiguration()), m_broadphase(new btDbvtBroadphase()), m_cullingCache(nullptr), m_cullingTree(nullptr), @@ -441,6 +466,8 @@ CcdPhysicsEnvironment::CcdPhysicsEnvironment(PHY_SolverType solverType, bool use m_dynamicsWorld.reset(new btSoftRigidDynamicsWorldMt(m_dispatcher.get(), m_broadphase.get(), m_solverPool.get(), m_solverMt.get(), m_collisionConfiguration.get())); m_dynamicsWorld->setInternalTickCallback(&CcdPhysicsEnvironment::StaticSimulationSubtickCallback, this); + m_dynamicsWorld->setDebugDrawer(&m_debugDrawer); + SetGravity(0.0f, 0.0f, -9.81f); } @@ -924,17 +951,12 @@ void CcdPhysicsEnvironment::ProcessFhSprings(double curTime, float interval) int CcdPhysicsEnvironment::GetDebugMode() const { - if (m_debugDrawer) { - return m_debugDrawer->getDebugMode(); - } - return 0; + return m_debugDrawer.getDebugMode(); } void CcdPhysicsEnvironment::SetDebugMode(int debugMode) { - if (m_debugDrawer) { - m_debugDrawer->setDebugMode(debugMode); - } + m_debugDrawer.setDebugMode(debugMode); } void CcdPhysicsEnvironment::SetNumIterations(int numIter) @@ -2581,45 +2603,6 @@ void CcdPhysicsEnvironment::ExportFile(const std::string& filename) } } -struct BlenderDebugDraw : public btIDebugDraw { - BlenderDebugDraw() - :m_debugMode(0) - { - } - - int m_debugMode; - - virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) - { - if (m_debugMode > 0) { - KX_RasterizerDrawDebugLine(ToMt(from), ToMt(to), mt::vec4(color.x(), color.y(), color.z(), 1.0f)); - } - } - - virtual void reportErrorWarning(const char *warningString) - { - } - - virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, float distance, int lifeTime, const btVector3& color) - { - drawLine(PointOnB, PointOnB + normalOnB, color); - drawSphere(PointOnB, 0.1f, color); - } - - virtual void setDebugMode(int debugMode) - { - m_debugMode = debugMode; - } - virtual int getDebugMode() const - { - return m_debugMode; - } - ///todo: find out if Blender can do this - virtual void draw3dText(const btVector3& location, const char *textString) - { - } -}; - CcdPhysicsEnvironment *CcdPhysicsEnvironment::Create(Scene *blenderscene, bool visualizePhysics) { static const PHY_SolverType solverTypeTable[] = { @@ -2632,7 +2615,6 @@ CcdPhysicsEnvironment *CcdPhysicsEnvironment::Create(Scene *blenderscene, bool v CcdPhysicsEnvironment *ccdPhysEnv = new CcdPhysicsEnvironment(solverTypeTable[blenderscene->gm.solverType], (blenderscene->gm.mode & WO_DBVT_CULLING) != 0); - ccdPhysEnv->SetDebugDrawer(new BlenderDebugDraw()); ccdPhysEnv->SetDeactivationLinearTreshold(blenderscene->gm.lineardeactthreshold); ccdPhysEnv->SetDeactivationAngularTreshold(blenderscene->gm.angulardeactthreshold); ccdPhysEnv->SetDeactivationTime(blenderscene->gm.deactivationtime); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index f02da7344714..709bf36ee687 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -59,6 +59,22 @@ class btConstraintSolverPoolMt; /// Find the id of the closest node to a point in a soft body. int Ccd_FindClosestNode(btSoftBody *sb, const btVector3& worldPoint); +class CcdDebugDraw : public btIDebugDraw +{ +private: + int m_debugMode; + +public: + CcdDebugDraw(); + + virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color); + virtual void reportErrorWarning(const char *warningString); + virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, float distance, int lifeTime, const btVector3& color); + virtual void setDebugMode(int debugMode); + virtual int getDebugMode() const; + virtual void draw3dText(const btVector3& location, const char *textString); +}; + /** CcdPhysicsEnvironment is an experimental mainloop for physics simulation using optional continuous collision detection. * Physics Environment takes care of stepping the simulation and is a container for physics entities. * It stores rigidbodies,constraints, materials etc. @@ -80,7 +96,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment, public mt::SimdCla protected: btVector3 m_gravity; - btIDebugDraw *m_debugDrawer; + CcdDebugDraw m_debugDrawer; std::unique_ptr m_collisionConfiguration; /// broadphase for dynamic world @@ -142,8 +158,6 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment, public mt::SimdCla /// Perform an integration step of duration 'timeStep'. - virtual void SetDebugDrawer(btIDebugDraw *debugDrawer); - virtual void SetNumIterations(int numIter); virtual void SetNumTimeSubSteps(int numTimeSubSteps) {