Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Aug 07, 2012 9:51 am 
Offline

Joined: Mon Aug 06, 2012 8:27 am
Posts: 8
SO I am working on integrating Bullet into an OpenGL simulation on the iPhone and I have a standard piece of setup code

Code:
- (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:
- (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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Exabot [Bot], vtwinracersp2 and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group