matrix and collada

Hy.
I’m a problem with collada and opengl : i savet with opencollada plugin for 3ds a scene and i would set the local trasformation matrix(i’m use backed matrix option in the options form) , how i convert a 16 characters matric from collada file to opengl matrix?
I read about colmajor and rowmajor , what is the correct format for translate collada matrix to opengl matrix?
Thanks.

Hi,

Collada uses the row-major format and OpenGL the col-major format.
e.g.:


1   2   3   4
5   6   7   8
9   10  11  12
13  14  15  16

Collada: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
OpenGL: 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16

I didn’t try it, but it should be correct.

[admin: your statement is incorrect. COLLADA is column-major also.]

I do this function:
for collada importer:
[source]
void CColladaReaderTriangles::GetMatrixComponent(domNode* dn ,Transformation* trans)
{
domMatrix_Array pMatrix = dn->getMatrix_array();
const unsigned int nMxCount = (unsigned int)pMatrix.getCount();
float* pfVect = new float[16];
for(unsigned int iMx = 0; iMx< nMxCount; iMx ++)
{

	domFloat4x4* pV = &pMatrix.get(iMx)-&gt;getValue();
	
	pfVect[0]=((float)pV-&gt;get(0));
	pfVect[1]=((float)pV-&gt;get(1));
	pfVect[2]=((float)pV-&gt;get(2));
	pfVect[3]=((float)pV-&gt;get(3));

	pfVect[4]=((float)pV-&gt;get(4));
	pfVect[5]=((float)pV-&gt;get(5));
	pfVect[6]=((float)pV-&gt;get(6));
	pfVect[7]=((float)pV-&gt;get(7));
	
	pfVect[8]=((float)pV-&gt;get(8));
	pfVect[9]=((float)pV-&gt;get(9));
	pfVect[10]=((float)pV-&gt;get(10));
	pfVect[11]=((float)pV-&gt;get(11));
	
	pfVect[12]=((float)pV-&gt;get(12));
	pfVect[13]=((float)pV-&gt;get(13));
	pfVect[14]=((float)pV-&gt;get(14));
	pfVect[15]=((float)pV-&gt;get(15));

}

//create 3x3 column major	
Matrix3f matrixRot(pfVect[0], pfVect[4], pfVect[8], pfVect[1], pfVect[5], pfVect[9], pfVect[2], pfVect[6], pfVect[10]);
Vector3f translation(pfVect[3], pfVect[7], pfVect[11]);

.
    .
    .ecc...

}
[/source]

the translation work fine, but the rotation is flipped,may be that is relative to collada exporter 3dsmax that export in Z_UP or Y_UP?or there are other errors?
thanks

Correction to earlier poster: COLLADA matrices are column-major (written row-by-row for human readability).

Example:


<matrix> 
  1.0 0.0 0.0  X 
  0.0 1.0 0.0  Y 
  0.0 0.0 1.0  Z 
  0.0 0.0 0.0 1.0
</matrix> 

thanks ,
so this matrix :
<matrix>Collada: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16</matrix>
how become in opengl 3x3 rotation matrix?

Sorry but i’m a little confused.
by


<matrix>
   1  2  3  4
   5  6  7  8
   9 10 11 12
  13 14 15 16
</matrix>

becomes:


/ 1  2  3 \
| 5  6  7 |
\ 9 10 11 /

… with the appropriate rotation math …

See http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

oh, maybe i misunderstood the specification text:
“These matrices are written in rowmajor order to aid the human reader.”
(COLLADA Core Elements Reference 5-77)