【Bullet引擎】复杂碰撞体 —— btCompoundShape

说明

  btCompoundShape可用于创建不规则的复杂几何体,碰撞体由多个基础几何体组成,如球体,六面体等。即btCompoundShape是由多个基础的碰撞体组合成的碰撞体。

  btCompoundShape内的子碰撞体可以动态地添加、删除和修改。

 

使用

btCompoundShape对象的创建

 

btCompoundShape* compound = new btCompoundShape();
btCollisionShape* sphereShape = new btSphereShape(radius);
btTransform localTrans;
localTrans.setIdentity();
localTrans.setOrigin(relPosition);
compound->addChildShape(localTrans, sphereShape);//添加子碰撞体

btTransform startTransform;
startTransform.setIdentity();

btScalar mass(1.);
btVector3 localInertia(0, 0, 0);
compound->calculateLocalInertia(mass, localInertia);

startTransform.setOrigin(btVector3(0., 10., 0.));//位置

btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, compound, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

dynamicsWorld->addRigidBody(body);

 

获取碰撞体

btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];//i为btCompoundShape对象的索引
btRigidBody* body = btRigidBody::upcast(obj);

btCompoundShape* compound = (btCompoundShape*)body->getCollisionShape();

 

常用方法

子几何体数量:

  compound->getNumChildShapes()

子几何体变换:

  compound->getChildTransform(idx)  //idx为子几何体索引

获取子几何体:

  btCollisionShape * childShape = compound->getChildShape(index);

添加几何体:

  btCollisionShape* sphereShape = new btSphereShape(5);
  btTransform localTrans;
  localTrans.setIdentity();
  localTrans.setOrigin(btVector3(0, 20, 0));
  compound->addChildShape(localTrans, sphereShape);

移除几何体:

  compound->removeChildShapeByIndex(idx);

 

 

 

实例

流固耦合模拟

(流体与刚体交互模拟)

    

 

  • 流体采用SPH算法,刚体使用Bullet计算。刚体由粒子组成,使用btCompoundShape实现,用于计算流体对刚体的作用力

 

转载于:https://www.cnblogs.com/esCharacter/p/8490355.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值