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:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-01-14 01:59:18 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2009-01-14 01:59:18 +0300
commit00c12e09066c551e3ae8ee6da3cb85fb3bcf90f8 (patch)
treea71ff54db96bf05245708ca65ad79de67c05fd76 /source/gameengine/Physics
parent7f5073729f5fafe4118edb18ac10abbab66bf0c7 (diff)
BGE patch: dynamically update the coumpound parent shape when parenting to a compound object.
This patch modifies the way the setParent actuator and KX_GameObject::setParent() function works when parenting to a compound object: the collision shape of the object being parented is dynamically added to the coumpound shape. Similarly, unparenting an object from a compound object will cause the child collision shape to be dynamically removed from the parent shape provided that is was previously added with setParent. Note: * This also works if the object is parented to a child of a compound object: the collision shape is added to the compound shape of the top parent. * The collision shape is added with the transformation (position, scale and orientation) it had at the time of the parenting. * The child shape is rigidly attached to the compound shape, the transformation is not affected by any further change in position/scale/orientation of the child object. * While the child shape is added to the compound shape, the child object is removed from the dynamic world to avoid superposition of shapes (one for the object itself and one for the compound child shape). This means that collision sensors on the child object are disabled while the child object is parent to a compound object. * There is no difference when setParent is used on a non-compound object: the child object is automatically changed to a static ghost object to avoid bad interaction with the parent shape; collision sensors on the child object continue to be active while the object is parented. * The child shape dynamically added to a compound shape modifies the inertia of the compound object but not the mass. It participates to collision detection as any other "static" child shape.
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;