i 'm making my own loader and i try to compute normals, but i don’t how use the transformation matrix which i read in the file. some guys told me i have to multiply it by vertices AND normals others just normals, others again told me that i have to swap the last two lines of the 3x3 part of the matrix (in order to swap y and z axis).
Can you tell me the right thing ?
You need to swap y/z values inside the matrix so that they match the gl one. You might also have to inverse the z value. But this won’t be suffisant I guess. Indeed, I think 3ds doesn’t use the same winding for rotations. So, you’ll have to check for that too.
You’ll also have to transform all your vertices and normals, of course.
Hope that helps.
ok thanks ! For the winding of rotations like Jide talks about, if someone know something it would be nice of helping me
the normals have to be computed by the 3x3 part (rotation part), but if i multiply the vertices by the matrix, have i to use the translation part(4x4 part i presume) ?
in fact i’m not sure : have i to multiply normals by the whole matrix (with the translation part)or just by the 3x3 part (without the translation part) ?
have i to multiply normals by the whole matrix (with the translation part)or just by the 3x3 part (without the translation part) ?
Not unless you want to translate your normals.
Think of a normal vector as a point with w = 0. With w = 0, you can multiply a 4-component normal by a general 4x4 matrix and eliminate the translation.
For your situation, you might just as well use a 3 component normal and multiply by the upper-left 3x3 rotation matrix instead–you’ll get the same result.
I started out swapping and negating values, but it is just much easier to rotate 90 around x axis before you call/draw your model.
As far as using the .3ds matrix…
the first thing you do before building your drawlist build a new matrix and copy the 3ds matrix to it, then invert the newly created matrix and last use glMultMatrixf.
I 'll save you some time… the best inverted matrix code is in graphics gems II, though I used the one in lib3ds.