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];
}
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);
}
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.