treating two dimensional arrays like one dimensional arrays

So I was looking for some more advanced Matrix operations than the ofxVectorMath addon affords and I ripped out the Vector, Quaternion and Matrix classes from OpenSceneGraph (as was suggested in this thread:

After some extended fiddling, I got rid of their dependencies on all the other OSG stuff and now it seems like I’m ready to go. The one thing at this point is that the Matrix classes from OSG store their matrices in a double[4][4] rather than the double[16] flavor that OpenGL likes.

This might be a big assumption to make, but it seems like a two dimensional array probably stores its values in consecutive memory the same way a one dimensional array does, so I’m wondering, is there a way to send the double[4][4] matrix to a method like glLoadMatrixd() without taking the intermediate step of stuffing its values into a double[16]?



turns out a friend was able to answer my question…

the way to do this is:

double matrix[4][4];  
// do something to fill in the values of this matrix  
glLoadMatrixd( (double*)(int*)matrix );  

That’s all folks!

yup, quite easily, just pass pointer to first one

double matrix44[4][4] ;  

P.S. You might get a performance increase if you use floats (and glLoadMatrixf) instead of doubles.