Ejemplo n.º 1
0
BulletShape::BulletShape(const BulletShape &copy, const osg::CopyOp &copyop)
    : mCollisionShape(duplicateCollisionShape(copy.mCollisionShape))
    , mCollisionBoxHalfExtents(copy.mCollisionBoxHalfExtents)
    , mCollisionBoxTranslate(copy.mCollisionBoxTranslate)
    , mAnimatedShapes(copy.mAnimatedShapes)
{
}
Ejemplo n.º 2
0
BulletShapeInstance::BulletShapeInstance(osg::ref_ptr<BulletShape> source)
    : BulletShape()
    , mSource(source)
{
    mCollisionBoxHalfExtents = source->mCollisionBoxHalfExtents;
    mCollisionBoxTranslate = source->mCollisionBoxTranslate;

    mAnimatedShapes = source->mAnimatedShapes;

    if (source->mCollisionShape)
        mCollisionShape = duplicateCollisionShape(source->mCollisionShape);
}
Ejemplo n.º 3
0
btCollisionShape* BulletShape::duplicateCollisionShape(btCollisionShape *shape) const
{
    if(shape->isCompound())
    {
        btCompoundShape *comp = static_cast<btCompoundShape*>(shape);
        btCompoundShape *newShape = new btCompoundShape;

        int numShapes = comp->getNumChildShapes();
        for(int i = 0;i < numShapes;++i)
        {
            btCollisionShape *child = duplicateCollisionShape(comp->getChildShape(i));
            btTransform trans = comp->getChildTransform(i);
            newShape->addChildShape(trans, child);
        }

        return newShape;
    }

    if(btBvhTriangleMeshShape* trishape = dynamic_cast<btBvhTriangleMeshShape*>(shape))
    {
#if BT_BULLET_VERSION >= 283
        btScaledBvhTriangleMeshShape* newShape = new btScaledBvhTriangleMeshShape(trishape, btVector3(1.f, 1.f, 1.f));
#else
        // work around btScaledBvhTriangleMeshShape bug ( https://code.google.com/p/bullet/issues/detail?id=371 ) in older bullet versions
        btTriangleMesh* oldMesh = static_cast<btTriangleMesh*>(trishape->getMeshInterface());
        btTriangleMesh* newMesh = new btTriangleMesh(*oldMesh);

        // Do not build a new bvh (not needed, since it's the same as the original shape's bvh)
        bool buildBvh = true;
        if (trishape->getOptimizedBvh())
            buildBvh = false;
        TriangleMeshShape* newShape = new TriangleMeshShape(newMesh, true, buildBvh);
        // Set original shape's bvh via pointer
        // The pointer is safe because the BulletShapeInstance keeps a ref_ptr to the original BulletShape
        if (!buildBvh)
            newShape->setOptimizedBvh(trishape->getOptimizedBvh());
#endif
        return newShape;
    }

    if (btBoxShape* boxshape = dynamic_cast<btBoxShape*>(shape))
    {
        return new btBoxShape(*boxshape);
    }

    throw std::logic_error(std::string("Unhandled Bullet shape duplication: ")+shape->getName());
}