Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bazee

3 x 4 matrix?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

The short and to the point version: I have the 3 axes (the X, Y and Z axes) describing the orientation of an object. The information I have is in the form of a vector for each axis. These vectors are not normalized but I can do that if needed. What I want to get is the equivalent yaw, pitch and roll that would create the same orientation, using that information. The gorey details (in case I am asking the question wrongly): I am trying to load models from 3DS files into my game engine. I have all the vertices, materials and textures working The only thing left is to transform the model into position. Each 3DS file can contain multiple meshes, each with their own transformation matrix (e.g. one for the arm of a character, one for the head etc. to allow skeletal animation hopefully). According to the official 3DS SDK, the mesh matrix is a: "3-by-4 matrix describing object orientation. Used by the Keyframer to determine object rotation and center" According to another source, this matrix is in the following format: " vector X1 vector X2 vector X3 vector O X1, X2 and X3 represent the axes, O the origin." At least I can deal with that origin But the axes do not work with my existing engine, it does all transformations using (via the external interface) yaw, pitch and roll (but internally it stores it as a D3DMATRIX which is a 4 x 4 matrix, which I could access if neccessary). I don't expect someone to post a whole solution and mathmatical proof here, but any help would be appreciated because its the last piece of the puzzle for me! Even some words to google would help, because I'm not even sure what I should be looking for (scary words like quaternions come to mind, is that related to this problem at all?). Or maybe some links to tutorials. Thanking the clever dude who answers this in advance, - Bazee [edited by - bazee on September 16, 2002 3:09:02 PM]

Share this post


Link to post
Share on other sites
Advertisement
Im not 100% positive about this, but this is what i understand from my linear algebra course:

well, a 4x4 transformation matrix basically consists of 4 column vectors:

[v1 v2 v3 T]

where v1=[x1.x x1.y x1.z 0] transposed.
v2=[x2.x x2.y x2.z 0] transposed.
v3=[x3.x x3.y x3.z 0] transposed.
T=[O.x O.y O.z 1] transposed.

to recap: v1, v2, v3 and T are columns. If that doesnt work, transpose the matrix (i believe DX uses a transposed one). One warning though... this does not always have to be an orthogonal orientation. nor does it have to be free of scaling. In other words, file could contain a skewed matrix, or a matrix that stretches the model... you can always make sure that the axis are normalized to remove scaling. But to remove skewing, you must choose one vector to stay constant and choose others using it.


Good Luck,
Salman.



Share this post


Link to post
Share on other sites
Thanks for your answer! :-) It''s all making sense now, I thought it was strange that it contained no scaling information, but ofcourse the scale is defined by the magnitude of the axis vectors. I''m going to try your suggestion and see if it works. If you''re correct, the problem was simpler than I thought, and I feel ignorant not knowing this stuff already.

Share this post


Link to post
Share on other sites
Oh dear before the arms were slightly bent, but now all bits of body are just exploded everywhere in random directions! I think your suggestion is probably correct, I''m just doing something wrong. I think it''s because I am misunderstanding. In particular, I don''t understand

quote:

But to remove skewing, you must choose one vector to stay constant and choose others using it.



and also what does the word transpose mean?

Anybody else have any other ideas? Thanks

Share this post


Link to post
Share on other sites
OK, I''ve been reading the DX SDK very carefully and I''m beginning to understand more but still not getting any correct results, even though I''ve tried everything. I can see why the axes might be skewed and how to solve that, although I don''t really mind. If the file is skewed I''ll assume it''s done for a reason. In my basic test model, theres no skewed axes anyway.

Share this post


Link to post
Share on other sites
Hmm seems the forum bug was fixed Now can anybody answer my question?

I decided to try various freeware and shareware 3DS file viewers, and guess what, they ALL have the same bug as my engine! So I guess it''s a difficult problem that very few people know how to fix. Except when I load the files in 3DS Max, they look correct.

Share this post


Link to post
Share on other sites
a standard 3*4 matrix looks like this:

