OpenGL 4x4 matrix and 3x3 matrix

This topic is 3146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hy. I must convert a 4x4 matrix from collada to a 3x3 matrix in opengl , is correct to do:
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 ignore the 4 ,8,12 and 16 and thake the last row 13 14 15 for the translate component? Thanks.

Share on other sites
I do this function:
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)->getValue();				pfVect[0]=((float)pV->get(0));		pfVect[1]=((float)pV->get(1));		pfVect[2]=((float)pV->get(2));		pfVect[3]=((float)pV->get(3));		pfVect[4]=((float)pV->get(4));		pfVect[5]=((float)pV->get(5));		pfVect[6]=((float)pV->get(6));		pfVect[7]=((float)pV->get(7));				pfVect[8]=((float)pV->get(8));		pfVect[9]=((float)pV->get(9));		pfVect[10]=((float)pV->get(10));		pfVect[11]=((float)pV->get(11));				pfVect[12]=((float)pV->get(12));		pfVect[13]=((float)pV->get(13));		pfVect[14]=((float)pV->get(14));		pfVect[15]=((float)pV->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...}

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

Share on other sites
IIRC, Collada uses column vectors in row major order with the homogeneous co-ordinate stored as 4th element. OpenGL, on the other hand, uses column vectors in column major order with the homogeneous co-ordinate stored as 4th element.

Using the matrix indexing shown in the OP, then
Quote:
 Collada: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16OpenGL: 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
would be correct. However, notice please indexes in programming language run commonly from 0, so make sure to have that right in your implementation.

Using the matrix indexing shown in the OP once again, then the translation would be in the elements { 4, 8, 12 } (which is mapped to { 13, 14, 15 } for OpenGL, and { 12, 13, 14 } for OpenGL when starting with index 0!).

From this point of view the implementation shown in the 2nd post seems me correct.

Share on other sites
Thanks.
so , may be that the axis x,y and z in 3ds and in opengl are swapped?
If the problem is this, how i can repair?
3ds have

Z
|
|
/\ / \x y
How are the opengl axis?

Thanks.

Share on other sites
sorry , but i can't draw the axis ,positive X to the right, positive Y into the distance, and positive Z up)

Share on other sites
If I interpret your ASCII art correctly, then you say that 3DS has its z axis upwards, its x axis to the right, and its y axis forwards (i.e. into the distance). So it has a right-handed co-ordinate system as OpenGL has, but it is rotated by -90° about the x axis, because OpenGL has its y axis upwards and its z axis towards. (All this said w.r.t. the standard camera orientation.) Right so far?

If so, then you have to apply an additional rotation about the x axis with 90°, of course. This makes a matrix like this
[ 1  0  0  0 ][ 0  0  1  0 ][ 0 -1  0  0 ][ 0  0  0  1 ]
if I made no error ;) IMHO you should apply this matrix during import directly on the vertices.

EDIT:
Quote:
 Original post by giugiosorry , but i can't draw the axis ,positive X to the right, positive Y into the distance, and positive Z up)
Err, was this little post already there when I formulated the above answer? (rolleyes) Sorry, but I've managed it to overlook that hint. Tststs.

[Edited by - haegarr on March 8, 2010 1:56:08 AM]

Share on other sites
I was working on a collada loader for a while... then I found this, http://assimp.sourceforge.net/

Share on other sites
thanks, but this is in directx , there is an opensource reader for opengl?
Thanks.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• Forum Statistics

• Total Topics
632948
• Total Posts
3009401
• Who's Online (See full list)

There are no registered users currently online

×