0
votes

I'm trying to orient a cylinder in bullet. Right now, the cylinder is the only thing in the simulation. I have found some answers here, and believe I am close, but still no rotation. Here is my function for creating the cylinder, maybe something will jump out at someone.

What am I doing incorrectly?

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

}
1

1 Answers

1
votes

You must modify the Body's WorldTransform, not the CenterOfMassTransform. You can do this in the DefaultMotionState as well as on the Body itself.