# OpenGL Applying a transformation matrix in OpenGL

## 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[i][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[i].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.

##### Share on other sites
Quote:
 Original post by Revelation60Making it a 1D array gave no other results. Are you sure I don't need to change the matrix before handing it to OpenGL?
I'm curious: did you try the code that I posted?

##### Share on other sites
All the objects alone load great, but for the rotation of course.

http://home.versatel.nl/benruyl/test.rar

In 3ds.cpp you can find ReadTranslation, that's where the matrix is loaded.
In main.cpp I rotate the scene -90 degs in the DrawGLScene procedure.
In 3dsloader.cpp you can see my matrix multiplied.

I've included the binary to give you an example. Furthermore, the white spot in the middle is just the crosshair with the texture missing ;)

I have a feeling that says I shouldn't be multiplying at all, but like I said before, I am new to matrices :P

@jyk, I've tried your suggestion. But it didn't work :(

edit: of course, the model is in the file too

[Edited by - Revelation60 on July 10, 2007 7:35:47 AM]

##### Share on other sites
Quote:
 Original post by Revelation60All the objects alone load great, but for the rotation of course.I've uploaded my project:http://home.versatel.nl/benruyl/test.rarIn 3ds.cpp you can find ReadTranslation, that's where the matrix is loaded.In main.cpp I rotate the scene -90 degs in the DrawGLScene procedure.In 3dsloader.cpp you can see my matrix multiplied.I've included the binary to give you an example. Furthermore, the white spot in the middle is just the crosshair with the texture missing ;)I have a feeling that says I shouldn't be multiplying at all, but like I said before, I am new to matrices :P@jyk, I've tried your suggestion. But it didn't work :(edit: of course, the model is in the file too
You might consider posting some code for those of those who may not have the time or inclination to download and examine your project.

As for having tried my suggestion and it not working, I'm not sure I buy it (I'm guessing you either messed up the implementation, or that your information about the model format is incorrect). Anyway, again, I'd recommend just posting the relevant files (3ds.cpp, 3dsloader.cpp, main.cpp) to this thread (remember to use [ source ] tags for formatting) so that we can take a look at them.

##### Share on other sites
I already posted that code and I guessed something else was the problem. Anyway, I found another code package that does successfully load the .3ds file. In that code I saw them translation with the negative of some node pivots.
But what are pivots?

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627651
• Total Posts
2978397
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33