Bullet Linear Math and OpenGL Conversion Question

Post Reply
kraythe
Posts: 9
Joined: Mon Aug 06, 2012 8:27 am

Bullet Linear Math and OpenGL Conversion Question

Post by kraythe »

SO I am working on integrating Bullet into an OpenGL simulation on the iPhone and I have a standard piece of setup code

Code: Select all

- (void)setupGL {
   [EAGLContext setCurrentContext:self.context];
   // aspect has to be created prior to the screen rotating.
   _aspect = fabsf(self.view.bounds.size.height / self.view.bounds.size.width);
   _fieldOfView = GLKMathDegreesToRadians(50.0f);
   _cameraPosition = GLKVector3Make(0.0f, 0.0f, 8.0f);
   _baseModelView = GLKMatrix4MakeLookAt(_cameraPosition.x, _cameraPosition.y, _cameraPosition.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
   _projection = GLKMatrix4MakePerspective(_fieldOfView, _aspect, 0.1f, 1000.0f);

   // [self.obstacle setupGL];
   self.ball.position = GLKVector3Make(0.0f, 0.0f, 0.0f);
   [self.ball setupGL];
}
This is some Objective-C magic that creates a 4x4 matrix that represents the world transformation. In the update phase of the simulation I currently have the following code.

Code: Select all

- (void)updateUsingInterval:(NSTimeInterval)interval andDynamicsWorld:(btDiscreteDynamicsWorld *)dynamicsWorld {
   btTransform transform = self.sphereBody->getCenterOfMassTransform();
   btVector3 velocity = self.sphereBody->getTurnVelocity();
   btVector3 position = transform.getOrigin();
   btMatrix3x3 rotation = transform.getBasis();

   //---------- old code below, how the heck do I go from bullet to this? 
   GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(self.position.x, self.position.y, self.position.z);
   modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, GLKMatrix4MakeWithQuaternion(_rotation));
   modelViewMatrix = GLKMatrix4Multiply(self.viewController.baseModelView, modelViewMatrix);

   _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
   _modelViewProjection = GLKMatrix4Multiply(self.viewController.projection, modelViewMatrix);
}
The code above the comment line is from bullet and the code below from the standard linear math library that comes with GLKit on iOS 5+. What I need to do is integrate the two approaches. I figure i have two potential solutions, either implement the math operaitons in the bullet linear math library or convert the bullet objects to GLKMatrix objects. Is there any way to do all of this math inside bullet and thus reduce my complexity? I wasn't able to find a 4x4 matrix class in the API anywhere but perhaps I was looking in the wrong spot.

I suppose a third option would be to pass the world transform and object transform separately to the vertex shader and do the combination there.

Advice would be appreciated.
Post Reply