mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-29 12:36:50 +00:00
Move functions independent from BulletShape into anonymous namespace
This commit is contained in:
parent
29a772c33f
commit
ca8584f6f6
2 changed files with 53 additions and 65 deletions
|
@ -10,6 +10,53 @@
|
||||||
|
|
||||||
namespace Resource
|
namespace Resource
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
btCollisionShape* duplicateCollisionShape(const btCollisionShape *shape)
|
||||||
|
{
|
||||||
|
if (shape == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (shape->isCompound())
|
||||||
|
{
|
||||||
|
const btCompoundShape *comp = static_cast<const btCompoundShape*>(shape);
|
||||||
|
btCompoundShape* newShape = new btCompoundShape;
|
||||||
|
|
||||||
|
for (int i = 0, n = comp->getNumChildShapes(); i < n; ++i)
|
||||||
|
{
|
||||||
|
btCollisionShape* child = duplicateCollisionShape(comp->getChildShape(i));
|
||||||
|
const btTransform& trans = comp->getChildTransform(i);
|
||||||
|
newShape->addChildShape(trans, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const btBvhTriangleMeshShape* trishape = dynamic_cast<const btBvhTriangleMeshShape*>(shape))
|
||||||
|
return new btScaledBvhTriangleMeshShape(const_cast<btBvhTriangleMeshShape*>(trishape), btVector3(1.f, 1.f, 1.f));
|
||||||
|
|
||||||
|
if (const btBoxShape* boxshape = dynamic_cast<const btBoxShape*>(shape))
|
||||||
|
return new btBoxShape(*boxshape);
|
||||||
|
|
||||||
|
if (shape->getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
|
||||||
|
return new btHeightfieldTerrainShape(static_cast<const btHeightfieldTerrainShape&>(*shape));
|
||||||
|
|
||||||
|
throw std::logic_error(std::string("Unhandled Bullet shape duplication: ") + shape->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteShape(btCollisionShape* shape)
|
||||||
|
{
|
||||||
|
if (shape->isCompound())
|
||||||
|
{
|
||||||
|
btCompoundShape* compound = static_cast<btCompoundShape*>(shape);
|
||||||
|
for (int i = 0, n = compound->getNumChildShapes(); i < n; i++)
|
||||||
|
if (btCollisionShape* child = compound->getChildShape(i))
|
||||||
|
deleteShape(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete shape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BulletShape::BulletShape()
|
BulletShape::BulletShape()
|
||||||
: mCollisionShape(nullptr)
|
: mCollisionShape(nullptr)
|
||||||
|
@ -28,60 +75,12 @@ BulletShape::BulletShape(const BulletShape ©, const osg::CopyOp ©op)
|
||||||
|
|
||||||
BulletShape::~BulletShape()
|
BulletShape::~BulletShape()
|
||||||
{
|
{
|
||||||
|
if (mAvoidCollisionShape != nullptr)
|
||||||
deleteShape(mAvoidCollisionShape);
|
deleteShape(mAvoidCollisionShape);
|
||||||
|
if (mCollisionShape != nullptr)
|
||||||
deleteShape(mCollisionShape);
|
deleteShape(mCollisionShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BulletShape::deleteShape(btCollisionShape* shape)
|
|
||||||
{
|
|
||||||
if(shape!=nullptr)
|
|
||||||
{
|
|
||||||
if(shape->isCompound())
|
|
||||||
{
|
|
||||||
btCompoundShape* ms = static_cast<btCompoundShape*>(shape);
|
|
||||||
int a = ms->getNumChildShapes();
|
|
||||||
for(int i=0; i <a;i++)
|
|
||||||
deleteShape(ms->getChildShape(i));
|
|
||||||
}
|
|
||||||
delete shape;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
btCollisionShape* BulletShape::duplicateCollisionShape(const btCollisionShape *shape) const
|
|
||||||
{
|
|
||||||
if(shape->isCompound())
|
|
||||||
{
|
|
||||||
const btCompoundShape *comp = static_cast<const btCompoundShape*>(shape);
|
|
||||||
btCompoundShape *newShape = new btCompoundShape;
|
|
||||||
|
|
||||||
int numShapes = comp->getNumChildShapes();
|
|
||||||
for(int i = 0;i < numShapes;++i)
|
|
||||||
{
|
|
||||||
btCollisionShape *child = duplicateCollisionShape(comp->getChildShape(i));
|
|
||||||
const btTransform& trans = comp->getChildTransform(i);
|
|
||||||
newShape->addChildShape(trans, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newShape;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(const btBvhTriangleMeshShape* trishape = dynamic_cast<const btBvhTriangleMeshShape*>(shape))
|
|
||||||
{
|
|
||||||
btScaledBvhTriangleMeshShape* newShape = new btScaledBvhTriangleMeshShape(const_cast<btBvhTriangleMeshShape*>(trishape), btVector3(1.f, 1.f, 1.f));
|
|
||||||
return newShape;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const btBoxShape* boxshape = dynamic_cast<const btBoxShape*>(shape))
|
|
||||||
{
|
|
||||||
return new btBoxShape(*boxshape);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shape->getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
|
|
||||||
return new btHeightfieldTerrainShape(static_cast<const btHeightfieldTerrainShape&>(*shape));
|
|
||||||
|
|
||||||
throw std::logic_error(std::string("Unhandled Bullet shape duplication: ")+shape->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
btCollisionShape *BulletShape::getCollisionShape() const
|
btCollisionShape *BulletShape::getCollisionShape() const
|
||||||
{
|
{
|
||||||
return mCollisionShape;
|
return mCollisionShape;
|
||||||
|
@ -115,13 +114,8 @@ BulletShapeInstance::BulletShapeInstance(osg::ref_ptr<const BulletShape> source)
|
||||||
, mSource(source)
|
, mSource(source)
|
||||||
{
|
{
|
||||||
mCollisionBox = source->mCollisionBox;
|
mCollisionBox = source->mCollisionBox;
|
||||||
|
|
||||||
mAnimatedShapes = source->mAnimatedShapes;
|
mAnimatedShapes = source->mAnimatedShapes;
|
||||||
|
|
||||||
if (source->mCollisionShape)
|
|
||||||
mCollisionShape = duplicateCollisionShape(source->mCollisionShape);
|
mCollisionShape = duplicateCollisionShape(source->mCollisionShape);
|
||||||
|
|
||||||
if (source->mAvoidCollisionShape)
|
|
||||||
mAvoidCollisionShape = duplicateCollisionShape(source->mAvoidCollisionShape);
|
mAvoidCollisionShape = duplicateCollisionShape(source->mAvoidCollisionShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ namespace Resource
|
||||||
|
|
||||||
osg::ref_ptr<BulletShapeInstance> makeInstance() const;
|
osg::ref_ptr<BulletShapeInstance> makeInstance() const;
|
||||||
|
|
||||||
btCollisionShape* duplicateCollisionShape(const btCollisionShape* shape) const;
|
|
||||||
|
|
||||||
btCollisionShape* getCollisionShape() const;
|
btCollisionShape* getCollisionShape() const;
|
||||||
|
|
||||||
btCollisionShape* getAvoidCollisionShape() const;
|
btCollisionShape* getAvoidCollisionShape() const;
|
||||||
|
@ -53,10 +51,6 @@ namespace Resource
|
||||||
void setLocalScaling(const btVector3& scale);
|
void setLocalScaling(const btVector3& scale);
|
||||||
|
|
||||||
bool isAnimated() const;
|
bool isAnimated() const;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void deleteShape(btCollisionShape* shape);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue