# OpenGL Applying a transformation matrix in OpenGL

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

## Recommended Posts

Hi, I am creating a 3ds loader and I am having trouble finding the correct way to express the translation matrix of block 4160. The information about this block is:
Quote:
 4160 - Translation Matrix This structure describes a matrix for the object. It is stored as a 3 X 4 matrix because it is assumed that the right most column is 0,0,0,1
What command must I use to translate the scene? I've tried, maybe in the wrong way, glMultMatrixf. Thanks!

##### Share on other sites
Quote:
 4160 - Translation MatrixThis structure describes a matrix for the object.It is stored as a 3 X 4 matrix because it is assumed thatthe right most column is 0,0,0,1
That doesn't seem right - if it's a 3x4 affine transform matrix, it should be the bottom row (not the right-most column) that's assumed to be identity.

Are you sure the docs didn't say '4x3'?

##### Share on other sites
It seems to be correct this way. Another doc says the following:

Quote:
 Local axis info. The three first blocks of three floats are the definition (in the absolute axis) of the local axis X Y Z of the object. And the last block of three floats is the local center of the object.

But how can I apply such a matrix in OpenGL?

##### Share on other sites
Quote:
 But how can I apply such a matrix in OpenGL?
I'm guessing something like the following will work:
float glm[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };// 'm' is the 3ds matrixglm[0 ] = m[0 ];glm[1 ] = m[1 ];glm[2 ] = m[2 ];glm[4 ] = m[3 ];glm[5 ] = m[4 ];glm[6 ] = m[5 ];glm[8 ] = m[6 ];glm[9 ] = m[7 ];glm[10] = m[8 ];glm[12] = m[9 ];glm[13] = m[10];glm[14] = m[11];glMultMatrixf(glm); // Or whatever...

##### Share on other sites
Unfortunately, that doens't work. All the objects are shattered around the room :(

##### Share on other sites
Quote:
 Original post by Revelation60Unfortunately, that doens't work. All the objects are shattered around the room :(
Well, that could mean:

2. The information you have about the 3ds matrix format is wrong
3. My example was wrong

I would bet on no. 1 being the most likely, followed by no. 2, and then no. 3. If you're not sure about no. 1, you might post some of your code so that we can see what you're doing.

##### Share on other sites
Well,

This is the code I use to load the information:

Quote:
 for (int i=0;i<4;i++) for (int j=0;j<3;j++) { pPreviousChunk->bytesRead += fread(&(pObject->localMatrix[j]), 1, sizeof (float), m_FilePointer); } pObject->localMatrix [0][3]=0; pObject->localMatrix [1][3]=0; pObject->localMatrix [2][3]=0; pObject->localMatrix [3][3]=1;

And this is the code to multiply the matrix:

Quote:
 glMultMatrixf(&m3DModel.pObject.localMatrix[0][0]);

I am trying to search code that does about the same, and I saw in one example that the localMatrix got inverted. I tried to do that (note that I don't know a lot abot matrices), but that didn't give good results. :(

Also leaving the pObject->localMatrix [0][3]=0; part out didn't help.

##### Share on other sites
Hmmm......you shouldn't be using a 2-dimensional matrix to store the object's position. OpenGL assumes that each of the 16 elements are perfectly adjacent in memory, and a 2-dimensional matrix is not. Try changing your code to use a 1-dimensional matrix and make sure to reference the indexes correctly when loading the values. Also make sure that the last value in your matrix, m[15], is 1.

##### Share on other sites
Making it a 1D array gave no other results. Are you sure I don't need to change the matrix before handing it to OpenGL?

##### Share on other sites
What happens when you only place a single object in the scene and export to 3ds and try to load it in your app? Is that object simply reflected across the z-axis?

Also keep in mind that 3dsmax uses the z-axis for up and down, and the y-axis for into and out of the viewport. So you will need to perform a 90 degree rotation around the x-axis.

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002140
×