Equivalent Rotation in Bullet in OpenGL

Started by
2 comments, last by Ashaman73 9 years, 4 months ago

Hello,

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;
                t.setIdentity();
                t.setOrigin(btVector3(newPos.x,newPos.y,newPos.z));
                
                btMotionState* motionStatePlane = new btDefaultMotionState(t);
                c->rigidBody->setMotionState(motionStatePlane);
                
            }

Advertisement

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.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

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;

xf.SetRotation(q);

xf.setOrigin(btVector3(newPos.x,newPos.y,newPos.z));

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

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;
    rotate()..
    translate()..
    setPosition()..
    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

This topic is closed to new replies.

Advertisement