| A.x B.x C.x T.x |
| A.y B.y C.y T.y |
| A.z B.z C.z T.z |
| 0 0 0 1 |


Where A, B and C are 3 perpendicular normalized axes that form the reference coordinate frame of the matrix. T is the translation. If ABC are perpendicular and normalized, then the matrix will be orthonormal (ie. the 3*3 part will represent a rotation, no scaling or shearing will be introduced).

Converting them to (yaw, pitch, roll) and then back into a 4*4 matrix is very problematic and should be avoided at all cost. A matrix -> Euler angles -> matrix conversion is not necessarily invertable. That means, that the conversion process can lose information due to the gimbal lock problem.

All you need to do, is convert the 3*4 matrix directly into a 4*4 matrix. Depending on supplied matrix and the expected matrix order from the API, you might need to transpose it first.

Also keep in mind, that Max model matrices are relative, not absolute matrices. When you walk along the model hierarchy, you need to multiply the matrices accordingly, in order to stay in the correct reference frame.

/ Yann

Share this post


Link to post
Share on other sites
Thankyou Yann

The way you''ve drawn that matrix, is like 90 degrees rotated from the way the DirectX SDK draws it. I think thats just a difference in your style, I doubt I''m filling my matrices in the wrong side up (I''ve tried both ways just in case).

What does transpose actually mean? I know theres a D3DXMatrixTranspose function, and I''ve tried using it in all sorts of places, but what does it do?

3DS files have no object hierachy. There are "chunks" and even though these chunks are nested inside each other in a hierachy, no mesh or object chunk is allowed to contain another mesh or object (according to the 3DS SDK, and also all my test files comply to that rule). So if the matrices are not relative to world space (rather than parent object space), it will be impossible for me to find the real locations of objects.

I''m not too concerned if the conversion process loses some accuracy, because I will only do this conversion upon loading, not every frame.

What my screen looks like now for example: I load a character, most of it is OK, but an arm or leg might be totally bent in the wrong direction. If I load the file in 3DS Max, it looks OK. The really discouraging thing is as I said, any other 3DS viewer (yes even commerical ones) also show the bent version in the exact same position as my engine does.

I''ll keep working at it!

Share this post


Link to post
Share on other sites
quote:

The way you've drawn that matrix, is like 90 degrees rotated from the way the DirectX SDK draws it. I think thats just a difference in your style, I doubt I'm filling my matrices in the wrong side up (I've tried both ways just in case).

What does transpose actually mean? I know theres a D3DXMatrixTranspose function, and I've tried using it in all sorts of places, but what does it do?


It rotates the matrix by 90 degrees

There is a difference between row major and column major. Each API or 3D programm follows one of the two conventions. If you use a column-major matrix in an API that expects a row-major one (or vice-versa), you will get garbage. So you have to transpose it first, to make it compatible. DirectX uses row-major order. I don't know what convention is used in 3ds files, but it should be specified in the fileformat specs.

You should definitely check out a introduction about matrix theory, there are some very good ones in the resource section here on gamedev.

quote:

3DS files have no object hierachy. There are "chunks" and even though these chunks are nested inside each other in a hierachy, no mesh or object chunk is allowed to contain another mesh or object (according to the 3DS SDK, and also all my test files comply to that rule).


Oh, OK. I never used the 3ds format, so I supposed it was handled the same way as Max does it internally. Probably a left-over from the old 3DStudio 4.0 days. Unfortunaly 3DStudio always was (and still is) very inconsistent with it's internal and external matrix representations.

quote:

I'm not too concerned if the conversion process loses some accuracy, because I will only do this conversion upon loading, not every frame.


It's not about accuracy. You might lose vital information. Under certain circumstances, the information you'll get will be totally wrong. There are ways to deal with that, but if you already have a matrix, then converting to Euler and back to a matrix is a waste of resources and dangerous. Just do a straight 3*4 to 4*4 conversion, it's nothing more than copying 12 values.

/ Yann

[edited by - Yann L on September 18, 2002 8:25:53 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!