Jump to content
  • Advertisement
Sign in to follow this  

Equivalent Rotation in Bullet in OpenGL

This topic is 1425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


So I've been working on integrating bullet into my engine. My rendering engine uses glRotate to rotate the geometry, which works fine. Only thing is, when something is rotated, because the rigid body is linked to the geometry, it needs to rotate in the same way. I know how glRotate works, but I have no idea how bullet handles its rotations, as far as if its in radians, etc.


Heres what I did for my translations, and I'm pretty sure you can use setRotation() to do rotations, but I'm not exactly sure how. Does anyone have any ideas? They would be much appreciated.

position = newPos;
        //we need to update the rigidbody, if we have one
        if (parent->hasComponent(CCollisionI))
                CCollision* c = (CCollision*)parent->getComponent(CCollisionI);
                btMotionState* m = c->rigidBody->getMotionState();
                delete m;
                btTransform t;
                btMotionState* motionStatePlane = new btDefaultMotionState(t);

Share this post

Link to post
Share on other sites

Imma follow this topic, I have exactly the same problem.


I got my rotations set up as an "orientation" vector ie: pitch, yaw, roll (i know i know, its awful, give me abreak). Tried with Bullet's quaternion but something is wrong. 

Share this post

Link to post
Share on other sites

Ill take a stab at it, although I only used bullet briefly.


I take it youre updating a bullet physics object from your own glRotate, xyzAxis/degAngle. Bullet uses a 3x3 matrix and vec3 position internally, but you can create a quaternion from your axis/angle then pass it to a bullet transform, say something like.


btQuaternion q(glRotXYZAxisNormalized, glRotAngleInRadians);


btTransform xf;




see how that works, Im making some assumptions about what you store to pass to glRotate

Edited by NumberXaero

Share this post

Link to post
Share on other sites

I like the MVC (model view controller) pattern to handle object orientation, that is, you only have one object orientation and many views/controls. This would mean, that if you rotate your object, then you only rotate a single (leading) data structure and not all data structures (physics, rendering etc.). If you rotate/translate all data structures all the time  then you will encounter most likely artifacts (physics no longer in sync with rendering).



Here's a basic example of how a MVC patter could look like in your case:

class MyObjectModel 
    matrix44 orientation;
    getOrientation() { return orientation;}
    setOrientation( ...

class BulletController
   MyObjectModel* controlledObject;
  transferOrientationFromBullet() {
     .. get motion state/world transform...
     matrix44 newOrientation = .. transform it (eg. left handed to right handed etc).
     controlledObject->setOrientation( newOrientation);

  transferOrientationToBullet() {
   btmatrix bulletOrientation = convertToBullet(controlledObject->getOrientation());
  ...update bullet data structures ...

class RenderView
   MyObjectModel* viewedObject;

   renderObject()  {
     GlMatrix4 renderMatrix = convertToOGL(viewedObject->getOrientation());
     ... set up ogl matrices etc. ..  
     ... render object ...

This is really useful, if you have different subsystems which handles coords/axis etc differently (eg OGL vs DX). The goal is , to handle your rotation/translation/scaling in one fix coord system and to have all other subsystems work only with the resulting transforamtion matrix (a single, homogene 4x4 matrix which holds all rotation,tranlsation,scaling).


This reduces your problem to find a proper transformation from your transforamtion matrix to the one used in bullet/ogl. With luck they will have all the same setup smile.png

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!