Quantcast
Viewing all articles
Browse latest Browse all 40524

How to rotate and translate a ofxBullet body?

I have been working on the orientation issues. Bullet handles quaternions different than OF. I am working on a dev branch to be ready for OF 009. I added a convenience function that will work with older versions of Bullet.

static btQuaternion ofGetBtQuat( ofQuaternion aQuat ) {
    float angle;
    ofVec3f axis;
    aQuat.getRotate( angle, axis );
    btQuaternion btquat;
    btquat = btQuaternion::getIdentity();
    btquat.setRotation( ofGetBtVector( axis ), angle * DEG_TO_RAD );
    return btquat;
}

I also added a rotation example to the branch that I am currently developing. But you will have to use the above function to convert from OF quat to bullet quat when passing to the function. Or you could just pass in the bullet transform using

static btTransform ofGetBtTransform( ofVec3f aGlobalPos, ofQuaternion aQuat ) {
    btTransform trans;
    trans.setIdentity();
    trans.setRotation( ofGetBtQuat(aQuat) );
    trans.setOrigin( ofGetBtVector( aGlobalPos ) );
    return trans;
}

If you are wondering how to create quats along a direction, check out this example. IF you are using an older version of bullet, you will have to use ofGetBtTransform after calculating the OF quat.
https://github.com/NickHardeman/ofxBullet/tree/develop-009/RotationExample


Viewing all articles
Browse latest Browse all 40524

Trending Articles