• 【Bullet引擎】刚体类 —— btRigidBody


    btRigidBody类主要用于刚体数据的计算。

    在模拟刚体动画过程中,可以使用btRigidBody类获取所保存的刚体对象,进而控制刚体对象的旋转和位移。进行刚体模拟计算需要经常用到此类。

    API:http://bulletphysics.org/Bullet/BulletFull/classbtRigidBody.html

    创建刚体对象

        btCollisionShape* colShape = new btBoxShape(btVector3(5, 5, 5));//创建一个基本几何体
    /// Create Dynamic Objects btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f);
    //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0, 0, 0); if (isDynamic) colShape->calculateLocalInertia(mass, localInertia); startTransform.setOrigin(btVector3(2, 10, 0));//刚体初始位置 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia); btRigidBody* body = new btRigidBody(rbInfo); dynamicsWorld->addRigidBody(body);

    从场景中获取刚体对象

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

    常用方法:

    刚体质心坐标:          

      body->getCenterOfMassPosition();

    获取刚体四元数:      

      btQuaternion qua = body->getOrientation();

    刚体旋转矩阵:         

      btTransform trans;
      body->getMotionState()->getWorldTransform(trans);
      btMatrix3x3 matrix33 = trans.getBasis();

    向刚体添加外力:

      body->applyCentralForce(btVector3(2, 1, 0));

    向刚体添加转矩:

      body->applyTorque(btVector3(0, 30, 0));

    设置刚体变换:

      btTransform trans;
      trans.setIdentity();
      trans.setOrigin(body->getCenterOfMassPosition() - dx);
      body->setCenterOfMassTransform(trans);

     刚体对象

     

  • 相关阅读:
    HTTP-Headers-And-Tricks
    Burp减少干扰
    HTTP 请求低位三连的解决办法
    apk 脱壳 报错:Failed to spawn: unable to access zygote64 while preparing for app launch; try disablin...
    mysql 如何分批 读取数据
    记录一次问题排查
    navicat打开几秒后就自动关闭
    1013 Battle Over Cities (25 分)
    1012 The Best Rank (25 分)
    1011 World Cup Betting (20 分)
  • 原文地址:https://www.cnblogs.com/esCharacter/p/8490434.html
Copyright © 2020-2023  润新知