How to configure Bullet for LookAt?

Posted by AllCoder on Game Development See other posts from Game Development or by AllCoder
Published on 2012-12-04T03:12:20Z Indexed on 2012/12/04 5:23 UTC
Read the original article Hit count: 202

Filed under:
|

I'm having problems positioning Bullet objects. I am doing:

ToolVec3 origin = ToolVec3( obj_posx, obj_posy, obj_posz );
ToolVec3 vmod = ToolVec3( object_sizex / 2.0f, object_sizey / 2.0f, object_sizez / 2.0f );

btTransform shapeTransform = btTransform::getIdentity();
shapeTransform.setOrigin( btVector3(origin.x+vmod.x, origin.y+vmod.y, origin.z+vmod.z) );
btDefaultMotionState* myMotionState = new btDefaultMotionState(shapeTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,m_collisionShapes[2],localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

I then do:

btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(colObj);

if(body && body->getMotionState()) {
    btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
    myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
} else {
    colObj->getWorldTransform().getOpenGLMatrix(m);
}

And after obtaining the matrix m, I paste it as model matrix.

I am observing few things:

  • I must add some weird "size / 2" to object's position, to have it drawed normally,
  • I have following "up" look at vector defined: "0.0f, -1.0f, 0.0f" – basically, Y grows up, Z grows forward (to monitor), BUT – x grows LEFT,
  • I think there is some conflict with the X direction.. I cannot obtain consistent positioning having world setup like this

How to configure this in Bullet?

Why the weird + size/2 requirement?

© Game Development or respective owner

Related posts about opengl

Related posts about bullet-physics