Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone matrix multiplication and inversion

I'm trying to apply a Kalman filter to the data coming out from the iPhone accelerometer. I need to perform matrix multiplication and inversion as fast as possible, so I was curious about the possibility of using the GPU to perform these two tasks. As of now I found only one reference for the matrix multiplication:

float mBone01[16] = { ... }
float mBone02[16] = { ... }
float mResult[16];

glMatrixMode  ( GL_MODELVIEW );
glLoadIdentity( );
glLoadMatrix  ( mBone01 );
glMultMatrix  ( mBone02 );
glGetMatrix   ( GL_MODELVIEW, mResult );

even tough the user is not really sure about the fact that this multiplication is performed inside the GPU. Do you have any hint on how to do (if possible) the same for the inversion?

Thank you all!

like image 997
Rupert Avatar asked Apr 25 '26 07:04

Rupert


2 Answers

As Kornel (and the OpenGL FAQ) already said, OpenGL does not provide an implementation of a matrix inversion.
This thread has some C++ implementations, that should work with the iPhone SDK.
Also, by calling the OpenGL API your code is not running on the GPU.
To use the GPU of the iPhone, you have to use OpenGL ES 2.0, which currently is only available on the following models:

  • iPhone 3GS
  • new iPod touch 32GB
  • new iPod touch 64GB

Apple has a sample project, that makes use of OpenGL ES 2.0 and shaders: http://developer.apple.com/iphone/library/samplecode/GLES2Sample/index.html

like image 196
Thomas Zoechling Avatar answered Apr 27 '26 21:04

Thomas Zoechling


The only sure way to perform calculations on the GPU is by using shaders.

That said, neither OpenGL nor GLSL has a built-in function for calculating inverse matrices, you have to code it by yourself.

like image 22
Kornel Kisielewicz Avatar answered Apr 27 '26 21:04

Kornel Kisielewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!