首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bullet Physics定向刚体

Bullet Physics定向刚体
EN

Stack Overflow用户
提问于 2015-04-10 03:27:24
回答 1查看 416关注 0票数 0

我在试着在子弹里定位一个圆柱体。现在,圆柱体是模拟中唯一的东西。我在这里找到了一些答案,并相信我已经很接近了,但仍然没有轮换。这是我的创建圆柱体的函数,可能会有一些东西跳出来。

我做错了什么?

代码语言:javascript
复制
void CreateCylinder(int index, double x, double y, double z, double radius, double length, int yaw, int pitch, int roll) {

    btScalar mass = 1;
    btVector3 position(x,y,z);
    btVector3 cylInertia(0,0,0);

    //create collision shape
    btCollisionShape* cylColl = new btCylinderShape(btVector3(radius,length,1));

    //default motion state
    btDefaultMotionState* ms = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,10,0)));

    //calculate inertia
    cylColl->calculateLocalInertia(mass, cylInertia);

    //construction info
    btRigidBody::btRigidBodyConstructionInfo cylCI(
        mass,
        ms,
        cylColl,          //collision shape
        cylInertia //inertia
    );

    btRigidBody *cylinder = new btRigidBody(cylCI);



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

    //apply transform to cylinder rigid body
    cylinder->setCenterOfMassTransform(tr);


    body[index] = cylinder;
    m_dynamicsWorld->addRigidBody(body[index]);

}
EN

回答 1

Stack Overflow用户

发布于 2015-04-15 09:45:23

您必须修改正文的WorldTransform,而不是CenterOfMassTransform。您可以在DefaultMotionState中执行此操作,也可以在Body本身上执行此操作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29547243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档