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.
This commit is contained in:
Benoit Bolsee
2009-01-13 22:59:18 +00:00
parent 7f5073729f
commit 00c12e0906
14 changed files with 257 additions and 15 deletions

View File

@@ -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