首页 > 数据库技术 > 详细

【Bullet引擎】刚体类 —— btRigidBody

时间:2018-03-01 21:11:00      阅读:261      评论:0      收藏:0      [点我收藏+]

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);

 

 

 刚体对象

 技术分享图片

 

【Bullet引擎】刚体类 —— btRigidBody

原文:https://www.cnblogs.com/esCharacter/p/8490434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!