旋转基座时,Bullet不会更新链接的关节轴

时间:2019-03-20 05:01:01

标签: c++ bulletphysics physics-engine

我正在使用BulletDynamics库模拟链接的刚体链。首先,只有一个带有X轴的旋转链接。这是初始化部分:

    //init the links
    btVector3 hingeJointAxis(1.f, 0.f, 0.f);

    //y-axis assumed up
    btVector3 parentCom(head + (head - tail));
    btVector3 thisPivot(head);
    btVector3 thisCom(tail);

    for (int i = 0; i < numLinks; ++i)
    {
        float linkMass = 10.f;
        btVector3 linkInertiaDiag(0.0001f, 0.0001f, 0.0001f);

        pMultiBody->setupRevolute(i,
                                  linkMass,
                                  linkInertiaDiag,
                                  i - 1,
                                  btQuaternion(0.f, 0.f, 0.f, 1.f),
                                  hingeJointAxis,
                                  (tail - head),
                                  0.1f * (tail - head),
                                  false);
    }
    pMultiBody->finalizeMultiDof();

    btMultiBodyDynamicsWorld* world = m_dynamicsWorld;

    world->addMultiBody(pMultiBody);
    pMultiBody->setCanSleep(canSleep);
    pMultiBody->setHasSelfCollision(selfCollide);
    pMultiBody->setUseGyroTerm(gyro);
    //

    if (!damping)
    {
        pMultiBody->setLinearDamping(0.f);
        pMultiBody->setAngularDamping(0.f);
    }
    else
    {
        pMultiBody->setLinearDamping(0.1f);
        pMultiBody->setAngularDamping(0.9f);
    }

    setGravityInWorldFrame(IBulletBodyController::gravityVector());

    btAlignedObjectArray<btQuaternion> scratch_q;
    btAlignedObjectArray<btVector3> scratch_m;
    pMultiBody->forwardKinematics(scratch_q, scratch_m);
    btAlignedObjectArray<btQuaternion> world_to_local;
    btAlignedObjectArray<btVector3> local_origin;
    pMultiBody->updateCollisionObjectWorldTransforms(world_to_local, local_origin);

这是从库随附的示例中获取的。因此,这必须是正确的。之后,我逐渐旋转底座,然后使用功能 stepSimulation()来查看结果。我可以看到,该链接相对于PI的角度为0(向后倾斜)(根据物理学的规定),而在圆弧PI的另一侧则为2PI向前倾斜,这绝对不是预期的。

    auto btEulerSpeed = btVector3(eulerSpeed.x, eulerSpeed.y, eulerSpeed.z);
    _multiBody->setBaseOmega(btEulerSpeed);
    m_dynamicsWorld->stepSimulation(deltaT, 0);

任何想法都会受到赞赏

0 个答案:

没有答案