PDA

View Full Version : How do i get the current matrix information?



cutting_crew
07-08-2010, 01:01 PM
I am wanted to use opengl libraries to send it my own 4x4 matrix, have opengl perform a rotation and then retrieve the resulting matrix from that operation for use back into my main program.

is there a way to use something like glGetFloat(GL_MODELVIEW_MATRIX, myMatrix) without having a windowing context? Perhaps there is an alternative way to do this.

I want to rotate around an arbitrary axis using transforms but there doesnt seem to be much detailed docs on how to do this without having tons of scaling issues. any help or links on this front would be helpful.

I just thought that perhaps just using the opengl libraries would provide me with faster and more reliable computations.

thanks!

Rosario Leonardi
07-08-2010, 02:19 PM
A - Matrix operation are not harware accelerated
So doing

glMatrixLoadIdentity();
glRotatef(30.f, 1.f, 0.f, 0.f);
glTranslate(0.f, 1.f, 1.f);
DrawObject();
is the same than:

myMatrixLibrary::Matrix4 modelView(myMatrixLibrary::Identity4);
modelView.rotate(30.f, eXAxis);
modelView.translate(0.f, 1.f, 1.f);
glLoadMatrixf(modelView.getPtr());
DrawObject();

probably the code of the driver that perform matrix operation is untouched by twenty years.

You also have the advantage that you have the matrix wherever you want, you don't need to ask openGL the current matrix.

If you don't draw anything is useless to use openGl only for matrix operation.

B- using glGet is a performance killer.
Driver is the interface between software and hardware. Every time you send an openGl command this should be sent to the GPU. But to interact with the hardware the driver must go in protected mode.. software interrupt, context switch, cache flush... ARGH.. a lot of wasted time.
To avoid of doing a context switch for every openGl command the driver put the command in a queue, when the queue is full it perform a context switch, probably once per frame. If you use a glGet you are asking the state of some value, so the driver must evaluate all the command in the queue and trigger a context switch. Doing many glGet can slow down your application a lot.

So, DON'T EVER USE glGetFloat if you care about performance.

If you want to rotate around and arbitrary axis you can simply go here
http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/
or study quaternion, and implement your own matrix library.

Otherwise, if you are lazy you can go on Google and look for a free linear algebra library (better if sse2 accelerated).
http://software.intel.com/en-us/articles...2-instructions/ (http://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/)