zoukankan      html  css  js  c++  java
  • 【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实现,用于计算流体对刚体的作用力

  • 相关阅读:
    php 通过header下载中文文件名 压缩包损坏或文件不存在的问题
    MySQL查看数据库安装路径
    PHP 中move_uploaded_file 上传中文文件名失败
    C# Windows异步I/O操作
    .Net 环境下比较各种数据库插入操作的性能
    GenericFactoryMethod泛型工厂模式实现简单IOC功能
    State状态模式
    .Net RabbitMQ之消息通信 构建RPC服务器
    .Net RabbitMQ系列之环境搭建于RabbitMQ基本介绍
    C# 算法之选择排序
  • 原文地址:https://www.cnblogs.com/esCharacter/p/8490355.html
Copyright © 2011-2022 走看看