How to apply rotation to a body in Bullet Physics Engine?

烈酒焚心 提交于 2019-12-14 01:21:22

问题


I have rotation values (roll, pitch, yaw). I would like to apply that rotation to a body, but I have no idea how to do that.


回答1:


The most straightforward way would be to directly set the world transform for a rigid body, either through a motion state or by direct setting. To get a transform from roll, pitch, and yaw, you could use:

btRigidBody * rigidBody = //...
btTransform tr;
tr.setIdentity();
btQuaternion quat;
quat.setEuler(yaw,pitch,roll); //or quat.setEulerZYX depending on the ordering you want
tr.setRotation(quat);

rigidBody->setCenterOfMassTransform(tr);


来源:https://stackoverflow.com/questions/8196634/how-to-apply-rotation-to-a-body-in-bullet-physics-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!