Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine/Physics')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp22
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h44
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp14
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h2
-rw-r--r--source/gameengine/Physics/common/PHY_DynamicTypes.h3
5 files changed, 79 insertions, 6 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index c9c30c1b450..fafce5cf5cc 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -1276,7 +1276,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
// assume no shape information
// no support for dynamic change of shape yet
- assert(m_meshObject == NULL);
+ assert(IsUnused());
m_shapeType = PHY_SHAPE_NONE;
m_vertexArray.clear();
m_polygonIndexArray.clear();
@@ -1398,6 +1398,17 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
return true;
}
+bool CcdShapeConstructionInfo::SetProxy(CcdShapeConstructionInfo* shapeInfo)
+{
+ if (shapeInfo == NULL)
+ return false;
+ // no support for dynamic change
+ assert(IsUnused());
+ m_shapeType = PHY_SHAPE_PROXY;
+ m_shapeProxy = shapeInfo;
+ return true;
+}
+
btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
{
btCollisionShape* collisionShape = 0;
@@ -1406,9 +1417,12 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
btCompoundShape* compoundShape = 0;
CcdShapeConstructionInfo* nextShapeInfo;
+ if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
+ return m_shapeProxy->CreateBulletShape();
+
switch (m_shapeType)
{
- case PHY_SHAPE_NONE:
+ default:
break;
case PHY_SHAPE_BOX:
@@ -1522,6 +1536,10 @@ CcdShapeConstructionInfo::~CcdShapeConstructionInfo()
m_meshShapeMap.erase(mit);
}
}
+ if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
+ {
+ m_shapeProxy->Release();
+ }
}
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 054ec91122a..c771aa2624b 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -67,11 +67,13 @@ public:
m_height(1.0),
m_halfExtend(0.f,0.f,0.f),
m_childScale(1.0f,1.0f,1.0f),
+ m_userData(NULL),
m_refCount(1),
m_meshObject(NULL),
m_unscaledShape(NULL),
m_useGimpact(false),
- m_weldingThreshold(0.f)
+ m_weldingThreshold(0.f),
+ m_shapeProxy(NULL)
{
m_childTrans.setIdentity();
}
@@ -92,6 +94,11 @@ public:
return 0;
}
+ bool IsUnused(void)
+ {
+ return (m_meshObject==NULL && m_shapeArray.size() == 0 && m_shapeProxy == NULL);
+ }
+
void AddShape(CcdShapeConstructionInfo* shapeInfo);
btTriangleMeshShape* GetMeshShape(void)
@@ -105,6 +112,32 @@ public:
return m_shapeArray.at(i);
}
+ int FindChildShape(CcdShapeConstructionInfo* shapeInfo, void* userData)
+ {
+ if (shapeInfo == NULL)
+ return -1;
+ for (int i=0; i<m_shapeArray.size(); i++)
+ {
+ CcdShapeConstructionInfo* childInfo = m_shapeArray.at(i);
+ if ((userData == NULL || userData == childInfo->m_userData) &&
+ (childInfo == shapeInfo ||
+ (childInfo->m_shapeType == PHY_SHAPE_PROXY &&
+ childInfo->m_shapeProxy == shapeInfo)))
+ return i;
+ }
+ return -1;
+ }
+
+ bool RemoveChildShape(int i)
+ {
+ if (i < 0 || i >= m_shapeArray.size())
+ return false;
+ m_shapeArray.at(i)->Release();
+ if (i < m_shapeArray.size()-1)
+ m_shapeArray[i] = m_shapeArray.back();
+ m_shapeArray.pop_back();
+ return true;
+ }
bool SetMesh(RAS_MeshObject* mesh, bool polytope,bool useGimpact);
RAS_MeshObject* GetMesh(void)
@@ -112,6 +145,12 @@ public:
return m_meshObject;
}
+ bool SetProxy(CcdShapeConstructionInfo* shapeInfo);
+ CcdShapeConstructionInfo* GetProxy(void)
+ {
+ return m_shapeProxy;
+ }
+
btCollisionShape* CreateBulletShape();
// member variables
@@ -121,6 +160,7 @@ public:
btVector3 m_halfExtend;
btTransform m_childTrans;
btVector3 m_childScale;
+ void* m_userData;
std::vector<btPoint3> m_vertexArray; // Contains both vertex array for polytope shape and
// triangle array for concave mesh shape.
// In this case a triangle is made of 3 consecutive points
@@ -146,7 +186,7 @@ protected:
std::vector<CcdShapeConstructionInfo*> m_shapeArray; // for compound shapes
bool m_useGimpact; //use gimpact for concave dynamic/moving collision detection
float m_weldingThreshold; //welding closeby vertices together can improve softbody stability etc.
-
+ CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info
};
struct CcdConstructionInfo
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 4fe35630784..d2274c1e8d6 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -536,12 +536,24 @@ void CcdPhysicsEnvironment::disableCcdPhysicsController(CcdPhysicsController* ct
{
} else
{
- m_dynamicsWorld->removeCollisionObject(body);
+ m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject());
}
}
}
}
+void CcdPhysicsEnvironment::refreshCcdPhysicsController(CcdPhysicsController* ctrl)
+{
+ btCollisionObject* obj = ctrl->GetCollisionObject();
+ if (obj)
+ {
+ btBroadphaseProxy* proxy = obj->getBroadphaseHandle();
+ if (proxy)
+ {
+ m_dynamicsWorld->getPairCache()->cleanProxyFromPairs(proxy,m_dynamicsWorld->getDispatcher());
+ }
+ }
+}
void CcdPhysicsEnvironment::beginFrame()
{
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
index 74384dd8cf2..4b28d3fddfc 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
@@ -196,6 +196,8 @@ protected:
void enableCcdPhysicsController(CcdPhysicsController* ctrl);
+ void refreshCcdPhysicsController(CcdPhysicsController* ctrl);
+
btBroadphaseInterface* getBroadphase();
btDispatcher* getDispatcher();
diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h
index 3b3e42c38d2..09126264dcc 100644
--- a/source/gameengine/Physics/common/PHY_DynamicTypes.h
+++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h
@@ -95,7 +95,8 @@ typedef enum PHY_ShapeType {
PHY_SHAPE_CONE,
PHY_SHAPE_MESH,
PHY_SHAPE_POLYTOPE,
- PHY_SHAPE_COMPOUND
+ PHY_SHAPE_COMPOUND,
+ PHY_SHAPE_PROXY
} PHY_ShapeType;