Matrices question

Started by
8 comments, last by python_regious 19 years, 8 months ago
Hello, If I understand correctly, with a 4x4 matrice (such as the one used by OpenGL and DirectX), you can get the x, y, and z axis direction vectors and the position from the matrix like in this diagram: (this is column major) x axis vector | y axis vector | | z axis vector | | | position | | | | | | | | | Xx Yx Zx Px | | Xy Yy Zy Py | | Xz Yz Zz Pz | | 0 0 0 1 | EDIT: Well, it wasn't displayed correctly, but it says the first column vector is x axis, second is y axis, and so on... If this is correct, then are those x, y, and z axis vectors normalized or is there a chance they may not be? If they are, then that would save me three normalizations per frame, which is the reason I am asking. Thanks, Slaru
Advertisement
No, their magnitude are the scaling factors on the axes. Generally I would think you would have that number somewhere seperate. As an example a level designer places an object in the world and scales it.
Keys to success: Ability, ambition and opportunity.
Just to expand on that last post, if the matrix is ONLY made up of rotations & translations, then yes those vectors are normalized. I don't know your situation, but you might be able to assume this is true.
Some people prefer the terms Right, Up and At vectors instead of x,y and z axes. Also, you've got a column major matrix. You can also define a row major matrix. The advantage over the column matrix is that the matrix can be defined as:
class Vector3{    float x, y, z;}class Matrix{    union    {        float matrix [16];        struct        {            Vector3 right; float pad1;            Vector3 up; float pad2;            Vector3 at; float pad3;            Vector3 pos; float pad4;        }    }}

which makes getting the component vectors easier.

Either way works just fine, it's just a matter of what works best for you.

Skizz
Quote:Original post by Skizz
Some people prefer the terms Right, Up and At vectors instead of x,y and z axes. Also, you've got a column major matrix. You can also define a row major matrix. The advantage over the column matrix is that the matrix can be defined as:
class Vector3{    float x, y, z;}class Matrix{    union    {        float matrix [16];        struct        {            Vector3 right; float pad1;            Vector3 up; float pad2;            Vector3 at; float pad3;            Vector3 pos; float pad4;        }    }}

which makes getting the component vectors easier.

Either way works just fine, it's just a matter of what works best for you.

Skizz


OpenGL's column matrices and D3D's row matrices actually have the same memory configuration. Besides, it's not like it's exactly hard to grab the vectors regardless of the memory configuration it's in.
If at first you don't succeed, redefine success.
Quote:Original post by Slaru
are those x, y, and z axis vectors normalized or is there a chance they may not be?


They don't have to be, they'll just scale the axis if they're not. 3 normalisations a frame isn't much anyway, just do it and forget about it.
If at first you don't succeed, redefine success.
I am using those vectors for my quaternion camera. There shouldn't be any scaling since this camera only uses pitch, yaw, roll, strafe, walk, and fly orientation commands. I think I can leave those normalizations out in this case. Tell me if I am thinking wrong here.
no thats right.

a quaternion to matrix operation will always yield you a pure rotation matrix, meaning that it doesnt do any scaling thus its column vectors are of unit length.

but even them renomralizing is only a problem in inner loops. doing it once per frame for your camera really isnt an issue.
Quote:Original post by python_regious
OpenGL's column matrices and D3D's row matrices actually have the same memory configuration. Besides, it's not like it's exactly hard to grab the vectors regardless of the memory configuration it's in.

Actually, a column matrix is the transpose of a row matrix.
The point I was making was that getting the right vector from a column matrix requires copying the values to a new vector whereas with a row matix you can just return a reference to the appropriate member.

Skizz
Quote:Original post by Skizz
Quote:Original post by python_regious
OpenGL's column matrices and D3D's row matrices actually have the same memory configuration. Besides, it's not like it's exactly hard to grab the vectors regardless of the memory configuration it's in.

Actually, a column matrix is the transpose of a row matrix.
The point I was making was that getting the right vector from a column matrix requires copying the values to a new vector whereas with a row matix you can just return a reference to the appropriate member.

Skizz


Yes, I know about the transpose thing. That isn't what I was getting at. The memory configuration ( i.e. layout ) of both, is the same ( from column major matrices in OpenGL to row major matrices in Direct3D ).
If at first you don't succeed, redefine success.

This topic is closed to new replies.

Advertisement